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.

51 lines
1.7 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. from odoo.exceptions import UserError
  6. class LoanEndOfYearOperation(models.TransientModel):
  7. _name = "loan.end.of.year.operation"
  8. operation_type = fields.Selection(
  9. [("eoy_debt", "End of year debt operation"),
  10. ("eoy_interest", "End of year interest operation")],
  11. required=True,
  12. string="Operation type"
  13. )
  14. ongoing_fy_id = fields.Many2one(
  15. comodel_name="account.fiscal.year",
  16. string="Ongoing fiscal year",
  17. required=True
  18. )
  19. @api.multi
  20. def run(self):
  21. afy_obj = self.env["account.fiscal.year"]
  22. interest_line_obj = self.env["loan.interest.line"]
  23. loan_issues = self.env["loan.issue"].browse(
  24. self._context.get("active_ids")
  25. )
  26. last_fy_day = self.ongoing_fy_id.date_to
  27. next_fy = afy_obj.get_next_fiscal_year(last_fy_day)
  28. if self.operation_type == "eoy_debt":
  29. if next_fy:
  30. interest_lines = interest_line_obj.search([
  31. ('due_date', '>=', next_fy.date_from),
  32. ('due_date', '<=', next_fy.date_to),
  33. ('due_loan_amount', '>', 0),
  34. ("loan_issue_id", "in", loan_issues.ids)
  35. ])
  36. if interest_lines:
  37. interest_lines.generate_loan_due_fy(last_fy_day)
  38. else:
  39. raise UserError("There is no account move lines to"
  40. " generate for the selected loan issue")
  41. elif self.operation_type == "eoy_interest":
  42. print()