From 3fecf305b7d99329d3393329983ed4058009b2ec Mon Sep 17 00:00:00 2001 From: Andrew Gavgavian Date: Mon, 25 Sep 2023 13:44:41 -0700 Subject: [PATCH] [FIX] mrp: fix access rights on change.production.qty call Steps to reproduce: As Admin: 1. Create a Storable product with a Route of Manufacture 2. Create a re-ordering rule for this product. 3. As a user with no MRP access rights, create a sale order with this product and confirm the sale order. This creates a new `mrp.production` record with `sudo()` on line \#85: https://github.com/odoo/odoo/blob/fae59cee91969692c2375b3bd37e914ec0fb606e/addons/mrp/models/stock_rule.py#L85 4. Duplicate sale order and try to confirm again. This produces an access right error because the first loop finds the existing `mrp.production` record and tries to create a `change.production.qty` record. However, the user doesn't have access rights so they get an error. Solution: Add `sudo` to the create call. opw-3508819 closes odoo/odoo#136640 X-original-commit: c5758e122db5396e23a57826a1b12ed7d9765f55 Signed-off-by: Tiffany Chang (tic) Signed-off-by: Andrew Gavgavian (andg) --- addons/mrp/models/stock_rule.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index 1435e27f22a..a0a4221e62f 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -74,7 +74,7 @@ class StockRule(models.Model): if not mo: new_productions_values_by_company[procurement.company_id.id].append(rule._prepare_mo_vals(*procurement, bom)) else: - self.env['change.production.qty'].with_context(skip_activity=True).create({ + self.env['change.production.qty'].sudo().with_context(skip_activity=True).create({ 'mo_id': mo.id, 'product_qty': mo.product_id.uom_id._compute_quantity((mo.product_uom_qty + procurement.product_qty), mo.product_uom_id) }).change_prod_qty()