|
@ -1,6 +1,7 @@ |
|
|
# Copyright 2020 Coop IT Easy SCRL fs |
|
|
# Copyright 2020 Coop IT Easy SCRL fs |
|
|
# Houssine BAKKALI <houssine@coopiteasy.be> |
|
|
# Houssine BAKKALI <houssine@coopiteasy.be> |
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). |
|
|
|
|
|
from dateutil.relativedelta import relativedelta |
|
|
|
|
|
|
|
|
from odoo import api, fields, models |
|
|
from odoo import api, fields, models |
|
|
|
|
|
|
|
@ -12,13 +13,13 @@ class LoanInterestLine(models.Model): |
|
|
comodel_name="account.move", |
|
|
comodel_name="account.move", |
|
|
string="Loan due this fiscal year account move" |
|
|
string="Loan due this fiscal year account move" |
|
|
) |
|
|
) |
|
|
loan_reimbursment_move = fields.Many2one( |
|
|
|
|
|
|
|
|
loan_due_move = fields.Many2one( |
|
|
comodel_name="account.move", |
|
|
comodel_name="account.move", |
|
|
string="Loan reimbursement account move" |
|
|
|
|
|
|
|
|
string="Loan due this fiscal year account move" |
|
|
) |
|
|
) |
|
|
interest_payment_move = fields.Many2one( |
|
|
|
|
|
|
|
|
loan_reimbursment_move = fields.Many2one( |
|
|
comodel_name="account.move", |
|
|
comodel_name="account.move", |
|
|
string="Interest payment account move" |
|
|
|
|
|
|
|
|
string="Loan reimbursement account move" |
|
|
) |
|
|
) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
@ -48,54 +49,90 @@ class LoanInterestLine(models.Model): |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def generate_interest_payement_move_lines(self): |
|
|
|
|
|
self.ensure_one() |
|
|
|
|
|
move_line_obj = self.env["account.move.line"] |
|
|
|
|
|
|
|
|
def generate_payment_move_lines(self): |
|
|
|
|
|
|
|
|
|
|
|
for line in self: |
|
|
|
|
|
if not self.loan_reimbursment_move: |
|
|
|
|
|
company = line.company_id |
|
|
|
|
|
move = line.create_move() |
|
|
|
|
|
|
|
|
|
|
|
debit_vals = line.get_move_line(line.partner_id) |
|
|
|
|
|
loaner_vals = line.get_move_line(line.partner_id) |
|
|
|
|
|
|
|
|
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"] = line.interest |
|
|
|
|
|
debit_vals["account_id"] = company.interest_account.id |
|
|
|
|
|
|
|
|
debit_vals["debit"] = self.interest |
|
|
|
|
|
debit_vals["account_id"] = self.company_id.interest_account.id |
|
|
|
|
|
|
|
|
if line.due_loan_amount > 0 and line.net_interest > 0: |
|
|
|
|
|
loaner_vals["credit"] = line.due_amount |
|
|
|
|
|
elif line.due_loan_amount > 0: |
|
|
|
|
|
loaner_vals["credit"] = line.due_loan_amount |
|
|
|
|
|
elif line.net_interest > 0: |
|
|
|
|
|
loaner_vals["credit"] = line.net_interest |
|
|
|
|
|
loaner_vals["account_id"] = company.loaner_account |
|
|
|
|
|
|
|
|
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) |
|
|
|
|
|
|
|
|
vals_list = [debit_vals, loaner_vals] |
|
|
|
|
|
|
|
|
move_line_obj.create(vals_list) |
|
|
|
|
|
|
|
|
if line.taxes_amount > 0: |
|
|
|
|
|
tax_vals = self.get_move_line() |
|
|
|
|
|
tax_vals["credit"] = line.taxes_amount |
|
|
|
|
|
tax_vals["account_id"] = company.tax_account.id |
|
|
|
|
|
vals_list.append(tax_vals) |
|
|
|
|
|
|
|
|
self.interest_payment_mpve = move |
|
|
|
|
|
|
|
|
self.env["account.move.line"].create(vals_list) |
|
|
|
|
|
|
|
|
|
|
|
line.write({"loan_reimbursment_move": move.id, |
|
|
|
|
|
"state": "scheduled"}) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def generate_loan_due_fy(self): |
|
|
|
|
|
self.ensure_one() |
|
|
|
|
|
|
|
|
def generate_loan_due_fy(self, date): |
|
|
|
|
|
|
|
|
move_line_obj = self.env["account.move.line"] |
|
|
|
|
|
|
|
|
for line in self: |
|
|
|
|
|
if not self.loan_due_fy_move: |
|
|
|
|
|
company = line.line.company_id |
|
|
|
|
|
move = line.create_move(date) |
|
|
|
|
|
|
|
|
move = self.create_move(fields.Date.today()) |
|
|
|
|
|
|
|
|
debit_vals = line.get_move_line(line.partner_id) |
|
|
|
|
|
credit_vals = line.get_move_line(line.partner_id) |
|
|
|
|
|
|
|
|
debit_vals = self.get_move_line(self.partner_id) |
|
|
|
|
|
credit_vals = self.get_move_line(self.partner_id) |
|
|
|
|
|
|
|
|
debit_vals["debit"] = line.due_loan_amount |
|
|
|
|
|
debit_vals["date"] = date |
|
|
|
|
|
debit_vals["account_id"] = company.debt_long_term_account.id |
|
|
|
|
|
|
|
|
debit_vals["debit"] = self.due_amount |
|
|
|
|
|
debit_vals["account_id"] = self.company_id.debt_long_term_account.id |
|
|
|
|
|
|
|
|
credit_vals["credit"] = line.due_loan_amount |
|
|
|
|
|
credit_vals["credit"] = date |
|
|
|
|
|
credit_vals["account_id"] = company.debt_long_term_fy_account.id |
|
|
|
|
|
|
|
|
credit_vals["credit"] = self.due_amount |
|
|
|
|
|
credit_vals["account_id"] = self.company_id.debt_long_term_fy_account |
|
|
|
|
|
|
|
|
self.env["account.move.line"].create([debit_vals, credit_vals]) |
|
|
|
|
|
|
|
|
move_line_obj.create([debit_vals, credit_vals]) |
|
|
|
|
|
|
|
|
line.write({"loan_due_fy_move": move.id, |
|
|
|
|
|
"state": "due_fy"}) |
|
|
|
|
|
|
|
|
self.loan_due_fy_move = move |
|
|
|
|
|
|
|
|
@api.multi |
|
|
|
|
|
def generate_loan_due_now(self): |
|
|
|
|
|
|
|
|
|
|
|
for line in self: |
|
|
|
|
|
if line.loan_due_move: |
|
|
|
|
|
company = line.company_id |
|
|
|
|
|
move = line.create_move(fields.Date.today()) |
|
|
|
|
|
|
|
|
|
|
|
debit_vals = line.get_move_line(line) |
|
|
|
|
|
credit_vals = line.get_move_line(line.partner_id) |
|
|
|
|
|
|
|
|
|
|
|
debit_vals["debit"] = line.due_loan_amount |
|
|
|
|
|
debit_vals["account_id"] = company.debt_long_term_fy_account.id |
|
|
|
|
|
|
|
|
|
|
|
credit_vals["credit"] = line.due_loan_amount |
|
|
|
|
|
credit_vals["account_id"] = company.debt_long_term_due_account |
|
|
|
|
|
|
|
|
|
|
|
self.env["account.move.line"].create([debit_vals, credit_vals]) |
|
|
|
|
|
|
|
|
|
|
|
line.write({"loan_due_move": move.id, |
|
|
|
|
|
"state": "due"}) |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
|
def _generate_move_line_debt_end_fy(self): |
|
|
def _generate_move_line_debt_end_fy(self): |
|
|
fy = self.env["account.fiscal.year"].get_next_fiscal_year() |
|
|
fy = self.env["account.fiscal.year"].get_next_fiscal_year() |
|
|
|
|
|
date = fy.date_from - relativedelta(days=1) |
|
|
if fy: |
|
|
if fy: |
|
|
interest_lines = self.search([ |
|
|
interest_lines = self.search([ |
|
|
('due_date', '>=', fy.date_from), |
|
|
('due_date', '>=', fy.date_from), |
|
@ -103,21 +140,18 @@ class LoanInterestLine(models.Model): |
|
|
('due_loan_amount', '>', 0), |
|
|
('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() |
|
|
|
|
|
|
|
|
interest_lines.generate_loan_due_fy(date) |
|
|
|
|
|
|
|
|
@api.model |
|
|
@api.model |
|
|
def _generate_payment_move(self): |
|
|
def _generate_payment_move(self): |
|
|
# TODO configure how many days before you want generate the move lines |
|
|
# TODO configure how many days before you want generate the move lines |
|
|
|
|
|
fy = self.env["account.fiscal.year"].get_next_fiscal_year() |
|
|
interest_lines = self.search([ |
|
|
interest_lines = self.search([ |
|
|
('due_date', '>=', fy.date_from), |
|
|
('due_date', '>=', fy.date_from), |
|
|
('due_date', '<=', fy.date_to), |
|
|
('due_date', '<=', fy.date_to), |
|
|
('due_amount', '>', 0), |
|
|
('due_amount', '>', 0), |
|
|
]) |
|
|
]) |
|
|
for line in interest_lines: |
|
|
|
|
|
if line.interest > 0 and not line.loan_reimbursment_move: |
|
|
|
|
|
line.generate_interest_payement_move_lines() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
interest_lines.generate_payment_move_lines() |
|
|
|
|
|
|
|
|
return True |
|
|
return True |