2
0
account-financial-tools/account_loan/model/account_move.py
Alba Riera e56f6f9e26 [MIG] account_loan: Migration to 13.0
Co-authored-by: Enric Tobella <etobella@creublanca.es>
2023-09-15 11:24:50 +02:00

30 lines
980 B
Python

# Copyright 2018 Creu Blanca
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
from odoo import 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",
)
def post(self):
res = super().post()
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
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