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..f9151349 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,14 +96,11 @@ def test_wizard_configuration(self): self.assertTrue(len(config_variants) == 1, "Wizard did not create a configurable variant") - def test_reconfiguration(self): - """Test reconfiguration functionality of the wizard""" - self.test_wizard_configuration() - - order_line = self.so.order_line.filtered( - lambda l: l.product_id.config_ok - ) + created_line = self.so.order_line - existing_lines + self.assertTrue(len(created_line) == 1, + "Wizard did not create an order line") + def do_reconfigure(self, order_line): reconfig_action = order_line.reconfigure_product() wizard = self.env['product.configurator'].browse( @@ -115,9 +114,37 @@ def test_reconfiguration(self): while wizard.action_next_step(): pass + 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 + ) + + self.do_reconfigure(order_line) + config_variants = self.env['product.product'].search([ ('config_ok', '=', True) ]) 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 + self.do_reconfigure(order_line) + + 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 @@ -