|
@ -8,7 +8,12 @@ from odoo.exceptions import UserError |
|
|
|
|
|
|
|
|
class LoanEndOfYearOperation(models.TransientModel): |
|
|
class LoanEndOfYearOperation(models.TransientModel): |
|
|
_name = "loan.end.of.year.operation" |
|
|
_name = "loan.end.of.year.operation" |
|
|
|
|
|
|
|
|
|
|
|
operation_type = fields.Selection( |
|
|
|
|
|
[("eoy_operation", "End of year operation"), |
|
|
|
|
|
("loan_due", "Loan payment account move lines")], |
|
|
|
|
|
required=True, |
|
|
|
|
|
string="Operation type" |
|
|
|
|
|
) |
|
|
ongoing_fy_id = fields.Many2one( |
|
|
ongoing_fy_id = fields.Many2one( |
|
|
comodel_name="account.fiscal.year", |
|
|
comodel_name="account.fiscal.year", |
|
|
string="Ongoing fiscal year", |
|
|
string="Ongoing fiscal year", |
|
@ -17,6 +22,7 @@ class LoanEndOfYearOperation(models.TransientModel): |
|
|
|
|
|
|
|
|
@api.multi |
|
|
@api.multi |
|
|
def run(self): |
|
|
def run(self): |
|
|
|
|
|
self.ensure_one() |
|
|
afy_obj = self.env["account.fiscal.year"] |
|
|
afy_obj = self.env["account.fiscal.year"] |
|
|
interest_line_obj = self.env["loan.interest.line"] |
|
|
interest_line_obj = self.env["loan.interest.line"] |
|
|
|
|
|
|
|
@ -27,27 +33,31 @@ class LoanEndOfYearOperation(models.TransientModel): |
|
|
last_fy_day = self.ongoing_fy_id.date_to |
|
|
last_fy_day = self.ongoing_fy_id.date_to |
|
|
next_fy = afy_obj.get_next_fiscal_year(last_fy_day) |
|
|
next_fy = afy_obj.get_next_fiscal_year(last_fy_day) |
|
|
|
|
|
|
|
|
if next_fy: |
|
|
|
|
|
interest_lines_loan = interest_line_obj.search([ |
|
|
|
|
|
("due_date", ">=", next_fy.date_from), |
|
|
|
|
|
("due_date", "<=", next_fy.date_to), |
|
|
|
|
|
("due_loan_amount", ">", 0), |
|
|
|
|
|
("loan_issue_id", "in", loan_issues.ids), |
|
|
|
|
|
("loan_reimbursment_move", "=", False) |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
interest_lines_loan.generate_loan_due_fy(last_fy_day) |
|
|
|
|
|
interest_lines_inter = 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), |
|
|
|
|
|
("interest_closing_fy", "=", False), |
|
|
|
|
|
("interest_opening_fy", "=", False) |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
interest_lines_inter.generate_interest_move_lines_fy(last_fy_day, |
|
|
|
|
|
next_fy) |
|
|
|
|
|
if not interest_lines_loan and not interest_lines_inter: |
|
|
|
|
|
raise UserError("There is no end of year account move lines to" |
|
|
|
|
|
" generate for the selected loan issue") |
|
|
|
|
|
|
|
|
if self.ongoing_fy_id == "eoy_operation": |
|
|
|
|
|
if next_fy: |
|
|
|
|
|
interest_lines_loan = interest_line_obj.search([ |
|
|
|
|
|
("due_date", ">=", next_fy.date_from), |
|
|
|
|
|
("due_date", "<=", next_fy.date_to), |
|
|
|
|
|
("due_loan_amount", ">", 0), |
|
|
|
|
|
("loan_issue_id", "in", loan_issues.ids), |
|
|
|
|
|
("loan_reimbursment_move", "=", False) |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
interest_lines_loan.generate_loan_due_fy(last_fy_day) |
|
|
|
|
|
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), |
|
|
|
|
|
("interest_closing_fy", "=", False), |
|
|
|
|
|
("interest_opening_fy", "=", False) |
|
|
|
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
interest_lines.generate_interest_move_lines_fy(last_fy_day, |
|
|
|
|
|
next_fy) |
|
|
|
|
|
if not interest_lines_loan and not interest_lines: |
|
|
|
|
|
raise UserError("There is no end of year account move" |
|
|
|
|
|
" lines to generate for the selected loan" |
|
|
|
|
|
" issue") |
|
|
|
|
|
elif self.ongoing_fy_id == "loan_due": |
|
|
|
|
|
print("lol") |