mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
[ADD] Contract Variable Qty Prorated
This commit is contained in:
committed by
Stéphane Bidoul
parent
ec5f69b73b
commit
ebd1ed9fa3
45
contract_variable_qty_prorated/models/contract_line.py
Normal file
45
contract_variable_qty_prorated/models/contract_line.py
Normal file
@@ -0,0 +1,45 @@
|
||||
# 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, theoretical_next_date,
|
||||
theoretical_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(
|
||||
theoretical_next_date, theoretical_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
|
||||
)
|
||||
Reference in New Issue
Block a user