Skip to content

Commit fdbc5eb

Browse files
yajocsnauwaert
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. Funny enough, while exercising the test, I also noticed that a similar situation happens with MRP. When installed, other users that would normally be able to browse products, would no longer have access. The fix is incouded too; otherwise the test wouldn't pass. @moduon MT-4390 OPW-3636032 closes odoo#151639 X-original-commit: 9c7028b Signed-off-by: Cedric Snauwaert <csn@odoo.com>
1 parent b669d5a commit fdbc5eb

File tree

4 files changed

+41
-2
lines changed

4 files changed

+41
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ access_account_tax_internal_user,account.tax internal user,model_account_tax,bas
6868
access_account_tax_readonly,account.tax,model_account_tax,account.group_account_readonly,1,0,0,0
6969
access_account_tax_invoice,account.tax,model_account_tax,account.group_account_invoice,1,0,0,0
7070
access_account_tax_manager,account.tax,model_account_tax,account.group_account_manager,1,1,1,1
71+
access_account_tag_internal_user,account.account.tag internal user,model_account_account_tag,base.group_user,1,0,0,0
7172
access_account_account_tax,account.account.tag,model_account_account_tag,account.group_account_user,1,1,1,1
7273
access_account_account_tax_readonly,account.account.tag,model_account_account_tag,account.group_account_readonly,1,0,0,0
7374
access_account_account_tax_user,account.account.tag,model_account_account_tag,account.group_account_invoice,1,0,0,0

addons/account/tests/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
from . import test_account_move_send
3030
from . import test_account_all_l10n
3131
from . import test_portal_attachment
32+
from . import test_product
3233
from . import test_tax_report
3334
from . import test_transfer_wizard
3435
from . import test_account_incoming_supplier_invoice
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
from .common import AccountTestInvoicingCommon
2+
from odoo.tests.common import Form, tagged, new_test_user
3+
from odoo import Command
4+
5+
6+
@tagged("post_install", "-at_install")
7+
class AccountProductCase(AccountTestInvoicingCommon):
8+
@classmethod
9+
def setUpClass(cls, chart_template_ref=None):
10+
super().setUpClass(chart_template_ref)
11+
cls.internal_user = new_test_user(
12+
cls.env, login="internal_user", groups="base.group_user"
13+
)
14+
15+
def test_internal_user_can_read_product_with_tax_and_tags(self):
16+
"""Internal users need read access to products, no matter their taxes."""
17+
# Add a tag to product_a's default tax
18+
self.company_data["company"].country_id = self.env.ref("base.us")
19+
tax_line_tag = self.env["account.account.tag"].create(
20+
{
21+
"name": "Tax tag",
22+
"applicability": "taxes",
23+
"country_id": self.company_data["company"].country_id.id,
24+
}
25+
)
26+
repartition_lines = (
27+
self.product_a.taxes_id.invoice_repartition_line_ids
28+
| self.product_a.taxes_id.refund_repartition_line_ids
29+
).filtered_domain([("repartition_type", "=", "tax")])
30+
repartition_lines.write({"tag_ids": [Command.link(tax_line_tag.id)]})
31+
# Check that internal user can read product_a
32+
with Form(
33+
self.product_a.with_user(self.internal_user).with_context(lang="en_US")
34+
) as form_a:
35+
# The tax string itself is not very important here; we just check
36+
# it has a value and we can read it, so there were no access errors
37+
self.assertTrue(form_a.tax_string)

addons/mrp/models/product.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class ProductTemplate(models.Model):
3030
compute='_compute_used_in_bom_count', compute_sudo=False)
3131
mrp_product_qty = fields.Float('Manufactured', digits='Product Unit of Measure',
3232
compute='_compute_mrp_product_qty', compute_sudo=False)
33-
is_kits = fields.Boolean(compute='_compute_is_kits', compute_sudo=False)
33+
is_kits = fields.Boolean(compute='_compute_is_kits', compute_sudo=True)
3434

3535
def _compute_bom_count(self):
3636
for product in self:
@@ -109,7 +109,7 @@ class ProductProduct(models.Model):
109109
compute='_compute_used_in_bom_count', compute_sudo=False)
110110
mrp_product_qty = fields.Float('Manufactured', digits='Product Unit of Measure',
111111
compute='_compute_mrp_product_qty', compute_sudo=False)
112-
is_kits = fields.Boolean(compute="_compute_is_kits", compute_sudo=False)
112+
is_kits = fields.Boolean(compute="_compute_is_kits", compute_sudo=True)
113113

114114
def _compute_bom_count(self):
115115
for product in self:

0 commit comments

Comments
 (0)