[FIX] stock: Add groups to product tree view to prevent ACLs error with quantity fields

Example use case:
- Create a product A.
- Update the available quantity of the product.
- Create a basic user without Inventory permissions.
- Go to the product list (product.product or product.template) and get
  an error when access to stock.move records to set the qty_available
  field (for example).

TT45220

closes odoo/odoo#142472

X-original-commit: e41fbda20582683361a5124db418f152bf80a3ed
Signed-off-by: William Henrotin (whe) <whe@odoo.com>
This commit is contained in:
Víctor Martínez
2023-12-15 14:36:42 +00:00
committed by William Henrotin
parent d0c2c225da
commit 1a04071e35
2 changed files with 25 additions and 8 deletions
+16 -1
View File
@@ -3,7 +3,7 @@
from odoo import Command
from odoo.exceptions import UserError
from odoo.tests import Form
from odoo.tests import Form, new_test_user
from odoo.tests.common import TransactionCase
@@ -2028,6 +2028,21 @@ class StockMove(TransactionCase):
move_partial._action_assign()
self.assertEqual(move_partial.state, 'assigned')
def test_product_tree_views(self):
"""Test to make sure that there are no ACLs errors in users with basic permissions."""
self.env["stock.quant"]._update_available_quantity(self.product, self.stock_location, 3.0)
user = new_test_user(self.env, login="test-basic-user")
product_view = Form(
self.env["product.product"].with_user(user).browse(self.product.id),
view="product.product_product_tree_view",
)
self.assertEqual(product_view.name, self.product.name)
template_view = Form(
self.env["product.template"].with_user(user).browse(self.product.product_tmpl_id.id),
view="product.product_template_tree_view",
)
self.assertEqual(template_view.name, self.product.product_tmpl_id.name)
def test_availability_9(self):
""" Test the assignment mechanism when the product quantity is increase
on a receipt move.
+9 -7
View File
@@ -42,8 +42,8 @@
<field name="inherit_id" ref="product.product_product_tree_view"/>
<field name="arch" type="xml">
<field name="type" position="after">
<field name="qty_available" invisible="type != 'product'" string="On Hand" optional="show" decoration-danger="virtual_available &lt; 0" decoration-warning="virtual_available == 0" decoration-bf="1"/>
<field name="virtual_available" invisible="type != 'product'" string="Forecasted" optional="show" decoration-danger="virtual_available &lt; 0" decoration-warning="virtual_available == 0"/>
<field name="qty_available" invisible="type != 'product'" string="On Hand" optional="show" decoration-danger="virtual_available &lt; 0" decoration-warning="virtual_available == 0" decoration-bf="1" groups="stock.group_stock_user"/>
<field name="virtual_available" invisible="type != 'product'" string="Forecasted" optional="show" decoration-danger="virtual_available &lt; 0" decoration-warning="virtual_available == 0" groups="stock.group_stock_user"/>
</field>
</field>
</record>
@@ -54,12 +54,12 @@
<field name="inherit_id" ref="product.product_template_tree_view"/>
<field name="arch" type="xml">
<field name="uom_id" position="before">
<field name="show_on_hand_qty_status_button" column_invisible="True"/>
<field name="qty_available" invisible="not show_on_hand_qty_status_button" string="On Hand" optional="show" decoration-danger="qty_available &lt; 0"/>
<field name="virtual_available" invisible="not show_on_hand_qty_status_button" string="Forecasted" optional="show" decoration-danger="virtual_available &lt; 0" decoration-bf="1"/>
<field name="show_on_hand_qty_status_button" column_invisible="True" groups="stock.group_stock_user"/>
<field name="qty_available" invisible="not show_on_hand_qty_status_button" string="On Hand" optional="show" decoration-danger="qty_available &lt; 0" groups="stock.group_stock_user"/>
<field name="virtual_available" invisible="not show_on_hand_qty_status_button" string="Forecasted" optional="show" decoration-danger="virtual_available &lt; 0" decoration-bf="1" groups="stock.group_stock_user"/>
</field>
<field name="default_code" position="after">
<field name="responsible_id" widget="many2one_avatar_user" optional="hide"/>
<field name="responsible_id" widget="many2one_avatar_user" optional="hide" groups="stock.group_stock_user"/>
</field>
</field>
</record>
@@ -158,10 +158,12 @@
<field name="arch" type="xml">
<xpath expr="//kanban" position="inside">
<field name="type"/>
<field name="show_on_hand_qty_status_button"/>
<field name="show_on_hand_qty_status_button" groups="stock.group_stock_user"/>
</xpath>
<xpath expr="//div[@name='product_lst_price']" position="after">
<t groups="stock.group_stock_user">
<div t-if="record.show_on_hand_qty_status_button.raw_value">On hand: <field name="qty_available"/> <field name="uom_id"/></div>
</t>
</xpath>
</field>
</record>