mirror of
https://github.com/OCA/contract.git
synced 2025-02-13 17:57:24 +02:00
@@ -611,19 +611,12 @@ class ContractLine(models.Model):
|
|||||||
return name
|
return name
|
||||||
|
|
||||||
def _update_recurring_next_date(self):
|
def _update_recurring_next_date(self):
|
||||||
|
# FIXME: Change method name according to real updated field
|
||||||
|
# e.g.: _update_last_date_invoiced()
|
||||||
for rec in self:
|
for rec in self:
|
||||||
last_date_invoiced = rec.next_period_date_end
|
last_date_invoiced = rec.next_period_date_end
|
||||||
recurring_next_date = rec.get_next_invoice_date(
|
|
||||||
last_date_invoiced + relativedelta(days=1),
|
|
||||||
rec.recurring_invoicing_type,
|
|
||||||
rec.recurring_invoicing_offset,
|
|
||||||
rec.recurring_rule_type,
|
|
||||||
rec.recurring_interval,
|
|
||||||
max_date_end=rec.date_end,
|
|
||||||
)
|
|
||||||
rec.write(
|
rec.write(
|
||||||
{
|
{
|
||||||
"recurring_next_date": recurring_next_date,
|
|
||||||
"last_date_invoiced": last_date_invoiced,
|
"last_date_invoiced": last_date_invoiced,
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ class ContractRecurrencyMixin(models.AbstractModel):
|
|||||||
|
|
||||||
@api.depends("next_period_date_start")
|
@api.depends("next_period_date_start")
|
||||||
def _compute_recurring_next_date(self):
|
def _compute_recurring_next_date(self):
|
||||||
for rec in self.filtered("next_period_date_start"):
|
for rec in self:
|
||||||
rec.recurring_next_date = self.get_next_invoice_date(
|
rec.recurring_next_date = self.get_next_invoice_date(
|
||||||
rec.next_period_date_start,
|
rec.next_period_date_start,
|
||||||
rec.recurring_invoicing_type,
|
rec.recurring_invoicing_type,
|
||||||
|
|||||||
@@ -120,6 +120,7 @@ class ContractContract(models.Model):
|
|||||||
lambda sale: sale.contract_auto_confirm
|
lambda sale: sale.contract_auto_confirm
|
||||||
)
|
)
|
||||||
sale_orders_to_confirm.action_confirm()
|
sale_orders_to_confirm.action_confirm()
|
||||||
|
self._compute_recurring_next_date()
|
||||||
return sale_orders
|
return sale_orders
|
||||||
|
|
||||||
@api.model
|
@api.model
|
||||||
|
|||||||
@@ -76,6 +76,7 @@ class ContractSaleCommon:
|
|||||||
"generation_type": "sale",
|
"generation_type": "sale",
|
||||||
"sale_autoconfirm": False,
|
"sale_autoconfirm": False,
|
||||||
"group_id": cls.analytic_account.id,
|
"group_id": cls.analytic_account.id,
|
||||||
|
"date_start": "2020-01-15",
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
cls.line_vals = {
|
cls.line_vals = {
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
# Copyright 2022 ACSONE SA/NV
|
||||||
|
# License AGPL-3.0 or later (https://www.gnu.org/licenses/agpl).
|
||||||
|
|
||||||
|
from freezegun.api import freeze_time
|
||||||
|
|
||||||
|
from odoo import fields
|
||||||
|
from odoo.tests import Form
|
||||||
|
from odoo.tests.common import SavepointCase
|
||||||
|
|
||||||
|
from .common import ContractSaleCommon
|
||||||
|
|
||||||
|
|
||||||
|
def to_date(date):
|
||||||
|
return fields.Date.to_date(date)
|
||||||
|
|
||||||
|
|
||||||
|
today = "2020-01-15"
|
||||||
|
|
||||||
|
|
||||||
|
class TestContractSale(ContractSaleCommon, SavepointCase):
|
||||||
|
@classmethod
|
||||||
|
def setUpClass(cls):
|
||||||
|
super().setUpClass()
|
||||||
|
cls.contract_obj = cls.env["contract.contract"]
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def _create_contract(cls):
|
||||||
|
cls.contract = cls.contract.create(
|
||||||
|
{
|
||||||
|
"name": "Test Contract",
|
||||||
|
"partner_id": cls.partner.id,
|
||||||
|
}
|
||||||
|
)
|
||||||
|
with Form(cls.contract) as contract_form:
|
||||||
|
contract_form.partner_id = cls.partner
|
||||||
|
contract_form.generation_type = "sale"
|
||||||
|
contract_form.group_id = cls.analytic_account
|
||||||
|
cls.contract = contract_form.save()
|
||||||
|
|
||||||
|
def test_contract_next_date(self):
|
||||||
|
"""
|
||||||
|
Change recurrence to weekly
|
||||||
|
Check the recurring next date value on lines
|
||||||
|
"""
|
||||||
|
with freeze_time(today):
|
||||||
|
self._create_contract()
|
||||||
|
self.contract.recurring_rule_type = "weekly"
|
||||||
|
with freeze_time(today):
|
||||||
|
with Form(self.contract) as contract_form:
|
||||||
|
with contract_form.contract_line_ids.new() as line_form:
|
||||||
|
line_form.product_id = self.product_1
|
||||||
|
line_form.name = "Services from #START# to #END#"
|
||||||
|
line_form.quantity = 1
|
||||||
|
line_form.price_unit = 100.0
|
||||||
|
line_form.discount = 50
|
||||||
|
line_form.recurring_rule_type = "weekly"
|
||||||
|
|
||||||
|
with freeze_time(today):
|
||||||
|
with Form(self.contract) as contract_form:
|
||||||
|
with contract_form.contract_line_ids.new() as line_form:
|
||||||
|
line_form.product_id = self.product_1
|
||||||
|
line_form.name = "Services from #START# to #END#"
|
||||||
|
line_form.quantity = 2
|
||||||
|
line_form.price_unit = 50.0
|
||||||
|
line_form.recurring_rule_type = "weekly"
|
||||||
|
|
||||||
|
self.assertEqual(
|
||||||
|
fields.Date.to_date("2020-01-15"), self.contract.recurring_next_date
|
||||||
|
)
|
||||||
|
|
||||||
|
self.contract.recurring_create_sale()
|
||||||
|
self.assertEqual(
|
||||||
|
fields.Date.to_date("2020-01-22"), self.contract.recurring_next_date
|
||||||
|
)
|
||||||
|
self.contract.recurring_create_sale()
|
||||||
|
self.assertEqual(
|
||||||
|
fields.Date.to_date("2020-01-29"), self.contract.recurring_next_date
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user