From 0217b88e481dc1d0d244b620ba527dec177edde1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pawe=C5=82=20Fertyk?= Date: Tue, 16 Apr 2024 17:54:09 +0200 Subject: [PATCH] [FIX] mrp_account: fix BoM creation for non-accounting users Currently, recalculating `analytic_distribution` requires access to `account.analytic.distribution.model`. This breaks BoM creation for non-accounting users (e.g. MRP managers). This commit fixes the issue by using `sudo()._get_distribution`. closes odoo/odoo#162184 X-original-commit: 3872e9365e4d8cc100a6022e934292f6f6802162 Signed-off-by: Arnold Moyaux (arm) Signed-off-by: Pawel Fertyk (pafe) --- addons/mrp_account/models/mrp_bom.py | 2 +- addons/mrp_account/tests/test_mrp_account.py | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/addons/mrp_account/models/mrp_bom.py b/addons/mrp_account/models/mrp_bom.py index ca2a1029819..1e92a997313 100644 --- a/addons/mrp_account/models/mrp_bom.py +++ b/addons/mrp_account/models/mrp_bom.py @@ -35,7 +35,7 @@ class MrpBom(models.Model): def _onchange_analytic_distribution(self): for record in self: if record.product_id: - record.analytic_distribution = record.env['account.analytic.distribution.model']._get_distribution({ + record.analytic_distribution = record.env['account.analytic.distribution.model'].sudo()._get_distribution({ "product_id": record.product_id.id, "product_categ_id": record.product_id.categ_id.id, "company_id": record.company_id.id, diff --git a/addons/mrp_account/tests/test_mrp_account.py b/addons/mrp_account/tests/test_mrp_account.py index 12760cc30f9..0277e140465 100644 --- a/addons/mrp_account/tests/test_mrp_account.py +++ b/addons/mrp_account/tests/test_mrp_account.py @@ -4,6 +4,7 @@ from odoo.addons.mrp.tests.common import TestMrpCommon from odoo.addons.stock_account.tests.test_account_move import TestAccountMoveStockCommon from odoo.tests import Form, tagged +from odoo.tests.common import new_test_user class TestMrpAccount(TestMrpCommon): @@ -188,6 +189,14 @@ class TestMrpAccount(TestMrpCommon): # 1 table head at 20 + 4 table leg at 15 + 4 bolt at 10 + 10 screw at 10 + 1*20 (extra cost) self.assertEqual(move_value, 141, 'Thing should have the correct price') + def test_stock_user_without_account_permissions_can_create_bom(self): + mrp_manager = new_test_user( + self.env, 'temp_mrp_manager', 'mrp.group_mrp_manager', + ) + + bom_form = Form(self.env['mrp.bom'].with_user(mrp_manager)) + bom_form.product_id = self.dining_table + @tagged("post_install", "-at_install") class TestMrpAccountMove(TestAccountMoveStockCommon):