From 4c99f3acb2c0b4d4be90f8e8cfb3641d73d5450a Mon Sep 17 00:00:00 2001 From: Patrick Wilson <36892066+patrickrwilson@users.noreply.github.com> Date: Tue, 10 May 2022 13:59:29 -0400 Subject: [PATCH 1/2] [IMP] product_state (copy=False) The product state shouldn't be copied when copying the product so this adds copy=False to the state field. [IMP] product_state: Add test for copy [FIX] Test --- product_state/models/product_template.py | 1 + product_state/tests/test_product_state.py | 15 ++++++++++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/product_state/models/product_template.py b/product_state/models/product_template.py index ca092d6dfd74..6fd17ce603d2 100644 --- a/product_state/models/product_template.py +++ b/product_state/models/product_template.py @@ -25,6 +25,7 @@ class ProductTemplate(models.Model): default=lambda self: self._get_default_product_state().id, index=True, tracking=10, + copy=False, ) def _inverse_product_state_id(self): diff --git a/product_state/tests/test_product_state.py b/product_state/tests/test_product_state.py index fb46aa505fba..30d02bc2a50d 100644 --- a/product_state/tests/test_product_state.py +++ b/product_state/tests/test_product_state.py @@ -75,7 +75,6 @@ def test_03_set_constrains_product_state(self): Create another default state, It should have the existing only one default state at time """ - with self.assertRaises(ValidationError) as cm: self.env["product.state"].create( {"name": "Default State 2", "code": "df2", "default": True} @@ -87,3 +86,17 @@ def test_04_invalid_state(self): self._create_product() with self.assertRaises(UserError): self.product.state = "new_code" + + def test_05_copy(self): + """ + Create product with non-default state. + Copy product. + The copy should have the default state. + """ + self._create_product() + self.product.state = "Code" + copied_product = self.product.copy() + self.assertEqual( + self.env.ref("product_state.product_state_sellable"), + copied_product.product_state_id, + ) From 223823053b15aadeaa1359e405be7f1fe3e9cccf Mon Sep 17 00:00:00 2001 From: Alessandro Uffreduzzi Date: Wed, 27 Jul 2022 18:27:39 +0200 Subject: [PATCH 2/2] product_state: move access to Sales + Inventory Manager --- product_state/security/ir.model.access.csv | 3 ++- product_status/tests/test_product_status.py | 9 +++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/product_state/security/ir.model.access.csv b/product_state/security/ir.model.access.csv index 742e02316112..523e15ff1e82 100644 --- a/product_state/security/ir.model.access.csv +++ b/product_state/security/ir.model.access.csv @@ -1,3 +1,4 @@ "id","name","model_id:id","group_id:id","perm_read","perm_write","perm_create","perm_unlink" -"access_product_state_product_manager","product.state","model_product_state","base.group_partner_manager",1,1,1,1 +"access_product_state_sale_manager","product.state","model_product_state","sales_team.group_sale_manager",1,1,1,1 +"access_product_state_stock_manager","product.state","model_product_state","stock.group_stock_manager",1,1,1,1 "access_product_state_public","product.state.public","model_product_state",,1,0,0,0 diff --git a/product_status/tests/test_product_status.py b/product_status/tests/test_product_status.py index 13069c0478b9..ab1f4f7577db 100644 --- a/product_status/tests/test_product_status.py +++ b/product_status/tests/test_product_status.py @@ -120,7 +120,8 @@ def test_template_state_dates(self): def test_modified_default_data(self): st_env = self.env["product.state"] - demo_user = self.env.ref("base.user_demo").id + demo_user = self.env.ref("base.user_demo") + demo_user.groups_id = [(4, self.env.ref("sales_team.group_sale_manager").id)] default_state = st_env._get_module_data() vals = { "name": "State change", @@ -131,7 +132,7 @@ def test_modified_default_data(self): for ds_id in default_state: vals["code"] = ds_id.code with self.assertRaises(ValidationError) as cm: - st_env.browse(ds_id.id).with_user(demo_user).write(vals) + st_env.browse(ds_id.id).with_user(demo_user.id).write(vals) wn_expect = cm.exception.args[0] self.assertEqual( "Cannot delete/modified state installed by module, state name: %s" @@ -139,7 +140,7 @@ def test_modified_default_data(self): wn_expect, ) with self.assertRaises(ValidationError) as cm: - st_env.browse(ds_id.id).with_user(demo_user).unlink() + st_env.browse(ds_id.id).with_user(demo_user.id).unlink() wn_expect = cm.exception.args[0] self.assertEqual( "Cannot delete/modified state installed by module, state name: %s" @@ -148,7 +149,7 @@ def test_modified_default_data(self): ) # Allow update default value current_default_state = st_env.search([("default", "=", True)]) - current_default_state = current_default_state.with_user(demo_user) + current_default_state = current_default_state.with_user(demo_user.id) for vals in [ {"default": False}, {"active": False},