[FIX] stock: move group inside the view
The goal being to get rid of the `groups_id` feature for backend views This one is a tricky case The `create` button should not be visible in the tree and form views of stock locations when the multi locations feature is not enabled. If you don't have the group, you do not see the menu bringing you to the locations list, but though it's still possible to reach the location form view through a many2one link on a location field missing the `groups="stock.group_stock_multi_locations"` e.g. on the stock move form. If you managed to reach a location form whatever the way, if you do not have the multi locations enabled, you shouldn't see the create button. As we would like to remove the `groups_id` feature of the `ir.ui.view`, we must find an alternative. This is the only case using `groups_id` to remove the create/edit button, so it's not like it's such a common way to achieve this goal. The right way to achieve this should be an ACL, preventing you to create a location at all (even through xmlrpc) if you do not have the multi-location feature enabled. Though, currently, there is an ACL giving the right to inventory managers to create locations, and this is unfortunately impossible in the ACLs model to make a combined group rule, like you need both the groups multi-locations and inventory manager to be allowed to create locations. Hence, as alternative, we enable/disable the view removing the create button from the list and form views when the multi-locations is enabled/disabled in the settings. Part-of: odoo/odoo#98551
This commit is contained in:
@@ -103,11 +103,27 @@ class ResConfigSettings(models.TransientModel):
|
||||
if self.group_stock_multi_locations and not previous_group.get('group_stock_multi_locations'):
|
||||
# override active_test that is false in set_values
|
||||
warehouse_obj.with_context(active_test=True).search([]).int_type_id.active = True
|
||||
# Disable the views removing the create button from the location list and form.
|
||||
# Be resilient if the views have been deleted manually.
|
||||
for view in (
|
||||
self.env.ref('stock.stock_location_view_tree2_editable', raise_if_not_found=False),
|
||||
self.env.ref('stock.stock_location_view_form_editable', raise_if_not_found=False),
|
||||
):
|
||||
if view:
|
||||
view.active = False
|
||||
elif not self.group_stock_multi_locations and previous_group.get('group_stock_multi_locations'):
|
||||
warehouse_obj.search([
|
||||
('reception_steps', '=', 'one_step'),
|
||||
('delivery_steps', '=', 'ship_only')
|
||||
]).int_type_id.active = False
|
||||
# Enable the views removing the create button from the location list and form.
|
||||
# Be resilient if the views have been deleted manually.
|
||||
for view in (
|
||||
self.env.ref('stock.stock_location_view_tree2_editable', raise_if_not_found=False),
|
||||
self.env.ref('stock.stock_location_view_form_editable', raise_if_not_found=False),
|
||||
):
|
||||
if view:
|
||||
view.active = True
|
||||
|
||||
if not was_operations_showed and self.env['stock.picking.type'].with_user(SUPERUSER_ID)._default_show_operations():
|
||||
self.env['stock.picking.type'].with_context(active_test=False).sudo().search([
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<field name="name">stock.location.form</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Stock Location" create="false">
|
||||
<form string="Stock Location">
|
||||
<field name="company_id" invisible="1"/>
|
||||
<sheet>
|
||||
<div class="oe_button_box" name="button_box">
|
||||
@@ -61,10 +61,9 @@
|
||||
<field name="name">stock.location.form.editable</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_form"/>
|
||||
<field name="groups_id" eval="[(4, ref('stock.group_stock_multi_locations'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//form" position="attributes">
|
||||
<attribute name="create">true</attribute>
|
||||
<attribute name="create">false</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
@@ -91,7 +90,7 @@
|
||||
<field name="model">stock.location</field>
|
||||
<field name="priority" eval="2"/>
|
||||
<field name="arch" type="xml">
|
||||
<tree string="Stock Location" decoration-info="usage=='view'" decoration-danger="usage=='internal'" create="false" multi_edit="1">
|
||||
<tree string="Stock Location" decoration-info="usage=='view'" decoration-danger="usage=='internal'" multi_edit="1">
|
||||
<field name="active" invisible="1"/>
|
||||
<field name="complete_name" string="Location"/>
|
||||
<field name="usage"/>
|
||||
@@ -105,10 +104,9 @@
|
||||
<field name="name">stock.location.tree2.editable</field>
|
||||
<field name="model">stock.location</field>
|
||||
<field name="inherit_id" ref="stock.view_location_tree2"/>
|
||||
<field name="groups_id" eval="[(4, ref('stock.group_stock_multi_locations'))]"/>
|
||||
<field name="arch" type="xml">
|
||||
<xpath expr="//tree" position="attributes">
|
||||
<attribute name="create">true</attribute>
|
||||
<attribute name="create">false</attribute>
|
||||
</xpath>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
Reference in New Issue
Block a user