[IMP] mrp,(purchase_)stock: set autogenerated doc creators to Odoobot

Make it so documents auto-generated by other actions have Odoobot set as
the creator rather than the user triggering the action. This includes
the following documents:

1. Delivery (stock.picking) - generated by Sales orders (including MTO)
2. Purchase orders - generated by dropshipping, manual replenishment,
	             and run scheduler
3. Manufacturing orders - generated by made to order (MTO)

This is addresses specification 2 of overall usability improvement task.

Task: 2041853
This commit is contained in:
Tiffany Chang (tic)
2020-03-05 13:04:11 +00:00
parent 2552fcc94e
commit 69c4b628c3
4 changed files with 7 additions and 7 deletions
+2 -2
View File
@@ -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()
+2 -2
View File
@@ -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)
+2 -2
View File
@@ -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:
+1 -1
View File
@@ -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