# 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()