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

30 lines
980 B
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 fields, models
2018-02-26 12:17:24 +01:00
class AccountMove(models.Model):
_inherit = "account.move"
2018-02-26 12:17:24 +01:00
loan_line_id = fields.Many2one(
"account.loan.line", readonly=True, ondelete="restrict",
2018-02-26 12:17:24 +01:00
)
loan_id = fields.Many2one(
"account.loan", readonly=True, store=True, ondelete="restrict",
2018-02-26 12:17:24 +01:00
)
def post(self):
res = super().post()
2018-02-26 12:17:24 +01:00
for record in self:
loan_line_id = record.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