diff --git a/addons/mrp/models/stock_rule.py b/addons/mrp/models/stock_rule.py index 47a9d8f4189..bb9c1deb738 100644 --- a/addons/mrp/models/stock_rule.py +++ b/addons/mrp/models/stock_rule.py @@ -4,7 +4,7 @@ from collections import defaultdict from dateutil.relativedelta import relativedelta -from odoo import api, fields, models, _ +from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.osv import expression from odoo.addons.stock.models.stock_rule import ProcurementException @@ -51,7 +51,7 @@ class StockRule(models.Model): for company_id, productions_values in productions_values_by_company.items(): # create the MO as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example) - productions = self.env['mrp.production'].sudo().with_company(company_id).create(productions_values) + productions = self.env['mrp.production'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(productions_values) self.env['stock.move'].sudo().create(productions._get_moves_raw_values()) productions.filtered(lambda p: p.move_raw_ids).action_confirm() diff --git a/addons/purchase_stock/models/purchase.py b/addons/purchase_stock/models/purchase.py index 18222c3e8b5..c5a74770b80 100644 --- a/addons/purchase_stock/models/purchase.py +++ b/addons/purchase_stock/models/purchase.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. -from odoo import api, fields, models, _ +from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.tools.float_utils import float_compare from dateutil import relativedelta from odoo.exceptions import UserError @@ -214,7 +214,7 @@ class PurchaseOrder(models.Model): pickings = order.picking_ids.filtered(lambda x: x.state not in ('done', 'cancel')) if not pickings: res = order._prepare_picking() - picking = StockPicking.create(res) + picking = StockPicking.with_user(SUPERUSER_ID).create(res) else: picking = pickings[0] moves = order.order_line._create_stock_moves(picking) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index d107a4b4a0d..fa7c1eaaa63 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -6,7 +6,7 @@ from datetime import datetime from dateutil.relativedelta import relativedelta from itertools import groupby -from odoo import api, fields, models, _ +from odoo import api, fields, models, SUPERUSER_ID, _ from odoo.addons.stock.models.stock_rule import ProcurementException @@ -90,7 +90,7 @@ class StockRule(models.Model): vals = rules[0]._prepare_purchase_order(company_id, origins, [p.values for p in procurements]) # The company_id is the same for all procurements since # _make_po_get_domain add the company in the domain. - po = self.env['purchase.order'].with_company(company_id).sudo().create(vals) + po = self.env['purchase.order'].with_user(SUPERUSER_ID).with_company(company_id).sudo().create(vals) else: # If a purchase order is found, adapt its `origin` field. if po.origin: diff --git a/addons/stock/models/stock_rule.py b/addons/stock/models/stock_rule.py index 564c32e3337..7570c0cbfb0 100644 --- a/addons/stock/models/stock_rule.py +++ b/addons/stock/models/stock_rule.py @@ -258,7 +258,7 @@ class StockRule(models.Model): for company_id, moves_values in moves_values_by_company.items(): # create the move as SUPERUSER because the current user may not have the rights to do it (mto product launched by a sale for example) - moves = self.env['stock.move'].sudo().with_company(company_id).create(moves_values) + moves = self.env['stock.move'].with_user(SUPERUSER_ID).sudo().with_company(company_id).create(moves_values) # Since action_confirm launch following procurement_group we should activate it. moves._action_confirm() return True