Skip to content
Snippets Groups Projects
Commit d01f3865 authored by Fanny He's avatar Fanny He Committed by Nans Lefebvre
Browse files

[FIX] mail: allow to notify a user currently in another company


In particular, the problem forbids a user to lower quantities on a SO
if the responsible is currently in another company.

- Install sale_stock and sale
- Activate Multi-companies
- Create Company A and Company B
- Admin in A and B
- Other user U (e.g. duplicate of Admin) in B only
- U creates a SO with a product, confirms it
- Admin connects to Company A
- U decreases product_uom_qty in a line
- U gets an AccessError

When decreasing the quantity, in sale_stock,
_log_decrease_ordered_quantity is called and calls stock's _log_activity,
that needs access to the responsible or the superuser's partner.
If that user is in another company, this raises an AccessError.

Because it is when accessing the partner that the AccessError is raised,
we cannot cleanly use a check_access_rule to determine when to use sudo.

OPW 2036879

closes odoo/odoo#35132

Signed-off-by: default avatarNans Lefebvre (len) <len@odoo.com>
parent cc32b7d1
No related branches found
No related tags found
No related merge requests found
......@@ -282,6 +282,12 @@ class MailActivity(models.Model):
activity = super(MailActivity, self.sudo()).create(values_w_defaults)
activity_user = activity.sudo(self.env.user)
activity_user._check_access('create')
need_sudo = False
try: # in multicompany, reading the partner might break
partner_id = activity_user.user_id.partner_id.id
except exceptions.AccessError:
need_sudo = True
partner_id = activity_user.user_id.sudo().partner_id.id
# send a notification to assigned user; in case of manually done activity also check
# target has rights on document otherwise we prevent its creation. Automated activities
......@@ -290,9 +296,12 @@ class MailActivity(models.Model):
if not activity_user.automated:
activity_user._check_access_assignation()
if not self.env.context.get('mail_activity_quick_update', False):
activity_user.action_notify()
if need_sudo:
activity_user.sudo().action_notify()
else:
activity_user.action_notify()
self.env[activity_user.res_model].browse(activity_user.res_id).message_subscribe(partner_ids=[activity_user.user_id.partner_id.id])
self.env[activity_user.res_model].browse(activity_user.res_id).message_subscribe(partner_ids=[partner_id])
if activity.date_deadline <= fields.Date.today():
self.env['bus.bus'].sendone(
(self._cr.dbname, 'res.partner', activity.user_id.partner_id.id),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment