From c95c776e4a879739dcf400806f06efc29956b15e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Alix?= Date: Mon, 31 Jan 2022 09:41:21 +0100 Subject: [PATCH] [FIX] Fix access right issues when using actions --- .../models/product.py | 6 ++++-- stock_available_unreserved/models/product_template.py | 9 +++++---- stock_request_analytic/models/analytic.py | 3 ++- stock_request_analytic/models/stock_request_order.py | 3 ++- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/product_quantity_update_force_inventory/models/product.py b/product_quantity_update_force_inventory/models/product.py index 69d69cd2c..87ebe9a4e 100644 --- a/product_quantity_update_force_inventory/models/product.py +++ b/product_quantity_update_force_inventory/models/product.py @@ -10,7 +10,8 @@ class ProductTemplate(models.Model): """Create an Inventory Adjustment instead of edit directly on quants""" self.ensure_one() view_form_id = self.env.ref("stock.view_inventory_form").id - action = self.env.ref("stock.action_inventory_form").sudo().read()[0] + xmlid = "stock.action_inventory_form" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) action.update( { "views": [(view_form_id, "form")], @@ -31,7 +32,8 @@ class ProductProduct(models.Model): """Create an Inventory Adjustment instead of edit directly on quants""" self.ensure_one() view_form_id = self.env.ref("stock.view_inventory_form").id - action = self.env.ref("stock.action_inventory_form").sudo().read()[0] + xmlid = "stock.action_inventory_form" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) action.update( { "views": [(view_form_id, "form")], diff --git a/stock_available_unreserved/models/product_template.py b/stock_available_unreserved/models/product_template.py index 073b32c8d..20d6f72de 100644 --- a/stock_available_unreserved/models/product_template.py +++ b/stock_available_unreserved/models/product_template.py @@ -32,13 +32,14 @@ class ProductTemplate(models.Model): quant_ids = quants.filtered( lambda x: x.product_id.qty_available_not_res > 0 ).ids - result = self.env.ref("stock.group_stock_multi_locations").read()[0] - result["domain"] = [("id", "in", quant_ids)] - result["context"] = { + xmlid = "stock_available_unreserved.product_open_quants_unreserved" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) + action["domain"] = [("id", "in", quant_ids)] + action["context"] = { "search_default_locationgroup": 1, "search_default_internal_loc": 1, } - return result + return action def _search_quantity_unreserved(self, operator, value): return [("product_variant_ids.qty_available_not_res", operator, value)] diff --git a/stock_request_analytic/models/analytic.py b/stock_request_analytic/models/analytic.py index b0203d0f9..3a3339e59 100644 --- a/stock_request_analytic/models/analytic.py +++ b/stock_request_analytic/models/analytic.py @@ -16,7 +16,8 @@ class AccountAnalyticAccount(models.Model): def action_view_stock_request(self): self.ensure_one() - action = self.env.ref("stock_request.action_stock_request_form").read()[0] + xmlid = "stock_request.action_stock_request_form" + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) requests = self.mapped("stock_request_ids") if len(requests) > 1: action["domain"] = [("id", "in", requests.ids)] diff --git a/stock_request_analytic/models/stock_request_order.py b/stock_request_analytic/models/stock_request_order.py index eadfbda4f..8d610518f 100644 --- a/stock_request_analytic/models/stock_request_order.py +++ b/stock_request_analytic/models/stock_request_order.py @@ -58,7 +58,8 @@ class StockRequestOrder(models.Model): raise ValidationError( _("Analytic type (analytic_type) not present in the context") ) - action = self.env.ref(MAP_ACTIONS[analytic_type]).read()[0] + xmlid = MAP_ACTIONS[analytic_type] + action = self.env["ir.actions.act_window"]._for_xml_id(xmlid) records = self.mapped(MAP_FIELDS[analytic_type]) if len(records) > 1: action["domain"] = [("id", "in", records.ids)]