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).
|
|
|
|
|
2021-02-23 12:15:36 +01:00
|
|
|
from odoo import fields, models
|
2018-02-26 12:17:24 +01:00
|
|
|
|
|
|
|
|
|
|
|
class AccountMove(models.Model):
|
2021-02-23 11:00:15 +01:00
|
|
|
_inherit = "account.move"
|
2018-02-26 12:17:24 +01:00
|
|
|
|
|
|
|
loan_line_id = fields.Many2one(
|
2021-02-23 11:00:15 +01:00
|
|
|
"account.loan.line", readonly=True, ondelete="restrict",
|
2018-02-26 12:17:24 +01:00
|
|
|
)
|
|
|
|
loan_id = fields.Many2one(
|
2021-02-23 11:00:15 +01:00
|
|
|
"account.loan", readonly=True, store=True, ondelete="restrict",
|
2018-02-26 12:17:24 +01:00
|
|
|
)
|
|
|
|
|
2021-02-23 12:15:36 +01:00
|
|
|
def post(self):
|
|
|
|
res = super().post()
|
2018-02-26 12:17:24 +01:00
|
|
|
for record in self:
|
2021-02-23 12:15:36 +01:00
|
|
|
loan_line_id = record.loan_line_id
|
2020-04-14 09:29:14 +02:00
|
|
|
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
|