|
@ -3,6 +3,8 @@ |
|
|
# 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 odoo import api, fields, models |
|
|
from odoo import api, fields, models |
|
|
|
|
|
|
|
|
|
|
|
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" |
|
@ -22,6 +24,7 @@ class LoanEndOfYearOperation(models.TransientModel): |
|
|
@api.multi |
|
|
@api.multi |
|
|
def run(self): |
|
|
def run(self): |
|
|
afy_obj = self.env["account.fiscal.year"] |
|
|
afy_obj = self.env["account.fiscal.year"] |
|
|
|
|
|
interest_line_obj = self.env["loan.interest.line"] |
|
|
|
|
|
|
|
|
loan_issues = self.env["loan.issue"].browse( |
|
|
loan_issues = self.env["loan.issue"].browse( |
|
|
self._context.get("active_ids") |
|
|
self._context.get("active_ids") |
|
@ -30,15 +33,19 @@ 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 self.operation_type == "debt_eoy": |
|
|
|
|
|
|
|
|
if self.operation_type == "eoy_debt": |
|
|
if next_fy: |
|
|
if next_fy: |
|
|
interest_lines = self.search([ |
|
|
|
|
|
|
|
|
interest_lines = interest_line_obj.search([ |
|
|
('due_date', '>=', next_fy.date_from), |
|
|
('due_date', '>=', next_fy.date_from), |
|
|
('due_date', '<=', next_fy.date_to), |
|
|
('due_date', '<=', next_fy.date_to), |
|
|
('due_loan_amount', '>', 0), |
|
|
('due_loan_amount', '>', 0), |
|
|
("loan_issue_id", "in", loan_issues.ids) |
|
|
("loan_issue_id", "in", loan_issues.ids) |
|
|
]) |
|
|
]) |
|
|
|
|
|
|
|
|
|
|
|
if interest_lines: |
|
|
interest_lines.generate_loan_due_fy(last_fy_day) |
|
|
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") |
|
|
elif self.operation_type == "eoy_interest": |
|
|
elif self.operation_type == "eoy_interest": |
|
|
print() |
|
|
print() |