From 2c6671e75e403c6a80c903ef6b6c5b620f44572a Mon Sep 17 00:00:00 2001 From: "Mahdi Cheikh Rouhou (macr)" Date: Tue, 19 Sep 2023 11:44:54 +0200 Subject: [PATCH] [FIX] sale_stock : Create backorder with inventory admin Issue: ====== We have a delivery order created by a sale order by another user. A user with administrator access to inventory and sale : own documents only ,can't deliver products of that sale order without backorder , it shows access error. Steps to reproduce the error: ============================= - Create another user with admin access for inventory and own documents for sale. - Create a sale order with the current user. - Change now for the inventory admin and deliver some of the products and click on no-backorder. - Access error will show. Origin of the issue: ==================== The admin user should be able to deliver the products but when creating no backorder he needs to write on the sale_order. Solution: ========= Added `sudo` to the function that logs in the sale_order. opw-3380566 closes odoo/odoo#138176 X-original-commit: de2d889b053827e39b11a648797ad2f30e646ce6 Signed-off-by: William Henrotin (whe) Signed-off-by: Mahdi Cheikh Rouhou (macr) --- addons/sale_stock/models/stock.py | 2 +- addons/sale_stock/tests/test_sale_stock.py | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/addons/sale_stock/models/stock.py b/addons/sale_stock/models/stock.py index 045b60d8085..d6bc92860bd 100644 --- a/addons/sale_stock/models/stock.py +++ b/addons/sale_stock/models/stock.py @@ -150,7 +150,7 @@ class StockPicking(models.Model): } return self.env['ir.qweb']._render('sale_stock.exception_on_picking', values) - documents = self._log_activity_get_documents(moves, 'sale_line_id', 'DOWN', _keys_in_groupby) + documents = self.sudo()._log_activity_get_documents(moves, 'sale_line_id', 'DOWN', _keys_in_groupby) self._log_activity(_render_note_exception_quantity, documents) return super(StockPicking, self)._log_less_quantities_than_expected(moves) diff --git a/addons/sale_stock/tests/test_sale_stock.py b/addons/sale_stock/tests/test_sale_stock.py index 16d8634159d..9cd9db442ed 100644 --- a/addons/sale_stock/tests/test_sale_stock.py +++ b/addons/sale_stock/tests/test_sale_stock.py @@ -1518,3 +1518,23 @@ class TestSaleStock(TestSaleCommon, ValuationReconciliationTestCommon): backorder_wizard.process() self.assertRecordValues(out_picking.move_line_ids, [{'result_package_id': False}, {'result_package_id': package_2.id}]) + + def test_inventory_admin_no_backorder_not_own_sale_order(self): + sale_order = self._get_new_sale_order() + sale_order.action_confirm() + pick = sale_order.picking_ids + inventory_admin_user = self.env['res.users'].create({ + 'name': "documents test basic user", + 'login': "dtbu", + 'email': "dtbu@yourcompany.com", + 'groups_id': [(6, 0, [ + self.ref('base.group_user'), + self.ref('stock.group_stock_manager'), + self.ref('sales_team.group_sale_salesman')])] + }) + pick.with_user(inventory_admin_user).move_ids.write( + {'quantity_done': 1}) + res_dict = pick.button_validate() + wizard = Form(self.env[(res_dict.get('res_model'))].with_user(inventory_admin_user).with_context( + res_dict['context'])).save() + wizard.with_user(inventory_admin_user).process_cancel_backorder()