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.

45 lines
1.7 KiB

  1. # Copyright 2018 ACSONE SA/NV
  2. # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
  3. from odoo import api, models
  4. class ContractLine(models.Model):
  5. _inherit = "contract.line"
  6. @api.model
  7. def _compute_prorated(
  8. self, real_next_date, real_last_date, therical_next_date,
  9. therical_last_date):
  10. def _invoiced_days(next_date, last_date):
  11. return (next_date - last_date).days + 1
  12. return _invoiced_days(real_next_date, real_last_date) / _invoiced_days(
  13. therical_next_date, therical_last_date
  14. )
  15. @api.multi
  16. def compute_prorated(self, period_first_date, period_last_date,
  17. invoice_date):
  18. self.ensure_one()
  19. relative_delta = self.get_relative_delta(
  20. self.recurring_rule_type, self.recurring_interval
  21. )
  22. theoretical_next_date = invoice_date
  23. if self.recurring_rule_type == "monthlylastday":
  24. relative_delta = self.get_relative_delta("monthly",
  25. self.recurring_interval)
  26. theoretical_next_date += self.get_relative_delta("daily", 1)
  27. if (
  28. self.recurring_invoicing_type == "pre-paid"
  29. and self.recurring_rule_type != "monthlylastday"
  30. ):
  31. theoretical_next_date += relative_delta
  32. theoretical_last_date = theoretical_next_date - relative_delta
  33. theoretical_next_date -= self.get_relative_delta("daily", 1)
  34. real_last_date = period_first_date
  35. real_next_date = period_last_date
  36. return self._compute_prorated(
  37. real_next_date, real_last_date, theoretical_next_date,
  38. theoretical_last_date
  39. )