|
@ -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 |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -19,6 +20,14 @@ class LoanInterestLine(models.Model): |
|
|
comodel_name="account.move", |
|
|
comodel_name="account.move", |
|
|
string="Loan reimbursement account move" |
|
|
string="Loan reimbursement account move" |
|
|
) |
|
|
) |
|
|
|
|
|
interest_closing_fy = fields.Many2one( |
|
|
|
|
|
comodel_name="account.move", |
|
|
|
|
|
string="Interest closing fiscal year account move" |
|
|
|
|
|
) |
|
|
|
|
|
interest_opening_fy = fields.Many2one( |
|
|
|
|
|
comodel_name="account.move", |
|
|
|
|
|
string="Interest opening fiscal year account move" |
|
|
|
|
|
) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def get_move_line(self, move_id, partner=None): |
|
|
def get_move_line(self, move_id, partner=None): |
|
@ -71,7 +80,7 @@ class LoanInterestLine(models.Model): |
|
|
vals_list = [debit_vals, loaner_vals] |
|
|
vals_list = [debit_vals, loaner_vals] |
|
|
|
|
|
|
|
|
if line.taxes_amount > 0: |
|
|
if line.taxes_amount > 0: |
|
|
tax_vals = self.get_move_line(move) |
|
|
|
|
|
|
|
|
tax_vals = line.get_move_line(move) |
|
|
tax_vals["credit"] = line.taxes_amount |
|
|
tax_vals["credit"] = line.taxes_amount |
|
|
tax_vals["account_id"] = company.tax_account.id |
|
|
tax_vals["account_id"] = company.tax_account.id |
|
|
vals_list.append(tax_vals) |
|
|
vals_list.append(tax_vals) |
|
@ -82,28 +91,54 @@ class LoanInterestLine(models.Model): |
|
|
"state": "scheduled"}) |
|
|
"state": "scheduled"}) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def generate_interest_move_lines_fy(self, date): |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def generate_interest_move_lines_fy(self, date, next_fy): |
|
|
|
|
|
aml_obj = self.env["account.move.line"] |
|
|
for line in self: |
|
|
for line in self: |
|
|
if not self.loan_due_fy_move: |
|
|
|
|
|
|
|
|
if not self.interest_closing_fy: |
|
|
company = line.company_id |
|
|
company = line.company_id |
|
|
move = line.create_move(date) |
|
|
|
|
|
|
|
|
|
|
|
deb_vals = line.get_move_line(move, line.partner_id) |
|
|
|
|
|
cred_vals = line.get_move_line(move, line.partner_id) |
|
|
|
|
|
|
|
|
# compute the prorata interest for the fiscal year |
|
|
|
|
|
prorata_date = line.due_date - relativedelta(years=-1) |
|
|
|
|
|
diff_days = (prorata_date - date).days |
|
|
|
|
|
days = line.loan_issue_id.get_number_of_days(date.year) |
|
|
|
|
|
|
|
|
deb_vals["debit"] = line.due_loan_amount |
|
|
|
|
|
|
|
|
previous_interest = line.accrued_interest - line.interest |
|
|
|
|
|
prorata_interest = line.interest * (diff_days / days) |
|
|
|
|
|
interest_fy = previous_interest + prorata_interest |
|
|
|
|
|
|
|
|
|
|
|
# create interest closing account move lines |
|
|
|
|
|
close_fy_move = line.create_move(date) |
|
|
|
|
|
deb_vals = line.get_move_line(close_fy_move, line.partner_id) |
|
|
|
|
|
cred_vals = line.get_move_line(close_fy_move, line.partner_id) |
|
|
|
|
|
|
|
|
|
|
|
deb_vals["debit"] = interest_fy |
|
|
deb_vals["date"] = date |
|
|
deb_vals["date"] = date |
|
|
deb_vals["account_id"] = company.debt_long_term_account.id |
|
|
|
|
|
|
|
|
deb_vals["account_id"] = company.interest_account.id |
|
|
|
|
|
|
|
|
cred_vals["credit"] = line.due_loan_amount |
|
|
|
|
|
|
|
|
cred_vals["credit"] = interest_fy |
|
|
cred_vals["date"] = date |
|
|
cred_vals["date"] = date |
|
|
cred_vals["account_id"] = company.debt_long_term_fy_account.id |
|
|
|
|
|
|
|
|
cred_vals["account_id"] = company.expense_account.id |
|
|
|
|
|
|
|
|
self.env["account.move.line"].create([deb_vals, cred_vals]) |
|
|
|
|
|
|
|
|
aml_obj.create([deb_vals, cred_vals]) |
|
|
|
|
|
|
|
|
line.write({"loan_due_fy_move": move.id, |
|
|
|
|
|
"state": "due_fy"}) |
|
|
|
|
|
|
|
|
line.write({"interest_closing_fy": close_fy_move.id}) |
|
|
|
|
|
|
|
|
|
|
|
# create interest opening account move lines |
|
|
|
|
|
opening_date = next_fy.date_from |
|
|
|
|
|
open_fy_move = line.create_move(opening_date) |
|
|
|
|
|
deb_vals = line.get_move_line(open_fy_move, line.partner_id) |
|
|
|
|
|
cred_vals = line.get_move_line(open_fy_move, line.partner_id) |
|
|
|
|
|
|
|
|
|
|
|
deb_vals["debit"] = interest_fy |
|
|
|
|
|
deb_vals["date"] = opening_date |
|
|
|
|
|
deb_vals["account_id"] = company.expense_account.id |
|
|
|
|
|
|
|
|
|
|
|
cred_vals["credit"] = interest_fy |
|
|
|
|
|
cred_vals["date"] = opening_date |
|
|
|
|
|
cred_vals["account_id"] = company.interest_account.id |
|
|
|
|
|
|
|
|
|
|
|
aml_obj.create([deb_vals, cred_vals]) |
|
|
|
|
|
line.write({"interest_opening_fy": open_fy_move.id}) |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def generate_loan_due_fy(self, date): |
|
|
def generate_loan_due_fy(self, date): |
|
@ -137,7 +172,7 @@ class LoanInterestLine(models.Model): |
|
|
company = line.company_id |
|
|
company = line.company_id |
|
|
move = line.create_move(fields.Date.today()) |
|
|
move = line.create_move(fields.Date.today()) |
|
|
|
|
|
|
|
|
debit_vals = line.get_move_line(move, line) |
|
|
|
|
|
|
|
|
debit_vals = line.get_move_line(move, line.partner_id) |
|
|
credit_vals = line.get_move_line(move, line.partner_id) |
|
|
credit_vals = line.get_move_line(move, line.partner_id) |
|
|
|
|
|
|
|
|
debit_vals["debit"] = line.due_loan_amount |
|
|
debit_vals["debit"] = line.due_loan_amount |
|
|