2
0
account-financial-tools/account_loan/model/account_move.py

38 lines
1.1 KiB
Python
Raw Normal View History

2018-02-26 12:17:24 +01:00
# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import api, fields, models
class AccountMove(models.Model):
_inherit = 'account.move'
loan_line_id = fields.Many2one(
'account.loan.line',
readonly=True,
ondelete='restrict',
)
loan_id = fields.Many2one(
'account.loan',
readonly=True,
store=True,
ondelete='restrict',
)
@api.multi
2019-05-27 17:08:53 +02:00
def post(self, invoice=False):
res = super().post(invoice=invoice)
2018-02-26 12:17:24 +01:00
for record in self:
loan_line_id = record.loan_line_id or (
invoice and invoice.loan_line_id
)
if loan_line_id:
if not record.loan_line_id:
record.loan_line_id = loan_line_id
record.loan_id = loan_line_id.loan_id
2018-02-26 12:17:24 +01:00
record.loan_line_id.check_move_amount()
record.loan_line_id.loan_id.compute_posted_lines()
if record.loan_line_id.sequence == record.loan_id.periods:
record.loan_id.close()
return res