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
45 lines
1.7 KiB
# Copyright 2018 ACSONE SA/NV
|
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl).
|
|
|
|
from odoo import api, models
|
|
|
|
|
|
class ContractLine(models.Model):
|
|
_inherit = "contract.line"
|
|
|
|
@api.model
|
|
def _compute_prorated(
|
|
self, real_next_date, real_last_date, therical_next_date,
|
|
therical_last_date):
|
|
def _invoiced_days(next_date, last_date):
|
|
return (next_date - last_date).days + 1
|
|
|
|
return _invoiced_days(real_next_date, real_last_date) / _invoiced_days(
|
|
therical_next_date, therical_last_date
|
|
)
|
|
|
|
@api.multi
|
|
def compute_prorated(self, period_first_date, period_last_date,
|
|
invoice_date):
|
|
self.ensure_one()
|
|
relative_delta = self.get_relative_delta(
|
|
self.recurring_rule_type, self.recurring_interval
|
|
)
|
|
theoretical_next_date = invoice_date
|
|
if self.recurring_rule_type == "monthlylastday":
|
|
relative_delta = self.get_relative_delta("monthly",
|
|
self.recurring_interval)
|
|
theoretical_next_date += self.get_relative_delta("daily", 1)
|
|
if (
|
|
self.recurring_invoicing_type == "pre-paid"
|
|
and self.recurring_rule_type != "monthlylastday"
|
|
):
|
|
theoretical_next_date += relative_delta
|
|
theoretical_last_date = theoretical_next_date - relative_delta
|
|
theoretical_next_date -= self.get_relative_delta("daily", 1)
|
|
real_last_date = period_first_date
|
|
real_next_date = period_last_date
|
|
return self._compute_prorated(
|
|
real_next_date, real_last_date, theoretical_next_date,
|
|
theoretical_last_date
|
|
)
|