2
0

46 lines
1.5 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 api, fields, models
class AccountInvoice(models.Model):
_inherit = "account.invoice"
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
)
@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
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