From 474b0ac1c1ca91643bb2db05903460897aa692d7 Mon Sep 17 00:00:00 2001 From: Richard deMeester Date: Mon, 10 Apr 2017 15:17:28 +1000 Subject: [PATCH 1/2] [ENH] Store source order_id to avoid active_id --- product_configurator_wizard/models/sale.py | 14 ++++++++ .../tests/test_wizard.py | 31 +++++++++++++++++- .../views/sale_view.xml | 4 +-- .../wizard/product_configurator.py | 32 ++++++++++++------- .../wizard/product_configurator_view.xml | 1 + 5 files changed, 67 insertions(+), 15 deletions(-) diff --git a/product_configurator_wizard/models/sale.py b/product_configurator_wizard/models/sale.py index 34eeacde..c5b2e7fb 100644 --- a/product_configurator_wizard/models/sale.py +++ b/product_configurator_wizard/models/sale.py @@ -39,3 +39,17 @@ def reconfigure_product(self): 'target': 'new', 'res_id': wizard.id, } + + +class SaleOrder(models.Model): + _inherit = 'sale.order' + + @api.multi + def configure_product(self): + res = self.env['ir.actions.act_window'].for_xml_id( + 'product_configurator_wizard', + 'action_wizard_product_configurator' + ) + res['context'] = {'default_order_id': self.id + } + return res diff --git a/product_configurator_wizard/tests/test_wizard.py b/product_configurator_wizard/tests/test_wizard.py index 3acd8643..41594b51 100644 --- a/product_configurator_wizard/tests/test_wizard.py +++ b/product_configurator_wizard/tests/test_wizard.py @@ -54,10 +54,12 @@ def wizard_write_proceed(self, wizard, attr_vals, value_ids=None): def test_wizard_configuration(self): """Test product configurator wizard""" + existing_lines = self.so.order_line + # Start a new configuration wizard wizard_obj = self.env['product.configurator'].with_context({ 'active_model': 'sale.order', - 'active_id': self.so.id + 'default_order_id': self.so.id }) wizard = wizard_obj.create({'product_tmpl_id': self.cfg_tmpl.id}) @@ -94,10 +96,16 @@ def test_wizard_configuration(self): self.assertTrue(len(config_variants) == 1, "Wizard did not create a configurable variant") + created_line = self.so.order_line - existing_lines + self.assertTrue(len(created_line) == 1, + "Wizard did not create an order line") + def test_reconfiguration(self): """Test reconfiguration functionality of the wizard""" self.test_wizard_configuration() + existing_lines = self.so.order_line + order_line = self.so.order_line.filtered( lambda l: l.product_id.config_ok ) @@ -121,3 +129,24 @@ def test_reconfiguration(self): self.assertTrue(len(config_variants) == 2, "Wizard reconfiguration did not create a new variant") + + created_line = self.so.order_line - existing_lines + self.assertTrue(len(created_line) == 0, + "Wizard created an order line on reconfiguration") + + # test that running through again with the same values does not + # create another variant + attr_vals = self.get_attr_values(['diesel', '220d']) + self.wizard_write_proceed(wizard, attr_vals) + + # Cycle through steps until wizard ends + while wizard.action_next_step(): + pass + + config_variants = self.env['product.product'].search([ + ('config_ok', '=', True) + ]) + + self.assertTrue(len(config_variants) == 2, + "Wizard reconfiguration created a redundant variant") + diff --git a/product_configurator_wizard/views/sale_view.xml b/product_configurator_wizard/views/sale_view.xml index 40485226..d8a4487f 100644 --- a/product_configurator_wizard/views/sale_view.xml +++ b/product_configurator_wizard/views/sale_view.xml @@ -17,10 +17,10 @@ -