|
2 | 2 | # Copyright 2021 ACSONE SA/NV (<http://acsone.eu>) |
3 | 3 | # License AGPL-3 - See http://www.gnu.org/licenses/agpl-3.0.html |
4 | 4 |
|
| 5 | +from lxml import etree |
| 6 | + |
5 | 7 | from odoo.exceptions import AccessError |
6 | 8 | from odoo.tests import Form, common |
7 | 9 |
|
@@ -136,3 +138,61 @@ def test_search_product(self): |
136 | 138 | ] |
137 | 139 | ) |
138 | 140 | self.assertEqual(searched_products, expected_products) |
| 141 | + |
| 142 | + def test_product_variant_tree_view_patched(self): |
| 143 | + """ |
| 144 | + Ensures that the standalone product.product list view is properly patched |
| 145 | + to prevent AccessErrors for restricted users. |
| 146 | + """ |
| 147 | + tree_view = self.env.ref("product.product_product_tree_view") |
| 148 | + tree_arch = etree.fromstring(tree_view.get_combined_arch()) |
| 149 | + |
| 150 | + company_id_nodes = tree_arch.xpath("//field[@name='company_id']") |
| 151 | + self.assertTrue( |
| 152 | + company_id_nodes, |
| 153 | + "TEST FAILURE: company_id field is completely missing from the base tree view.", |
| 154 | + ) |
| 155 | + |
| 156 | + column_invisible = company_id_nodes[0].get("column_invisible") |
| 157 | + self.assertIsNotNone( |
| 158 | + column_invisible, |
| 159 | + "TEST FAILURE: The XML fix is NOT applied! 'company_id' is visible in the list view.", |
| 160 | + ) |
| 161 | + self.assertIn( |
| 162 | + str(column_invisible), |
| 163 | + ["True", "1", "true"], |
| 164 | + f"TEST FAILURE: company_id has column_invisible='{column_invisible}'. Expected 'True'.", |
| 165 | + ) |
| 166 | + |
| 167 | + company_ids_nodes = tree_arch.xpath("//field[@name='company_ids']") |
| 168 | + self.assertTrue( |
| 169 | + company_ids_nodes, |
| 170 | + "TEST FAILURE: The XML fix is NOT applied! 'company_ids' is missing from the list view.", |
| 171 | + ) |
| 172 | + |
| 173 | + groups = company_ids_nodes[0].get("groups") |
| 174 | + self.assertEqual( |
| 175 | + str(groups), |
| 176 | + "base.group_multi_company", |
| 177 | + f"TEST FAILURE: company_ids groups attribute is '{groups}', expected 'base.group_multi_company'.", |
| 178 | + ) |
| 179 | + |
| 180 | + def test_product_variant_payload_simulation(self): |
| 181 | + """ |
| 182 | + Simulates the web client payload generation to ensure restricted |
| 183 | + fields are properly hidden and not requested by the frontend. |
| 184 | + """ |
| 185 | + tree_view = self.env.ref("product.product_product_tree_view") |
| 186 | + tree_arch = etree.fromstring(tree_view.sudo().get_combined_arch()) |
| 187 | + |
| 188 | + specification = {"name": {}} |
| 189 | + for node in tree_arch.xpath("//field[@name='company_id']"): |
| 190 | + invisible = node.get("column_invisible") in ["True", "1", "true"] |
| 191 | + if not invisible: |
| 192 | + specification["company_id"] = {"fields": {"display_name": {}}} |
| 193 | + |
| 194 | + self.assertNotIn( |
| 195 | + "company_id", |
| 196 | + specification, |
| 197 | + "TEST FAILURE: company_id is exposed in the view arch and would be requested by the web client.", |
| 198 | + ) |
0 commit comments