Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[17.0][FW] product_state: multiple ports from 14.0 #1755

Merged
merged 2 commits into from
Nov 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions product_state/models/product_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
3 changes: 2 additions & 1 deletion product_state/security/ir.model.access.csv
Original file line number Diff line number Diff line change
@@ -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
15 changes: 14 additions & 1 deletion product_state/tests/test_product_state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand All @@ -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,
)
9 changes: 5 additions & 4 deletions product_status/tests/test_product_status.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -131,15 +132,15 @@ 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"
% (ds_id.name),
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"
Expand All @@ -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},
Expand Down
Loading