You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

44 lines
1.4 KiB

  1. # Copyright 2020 Coop IT Easy SCRL fs
  2. # Houssine BAKKALI <houssine@coopiteasy.be>
  3. # License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl.html).
  4. from odoo import api, fields, models
  5. class LoanEndOfYearOperation(models.TransientModel):
  6. _name = "loan.end.of.year.operation"
  7. operation_type = fields.Selection(
  8. [("eoy_debt", "End of year debt operation"),
  9. ("eoy_interest", "End of year interest operation")],
  10. required=True,
  11. string="Operation type"
  12. )
  13. ongoing_fy_id = fields.Many2one(
  14. comodel_name="account.fiscal.year",
  15. string="Ongoing fiscal year",
  16. required=True
  17. )
  18. @api.multi
  19. def run(self):
  20. afy_obj = self.env["account.fiscal.year"]
  21. loan_issues = self.env["loan.issue"].browse(
  22. self._context.get("active_ids")
  23. )
  24. last_fy_day = self.ongoing_fy_id.date_to
  25. next_fy = afy_obj.get_next_fiscal_year(last_fy_day)
  26. if self.operation_type == "debt_eoy":
  27. if next_fy:
  28. interest_lines = self.search([
  29. ('due_date', '>=', next_fy.date_from),
  30. ('due_date', '<=', next_fy.date_to),
  31. ('due_loan_amount', '>', 0),
  32. ("loan_issue_id", "in", loan_issues.ids)
  33. ])
  34. interest_lines.generate_loan_due_fy(last_fy_day)
  35. elif self.operation_type == "eoy_interest":
  36. print()