From 25ff38eb429d282ee6f7ed12458745052014012a Mon Sep 17 00:00:00 2001 From: Nicolas Martinelli Date: Mon, 25 May 2020 09:29:25 +0000 Subject: [PATCH] [FIX] purchase_stock: PO follower - Create a dropship product - Set a supplier - As a portal user, buy the product on the eCommerce The portal user is added as a follower of the PO created. This is a side-effect of `sudo` keeping the current user and the following adding the current usr as a follower: https://github.com/odoo/odoo/blob/96b0dcf9e51f5a924e2cbf618c2ee5462cc1f03f/addons/mail/models/mail_thread.py#L262 When the PO is created from a procurement, the current user might not have access to the Purchase app. For example, the user might only have access to Sales. Therefore, there is no need of adding him as follower. opw-2249357 closes odoo/odoo#51895 X-original-commit: a561ad050e0c8cfe1dafb699c4c84c7c39bf777d Signed-off-by: Nicolas Martinelli (nim) --- addons/purchase_stock/models/stock_rule.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/addons/purchase_stock/models/stock_rule.py b/addons/purchase_stock/models/stock_rule.py index 829d67b4ad8..b10cd241544 100644 --- a/addons/purchase_stock/models/stock_rule.py +++ b/addons/purchase_stock/models/stock_rule.py @@ -96,7 +96,9 @@ 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_user(SUPERUSER_ID).with_company(company_id).sudo().create(vals) + # We use SUPERUSER_ID since we don't want the current user to be follower of the PO. + # Indeed, the current user may be a user without access to Purchase, or even be a portal user. + po = self.env['purchase.order'].with_company(company_id).with_user(SUPERUSER_ID).create(vals) else: # If a purchase order is found, adapt its `origin` field. if po.origin: