From b6a97b73bed5a9ccc6a7ebf334c5f3193a60b970 Mon Sep 17 00:00:00 2001 From: houssine Date: Tue, 8 Dec 2020 12:22:17 +0100 Subject: [PATCH] [IMP] add interest accounting move lines still in wip --- .../models/interest_line.py | 24 +++++++++++++++++++ .../wizard/end_of_year_operation.py | 14 ++++++++++- 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/easy_my_coop_loan_account/models/interest_line.py b/easy_my_coop_loan_account/models/interest_line.py index ad28d16..6b5f90e 100644 --- a/easy_my_coop_loan_account/models/interest_line.py +++ b/easy_my_coop_loan_account/models/interest_line.py @@ -81,6 +81,30 @@ class LoanInterestLine(models.Model): line.write({"loan_reimbursment_move": move.id, "state": "scheduled"}) + @api.multi + def generate_interest_move_lines_fy(self, date): + + for line in self: + if not self.loan_due_fy_move: + 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) + + deb_vals["debit"] = line.due_loan_amount + deb_vals["date"] = date + deb_vals["account_id"] = company.debt_long_term_account.id + + cred_vals["credit"] = line.due_loan_amount + cred_vals["date"] = date + cred_vals["account_id"] = company.debt_long_term_fy_account.id + + self.env["account.move.line"].create([deb_vals, cred_vals]) + + line.write({"loan_due_fy_move": move.id, + "state": "due_fy"}) + @api.multi def generate_loan_due_fy(self, date): diff --git a/easy_my_coop_loan_account/wizard/end_of_year_operation.py b/easy_my_coop_loan_account/wizard/end_of_year_operation.py index 12a4bbb..6ce356c 100644 --- a/easy_my_coop_loan_account/wizard/end_of_year_operation.py +++ b/easy_my_coop_loan_account/wizard/end_of_year_operation.py @@ -48,4 +48,16 @@ class LoanEndOfYearOperation(models.TransientModel): raise UserError("There is no account move lines to" " generate for the selected loan issue") elif self.operation_type == "eoy_interest": - print() + if next_fy: + interest_lines = interest_line_obj.search([ + ("due_date", ">=", next_fy.date_from), + ("due_date", "<=", next_fy.date_to), + ("interest", ">", 0), + ("loan_issue_id", "in", loan_issues.ids) + ]) + + if interest_lines: + interest_lines.generate_loan_due_fy(last_fy_day) + else: + raise UserError("There is no account move lines to" + " generate for the selected loan issue")