[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) <arm@odoo.com>
Signed-off-by: Pawel Fertyk (pafe) <pafe@odoo.com>
This commit is contained in:
Paweł Fertyk
2024-04-18 07:28:29 +00:00
parent b258e5d294
commit 0217b88e48
2 changed files with 10 additions and 1 deletions
+1 -1
View File
@@ -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,
@@ -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):