[FIX] sale: clean unnecessary portal/access code

Override of ``get_access_action`` in sale_management is useless. Indeed
it redirects to the portal when

  * there is an order template;
  * user is share OR force_website is in context;

This override calls ``get_portal_url``. This method basically crafts link like
``access_url?access_token=TOKEN`` as no other argument is given to portal
url computation method.

Using the standard ``get_access_action`` gives the same result. When having
read rights on the record (which is implied for current code), portal override
already calls ``_get_share_url``. Moreover portal version effectively checks
requested access_uid has read access while current override uses current user
which may lead to strange results depending on call chain.

Removing this kind of override simplifies management of notification emails
and buttons, especially that "Pay Now" template is about to be cleaned.

This notably partially reverts odoo/odoo@b49da62365 and some other commits. Those
are anyway linked to mails sent when sale did not have its portal available
directly from sale as portal was a side module. Website quote was adding its
own portal-related logic (accept and pay). All this is now standard in sale
and it makes sense to use standard ``get_access_action`` code when possible.

Task-2712450 (Mail/Sale: Improve 'Pay Now' notification template)

Part-of: odoo/odoo#82627
This commit is contained in:
Thibault Delavallée
2022-01-14 16:37:46 +00:00
parent 139e900276
commit e7b40e783a
@@ -135,20 +135,6 @@ class SaleOrder(models.Model):
order.sale_order_template_id.mail_template_id.send_mail(order.id)
return res
def get_access_action(self, access_uid=None):
""" Instead of the classic form view, redirect to the online quote if it exists. """
self.ensure_one()
user = access_uid and self.env['res.users'].sudo().browse(access_uid) or self.env.user
if not self.sale_order_template_id or (not user.share and not self.env.context.get('force_website')):
return super().get_access_action(access_uid)
return {
'type': 'ir.actions.act_url',
'url': self.get_portal_url(),
'target': 'self',
'res_id': self.id,
}
def update_prices(self):
super().update_prices()
# Special case: we want to overwrite the existing discount on update_prices call