Skip to content

Commit e35913e

Browse files
committed
[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#162243 X-original-commit: 3872e93 Signed-off-by: Arnold Moyaux (arm) <[email protected]> Signed-off-by: Pawel Fertyk (pafe) <[email protected]>
1 parent 3476356 commit e35913e

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

addons/mrp_account/models/mrp_bom.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def _compute_analytic_account_ids(self):
3535
def _onchange_analytic_distribution(self):
3636
for record in self:
3737
if record.product_id:
38-
record.analytic_distribution = record.env['account.analytic.distribution.model']._get_distribution({
38+
record.analytic_distribution = record.env['account.analytic.distribution.model'].sudo()._get_distribution({
3939
"product_id": record.product_id.id,
4040
"product_categ_id": record.product_id.categ_id.id,
4141
"company_id": record.company_id.id,

addons/mrp_account/tests/test_mrp_account.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from odoo.addons.mrp.tests.common import TestMrpCommon
55
from odoo.addons.stock_account.tests.test_account_move import TestAccountMoveStockCommon
66
from odoo.tests import Form, tagged
7+
from odoo.tests.common import new_test_user
78

89

910
class TestMrpAccount(TestMrpCommon):
@@ -188,6 +189,14 @@ def test_00_production_order_with_accounting(self):
188189
# 1 table head at 20 + 4 table leg at 15 + 4 bolt at 10 + 10 screw at 10 + 1*20 (extra cost)
189190
self.assertEqual(move_value, 141, 'Thing should have the correct price')
190191

192+
def test_stock_user_without_account_permissions_can_create_bom(self):
193+
mrp_manager = new_test_user(
194+
self.env, 'temp_mrp_manager', 'mrp.group_mrp_manager',
195+
)
196+
197+
bom_form = Form(self.env['mrp.bom'].with_user(mrp_manager))
198+
bom_form.product_id = self.dining_table
199+
191200

192201
@tagged("post_install", "-at_install")
193202
class TestMrpAccountMove(TestAccountMoveStockCommon):

0 commit comments

Comments
 (0)