Skip to content

Commit 26c4929

Browse files
yajowilliam-andre
authored andcommitted
[FIX] account: allow users to see products after configuring taxes
The `account` module adds the `tax_string` field to product forms: https://github.com/odoo/odoo/blob/ceb8b785fba1055deeff8d9075ccc707f2317278/addons/account/views/product_view.xml#L76 That field calls `Model(account.tax).compute_all()`: https://github.com/odoo/odoo/blob/ceb8b785fba1055deeff8d9075ccc707f2317278/addons/account/models/product.py#L71 That method needs access to `account.account.tag` records: https://github.com/odoo/odoo/blob/ceb8b785fba1055deeff8d9075ccc707f2317278/addons/account/models/account_tax.py#L563 https://github.com/odoo/odoo/blob/ceb8b785fba1055deeff8d9075ccc707f2317278/addons/account/models/account_tax.py#L632 https://github.com/odoo/odoo/blob/ceb8b785fba1055deeff8d9075ccc707f2317278/addons/account/models/account_tax.py#L648 https://github.com/odoo/odoo/blob/ceb8b785fba1055deeff8d9075ccc707f2317278/addons/account/models/account_tax.py#L671 Internal users were able to read `account.tax` and `account.tax.repartition.line` records, but they couldn't read `account.account.tag` records. So, this lead to the absurd situation where a user with permissions to read products (like stock, PoS or event users) couldn't be able to see the product form anymore whenever that product happened to have a tax with a repartition line with a tag. This is a regression from Odoo 14, introduced in odoo#74138 and odoo#73602. I'm granting all internal users read permission over `account.account.tag`, just like the one they have for `account.tax` and `account.tax.repartition.line`. BTW that's the fix suggested by Odoo helpdesk. @moduon MT-4390 OPW-3636032 X-original-commit: 5fb4e82
1 parent f09833c commit 26c4929

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

addons/account/security/ir.model.access.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ access_account_tax_internal_user,account.tax internal user,model_account_tax,bas
7070
access_account_tax_readonly,account.tax,model_account_tax,account.group_account_readonly,1,0,0,0
7171
access_account_tax_invoice,account.tax,model_account_tax,account.group_account_invoice,1,0,0,0
7272
access_account_tax_manager,account.tax,model_account_tax,account.group_account_manager,1,1,1,1
73+
access_account_tag_internal_user,account.account.tag internal user,model_account_account_tag,base.group_user,1,0,0,0
7374
access_account_account_tax,account.account.tag,model_account_account_tag,account.group_account_user,1,1,1,1
7475
access_account_account_tax_readonly,account.account.tag,model_account_account_tag,account.group_account_readonly,1,0,0,0
7576
access_account_account_tax_user,account.account.tag,model_account_account_tag,account.group_account_invoice,1,0,0,0

addons/account/tests/test_product.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,37 @@
11
# -*- coding: utf-8 -*-
22

33
from odoo.addons.account.tests.common import AccountTestInvoicingCommon
4-
from odoo.tests import tagged
4+
from odoo.tests import Form, tagged
5+
from odoo.tests.common import new_test_user
56

67

78
@tagged('post_install', 'post_install_l10n', '-at_install')
89
class TestProduct(AccountTestInvoicingCommon):
910

11+
@classmethod
12+
def setUpClass(cls, chart_template_ref=None):
13+
super().setUpClass(chart_template_ref)
14+
cls.internal_user = new_test_user(
15+
cls.env,
16+
login="internal_user",
17+
groups="base.group_user",
18+
)
19+
20+
def test_internal_user_can_read_product_with_tax_and_tags(self):
21+
"""Internal users need read access to products, no matter their taxes."""
22+
# Add a tag to product_a's default tax
23+
tax_line_tag = self.env["account.account.tag"].create({
24+
"name": "Tax tag",
25+
"applicability": "taxes",
26+
})
27+
self.product_a.taxes_id.repartition_line_ids.tag_ids = tax_line_tag
28+
# Check that internal user can read product_a
29+
self.env.invalidate_all()
30+
with Form(self.product_a.with_user(self.internal_user)) as form_a:
31+
# The tax string itself is not very important here; we just check
32+
# it has a value and we can read it, so there were no access errors
33+
self.assertTrue(form_a.tax_string)
34+
1035
def test_multi_company_product_tax(self):
1136
""" Ensure default taxes are set for all companies on products with no company set. """
1237
product_without_company = self.env['product.template'].with_context(allowed_company_ids=self.env.company.ids).create({

0 commit comments

Comments
 (0)