diff --git a/easy_my_coop_loan_account/models/account_fiscal_year.py b/easy_my_coop_loan_account/models/account_fiscal_year.py index 8f13d53..a6167f4 100644 --- a/easy_my_coop_loan_account/models/account_fiscal_year.py +++ b/easy_my_coop_loan_account/models/account_fiscal_year.py @@ -16,30 +16,30 @@ class AccountFiscalYear(models.Model): def get_ongoing_fiscal_year(self, company_id=None): today = fields.Date.today() fy = self.env["account.fiscal.year"].search([ - ('date_from', '>=', today), - ('date_to', '<=', today), - ('company_id', '=', company_id) + ('date_from', '<=', today), + ('date_to', '>=', today), ]) if not fy: - raise UserError("No fiscal year has been found for %d", - today) + raise UserError("No fiscal year has been found for %s" % + str(today)) if company_id: return fy.filtered(lambda r: r.company_id == company_id) return fy @api.model - def get_next_fiscal_year(self, company_id=None): - nextyear = fields.Date.today() + relativedelta(years=+1) + def get_next_fiscal_year(self, date=None, company_id=None): + if not date: + date = fields.Date.today() + nextyear = date + relativedelta(years=+1) fy = self.env["account.fiscal.year"].search([ - ('date_from', '>=', nextyear), - ('date_to', '<=', nextyear), - ('company_id', '=', company_id) + ('date_from', '<=', nextyear), + ('date_to', '>=', nextyear), ]) if not fy: - raise UserError("No next fiscal year has been found for %d", - nextyear) + raise UserError("No next fiscal year has been found for %s" % + str(nextyear)) if company_id: return fy.filtered(lambda r: r.company_id == company_id) diff --git a/easy_my_coop_loan_account/wizard/__init__.py b/easy_my_coop_loan_account/wizard/__init__.py new file mode 100644 index 0000000..27fa01d --- /dev/null +++ b/easy_my_coop_loan_account/wizard/__init__.py @@ -0,0 +1 @@ +from . import end_of_year_operation 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 new file mode 100644 index 0000000..0563c1e --- /dev/null +++ b/easy_my_coop_loan_account/wizard/end_of_year_operation.py @@ -0,0 +1,44 @@ +# Copyright 2020 Coop IT Easy SCRL fs +# Houssine BAKKALI +# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html). +from odoo import api, fields, models + + +class LoanEndOfYearOperation(models.TransientModel): + _name = "loan.end.of.year.operation" + + operation_type = fields.Selection( + [("eoy_debt", "End of year debt operation"), + ("eoy_interest", "End of year interest operation")], + required=True, + string="Operation type" + ) + ongoing_fy_id = fields.Many2one( + comodel_name="account.fiscal.year", + string="Ongoing fiscal year", + required=True + ) + + @api.multi + def run(self): + afy_obj = self.env["account.fiscal.year"] + + loan_issues = self.env["loan.issue"].browse( + self._context.get("active_ids") + ) + + last_fy_day = self.ongoing_fy_id.date_to + next_fy = afy_obj.get_next_fiscal_year(last_fy_day) + + if self.operation_type == "debt_eoy": + if next_fy: + interest_lines = self.search([ + ('due_date', '>=', next_fy.date_from), + ('due_date', '<=', next_fy.date_to), + ('due_loan_amount', '>', 0), + ("loan_issue_id", "in", loan_issues.ids) + ]) + + interest_lines.generate_loan_due_fy(last_fy_day) + elif self.operation_type == "eoy_interest": + print() diff --git a/easy_my_coop_loan_account/wizard/end_of_year_operation.xml b/easy_my_coop_loan_account/wizard/end_of_year_operation.xml new file mode 100644 index 0000000..b2ae81a --- /dev/null +++ b/easy_my_coop_loan_account/wizard/end_of_year_operation.xml @@ -0,0 +1,35 @@ + + + + End of year loan operation + loan.end.of.year.operation + +
+

+ End of year loan operation. +

+ + + + +
+
+
+
+
+ + +