From 2e84b92d07e6e28d7b1bba75f8e17ec54fbfaf8c Mon Sep 17 00:00:00 2001 From: Denis Roussel Date: Mon, 7 Mar 2022 14:37:16 +0100 Subject: [PATCH] [14.0][IMP] contract_sale_generation: Add tests with another recurrency --- contract_sale_generation/__manifest__.py | 2 +- .../tests/test_contract_sale_recurrency.py | 78 +++++++++++++++++++ 2 files changed, 79 insertions(+), 1 deletion(-) create mode 100644 contract_sale_generation/tests/test_contract_sale_recurrency.py diff --git a/contract_sale_generation/__manifest__.py b/contract_sale_generation/__manifest__.py index 758a23e0c..74af8013d 100644 --- a/contract_sale_generation/__manifest__.py +++ b/contract_sale_generation/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Contracts Management - Recurring Sales", - "version": "14.0.1.0.0", + "version": "14.0.1.0.1", "category": "Contract Management", "license": "AGPL-3", "author": "ACSONE SA/NV, PESOL, Odoo Community Association (OCA)", diff --git a/contract_sale_generation/tests/test_contract_sale_recurrency.py b/contract_sale_generation/tests/test_contract_sale_recurrency.py new file mode 100644 index 000000000..63ffd539b --- /dev/null +++ b/contract_sale_generation/tests/test_contract_sale_recurrency.py @@ -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 + )