[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) <nim@odoo.com>
This commit is contained in:
@@ -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:
|
||||
|
||||
Reference in New Issue
Block a user