You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
123 lines
3.9 KiB
123 lines
3.9 KiB
# Copyright 2020 Coop IT Easy SCRL fs
|
|
# Houssine BAKKALI <houssine@coopiteasy.be>
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
|
|
|
|
from odoo import api, fields, models
|
|
|
|
|
|
class LoanInterestLine(models.Model):
|
|
_inherit = "loan.interest.line"
|
|
|
|
loan_due_fy_move = fields.Many2one(
|
|
comodel_name="account.move",
|
|
string="Loan due this fiscal year account move"
|
|
)
|
|
loan_reimbursment_move = fields.Many2one(
|
|
comodel_name="account.move",
|
|
string="Loan reimbursement account move"
|
|
)
|
|
interest_payment_move = fields.Many2one(
|
|
comodel_name="account.move",
|
|
string="Interest payment account move"
|
|
)
|
|
|
|
@api.multi
|
|
def get_move_line(self, move_id, partner=None):
|
|
self.ensure_one()
|
|
move_line = {
|
|
"date_maturity": self.due_date,
|
|
"date": self.due_date,
|
|
"move_id": move_id,
|
|
}
|
|
if partner:
|
|
move_line["partner_id"] = partner.id
|
|
return move_line
|
|
|
|
@api.multi
|
|
def create_move(self, date=None):
|
|
self.ensure_one()
|
|
if date:
|
|
due_date = date
|
|
else:
|
|
due_date = self.due_date
|
|
|
|
return self.env["account.move"].create({
|
|
"ref": self.loan_issue_id.reference,
|
|
"date": due_date,
|
|
"journal_id": self.company_id.loan_journal.id,
|
|
})
|
|
|
|
@api.multi
|
|
def generate_interest_payement_move_lines(self):
|
|
self.ensure_one()
|
|
move_line_obj = self.env["account.move.line"]
|
|
|
|
move = self.create_move()
|
|
debit_vals = self.get_move_line(self.partner_id)
|
|
loaner_vals = self.get_move_line(self.partner_id)
|
|
|
|
debit_vals["debit"] = self.interest
|
|
debit_vals["account_id"] = self.company_id.interest_account.id
|
|
|
|
loaner_vals["credit"] = self.due_amount
|
|
loaner_vals["account_id"] = self.company_id.loaner_account
|
|
vals_list = [debit_vals, loaner_vals]
|
|
if self.taxes_amount > 0:
|
|
tax_vals = self.get_move_line()
|
|
tax_vals["credit"] = self.taxes_amount
|
|
tax_vals["account_id"] = self.company_id.tax_account.id
|
|
vals_list.append(tax_vals)
|
|
|
|
move_line_obj.create(vals_list)
|
|
|
|
self.interest_payment_mpve = move
|
|
|
|
@api.multi
|
|
def generate_loan_due_fy(self):
|
|
self.ensure_one()
|
|
|
|
move_line_obj = self.env["account.move.line"]
|
|
|
|
move = self.create_move(fields.Date.today())
|
|
|
|
debit_vals = self.get_move_line(self.partner_id)
|
|
credit_vals = self.get_move_line(self.partner_id)
|
|
|
|
debit_vals["debit"] = self.due_amount
|
|
debit_vals["account_id"] = self.company_id.debt_long_term_account.id
|
|
|
|
credit_vals["credit"] = self.due_amount
|
|
credit_vals["account_id"] = self.company_id.debt_long_term_fy_account
|
|
|
|
move_line_obj.create([debit_vals, credit_vals])
|
|
|
|
self.loan_due_fy_move = move
|
|
|
|
@api.model
|
|
def _generate_move_line_debt_end_fy(self):
|
|
fy = self.env["account.fiscal.year"].get_next_fiscal_year()
|
|
if fy:
|
|
interest_lines = self.search([
|
|
('due_date', '>=', fy.date_from),
|
|
('due_date', '<=', fy.date_to),
|
|
('due_loan_amount', '>', 0),
|
|
])
|
|
|
|
for line in interest_lines:
|
|
if (not line.loan_reimbursment_move
|
|
and not line.loan_due_fy_move):
|
|
self.generate_loan_due_fy()
|
|
|
|
@api.model
|
|
def _generate_payment_move(self):
|
|
# TODO configure how many days before you want generate the move lines
|
|
interest_lines = self.search([
|
|
('due_date', '>=', fy.date_from),
|
|
('due_date', '<=', fy.date_to),
|
|
('due_amount', '>', 0),
|
|
])
|
|
for line in interest_lines:
|
|
if line.interest > 0 and not line.loan_reimbursment_move:
|
|
line.generate_interest_payement_move_lines()
|
|
|
|
return True
|