From 705a908d048f6bea0e7e51a79d4f1baea779217a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jes=C3=BAs=20Feliciano=20Valdez=20Cruz=20=5BVauxoo=5D?= Date: Sun, 28 May 2023 02:02:12 +0000 Subject: [PATCH] [MIG] contract_sale_generation: Migration to 16.0 --- contract_sale_generation/__manifest__.py | 2 +- contract_sale_generation/models/contract.py | 8 +++++-- .../models/contract_line.py | 5 ++--- contract_sale_generation/tests/common.py | 22 +++++++++---------- .../tests/test_contract_sale.py | 3 ++- 5 files changed, 22 insertions(+), 18 deletions(-) diff --git a/contract_sale_generation/__manifest__.py b/contract_sale_generation/__manifest__.py index 663a1d1822e..7cee130530b 100644 --- a/contract_sale_generation/__manifest__.py +++ b/contract_sale_generation/__manifest__.py @@ -5,7 +5,7 @@ { "name": "Contracts Management - Recurring Sales", - "version": "15.0.1.0.3", + "version": "16.0.1.0.0", "category": "Contract Management", "license": "AGPL-3", "author": "ACSONE SA/NV, PESOL, Odoo Community Association (OCA)", diff --git a/contract_sale_generation/models/contract.py b/contract_sale_generation/models/contract.py index 80ba905b742..f581ef7be25 100644 --- a/contract_sale_generation/models/contract.py +++ b/contract_sale_generation/models/contract.py @@ -32,8 +32,12 @@ def _prepare_sale(self, date_ref): sale.payment_term_id = self.payment_term_id.id if self.fiscal_position_id: sale.fiscal_position_id = self.fiscal_position_id.id - # Get other sale values from partner onchange - sale.onchange_partner_id() + # Get other sale values + sale._compute_partner_shipping_id() + sale._compute_pricelist_id() + sale._compute_currency_rate() + sale._compute_user_id() + sale._compute_team_id() return sale._convert_to_write(sale._cache) def _get_related_sales(self): diff --git a/contract_sale_generation/models/contract_line.py b/contract_sale_generation/models/contract_line.py index ebbb3274915..e6e69fa525f 100644 --- a/contract_sale_generation/models/contract_line.py +++ b/contract_sale_generation/models/contract_line.py @@ -11,7 +11,7 @@ def _prepare_sale_line_vals(self, dates, order_id=False): sale_line_vals = { "product_id": self.product_id.id, "product_uom_qty": self._get_quantity_to_invoice(*dates), - "product_uom": self.uom_id.id, + "product_uom": self.product_id.uom_id.id, "discount": self.discount, "contract_line_id": self.id, "display_type": self.display_type, @@ -40,7 +40,7 @@ def _prepare_sale_line(self, order_id=False, sale_values=False): ) order_line.order_id = sale # Get other order line values from product onchange - order_line.product_id_change() + order_line._onchange_product_id_warning() sale_line_vals = order_line._convert_to_write(order_line._cache) # Insert markers name = self._insert_markers(dates[0], dates[1]) @@ -48,7 +48,6 @@ def _prepare_sale_line(self, order_id=False, sale_values=False): { "sequence": self.sequence, "name": name, - "analytic_tag_ids": [(6, 0, self.analytic_tag_ids.ids)], "price_unit": self.price_unit, } ) diff --git a/contract_sale_generation/tests/common.py b/contract_sale_generation/tests/common.py index fe100b02faa..5b0fdb99c02 100644 --- a/contract_sale_generation/tests/common.py +++ b/contract_sale_generation/tests/common.py @@ -22,6 +22,7 @@ def setUpClass(cls): cls.analytic_account = cls.env["account.analytic.account"].create( { "name": "Contracts", + "plan_id": cls.env.ref("analytic.analytic_plan_internal").id, } ) cls.payment_term_id = cls.env.ref( @@ -58,6 +59,7 @@ def setUpClass(cls): "discount": 50, "recurring_rule_type": "yearly", "recurring_interval": 1, + "display_type": False, } cls.template_vals = { "name": "Test Contract Template", @@ -89,26 +91,23 @@ def setUpClass(cls): ) cls.line_vals = { "name": "Services from #START# to #END#", + "product_id": cls.product_1.id, + "uom_id": cls.product_1.uom_id.id, "quantity": 1, "price_unit": 100, "discount": 50, "recurring_rule_type": "monthly", "recurring_interval": 1, - "date_start": "2020-01-01", + "date_start": "2020-01-15", "recurring_next_date": "2020-01-15", + "display_type": False, } + discount_line_group_id = cls.env.ref("product.group_discount_per_so_line") + cls.env.user.groups_id = [(4, discount_line_group_id.id)] + with Form(cls.contract) as contract_form, freeze_time(contract_date): contract_form.contract_template_id = cls.template - with contract_form.contract_line_ids.new() as line_form: - line_form.product_id = cls.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 = "monthly" - line_form.recurring_interval = 1 - line_form.date_start = "2020-01-15" - line_form.recurring_next_date = "2020-01-15" + cls.contract.write({"contract_line_ids": [(0, 0, cls.line_vals)]}) cls.contract_line = cls.contract.contract_line_ids[1] cls.contract2 = cls.env["contract.contract"].create( @@ -133,6 +132,7 @@ def setUpClass(cls): "recurring_interval": 1, "date_start": "2018-02-15", "recurring_next_date": "2018-02-22", + "display_type": False, }, ) ], diff --git a/contract_sale_generation/tests/test_contract_sale.py b/contract_sale_generation/tests/test_contract_sale.py index a5eaf65009c..64cc7e2ce0b 100644 --- a/contract_sale_generation/tests/test_contract_sale.py +++ b/contract_sale_generation/tests/test_contract_sale.py @@ -64,6 +64,7 @@ def test_onchange_contract_template_id(self): "discount": 50, "recurring_rule_type": "yearly", "recurring_interval": 1, + "display_type": False, }, ) ], @@ -87,7 +88,7 @@ def test_contract_count_sale_2(self): self.assertEqual(set(action["domain"][0][2]), set(orders.ids)) def test_cron_recurring_create_sale(self): - self.contract_line.date_start = "2020-01-01" + self.contract_line.date_start = "2020-01-15" self.contract_line.recurring_invoicing_type = "post-paid" self.contract_line.date_end = "2020-03-15" self.contract_line._onchange_is_auto_renew()