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

35 lines
1.0 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 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(
2022-01-10 15:07:49 +01:00
"account.loan.line",
readonly=True,
ondelete="restrict",
2018-02-26 12:17:24 +01:00
)
loan_id = fields.Many2one(
2022-01-10 15:07:49 +01:00
"account.loan",
readonly=True,
store=True,
ondelete="restrict",
2018-02-26 12:17:24 +01:00
)
def action_post(self):
res = super().action_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