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 AccountInvoice(models.Model):
|
2021-02-23 11:00:15 +01:00
|
|
|
_inherit = "account.invoice"
|
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
|
|
|
)
|
|
|
|
|
|
|
|
@api.multi
|
|
|
|
def finalize_invoice_move_lines(self, move_lines):
|
|
|
|
vals = super().finalize_invoice_move_lines(move_lines)
|
|
|
|
if self.loan_line_id:
|
|
|
|
ll = self.loan_line_id
|
2021-02-23 11:00:15 +01:00
|
|
|
if ll.long_term_loan_account_id and ll.long_term_principal_amount != 0:
|
|
|
|
vals.append(
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": ll.loan_id.short_term_loan_account_id.id,
|
|
|
|
"credit": ll.long_term_principal_amount,
|
|
|
|
"debit": 0,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
|
|
|
vals.append(
|
|
|
|
(
|
|
|
|
0,
|
|
|
|
0,
|
|
|
|
{
|
|
|
|
"account_id": ll.long_term_loan_account_id.id,
|
|
|
|
"credit": 0,
|
|
|
|
"debit": ll.long_term_principal_amount,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
)
|
2018-02-26 12:17:24 +01:00
|
|
|
return vals
|