Skip to content

Commit 6e18897

Browse files
committed
[MIG] pos_product_cost_security: Migration to 17.0
1 parent c14b06f commit 6e18897

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

pos_product_cost_security/__manifest__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
{
44
"name": "PoS Product Cost Security",
55
"summary": "Compatibility between Point of Sale and Product Cost Security",
6-
"version": "16.0.1.0.0",
6+
"version": "17.0.1.0.0",
77
"category": "Product",
88
"website": "https://github.com/OCA/product-attribute",
99
"author": "Tecnativa, Odoo Community Association (OCA)",

pos_product_cost_security/models/product_product.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,6 @@ def read(self, fields=None, load="_classic_read"):
2424
fields=["standard_price"], load=load
2525
)
2626
# No we zip both results altogether to feed the PoS data load
27-
for res_item, std_price_res_item in zip(result, std_price_result):
27+
for res_item, std_price_res_item in zip(result, std_price_result, strict=True):
2828
res_item["standard_price"] = std_price_res_item["standard_price"]
2929
return result

pos_product_cost_security/tests/test_pos_product_cost.py

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Copyright 2021 Tecnativa - David Vidal
22
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html).
3+
from odoo.exceptions import AccessError
34
from odoo.tests import tagged, users
45

56
from odoo.addons.point_of_sale.tests.common import TestPointOfSaleCommon, TestPoSCommon
@@ -11,7 +12,47 @@ class TestPosProductCostSecurity(TestPointOfSaleCommon, TestPoSCommon):
1112
def setUpClass(cls):
1213
super().setUpClass()
1314
cls.config = cls.basic_config
15+
cls.product = cls.env.ref("product.product_product_3")
16+
17+
def _read_product(self, context_values, fields=None):
18+
"""Read product with given context and fields"""
19+
if fields is None:
20+
fields = ["name", "standard_price"]
21+
return (
22+
self.env["product.product"]
23+
.with_context(**context_values)
24+
.browse(self.product.id)
25+
.read(fields)
26+
)
27+
28+
@users("demo")
29+
def test_pos_session_open_and_override_loader_params(self):
30+
session = self.open_new_session()
31+
params = session._loader_params_product_product()
32+
product_data = self._read_product(params["context"])
33+
self.assertIn("standard_price", product_data[0])
1434

1535
@users("demo")
16-
def test_pos_session_open(self):
17-
self.session = self.open_new_session()
36+
def test_read_without_override_context(self):
37+
"""User without override should not be able to read standard_price"""
38+
with self.assertRaises(
39+
AccessError, msg="Should raise AccessError without override"
40+
):
41+
self._read_product({"pos_override_cost_security": False})
42+
43+
@users("demo")
44+
def test_read_with_override_context(self):
45+
"""User with override should see standard_price"""
46+
product_data = self._read_product({"pos_override_cost_security": True})
47+
48+
self.assertIn("name", product_data[0])
49+
self.assertIn(
50+
"standard_price",
51+
product_data[0],
52+
"Standard price should be visible with override",
53+
)
54+
self.assertEqual(
55+
product_data[0]["standard_price"],
56+
self.env["product.product"].browse(self.product.id).sudo().standard_price,
57+
"Standard price should match the product cost",
58+
)

0 commit comments

Comments
 (0)