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
34from odoo .tests import tagged , users
45
56from 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