[IMP] sale, website_quote: improve email link and wording computation

The 'View', 'Accept and Sign', 'Pay Online' buttons are now correctly
computed based on the sales settings or the online quote settings.
Indeed it is now possible to sign and/or pay quotations without having
website_quote module installed.
This commit is contained in:
Thibault Delavallée
2017-09-06 10:49:02 +02:00
parent 1925837d47
commit 2d4c8103f9
3 changed files with 36 additions and 12 deletions
+2 -2
View File
@@ -18,8 +18,8 @@
% set access_action = object.with_context(force_website=True).get_access_action()
% set is_online = access_action and access_action['type'] == 'ir.actions.act_url'
% set doc_name = 'quotation' if object.state in ('draft', 'sent') else 'order confirmation'
% set pay_sign_name = ('require_payment' in object and object.require_payment and 'pay') or 'sign'
% set access_name = is_online and object.template_id and object.state in ('draft', 'sent') and 'Accept and %s online' % pay_sign_name or 'View %s' % doc_name
% set pay_sign_name = object.get_portal_confirmation_action()
% set access_name = is_online and object.state in ('draft', 'sent') and pay_sign_name in ('pay', 'sign') and 'Accept and %s online' % pay_sign_name or 'View %s' % doc_name
% set access_url = is_online and object.get_mail_url() or ''
% if object.partner_id.parent_id:
+28 -10
View File
@@ -572,22 +572,40 @@ class SaleOrder(models.Model):
portal users or if force_website=True in the context. """
# TDE note: read access on sales order to portal users granted to followed sales orders
self.ensure_one()
if self.state == 'cancel' or (self.state == 'draft' and not self.env.context.get('mark_so_as_sent')):
return super(SaleOrder, self).get_access_action(access_uid)
user = self.env['res.users'].sudo().browse(access_uid) if access_uid else self.env.user
if user.share or self.env.context.get('force_website'):
return {
'type': 'ir.actions.act_url',
'url': '/my/orders/%s?access_token=%s' % (self.id, self.access_token),
'target': 'self',
'res_id': self.id,
}
if self.state != 'cancel' and (self.state != 'draft' or self.env.context.get('mark_so_as_sent')):
user, record = self.env.user, self
if access_uid:
user = self.env['res.users'].sudo().browse(access_uid)
record = self.sudo(user)
if user.share or self.env.context.get('force_website'):
try:
record.check_access_rule('read')
except AccessError:
if self.env.context.get('force_website'):
return {
'type': 'ir.actions.act_url',
'url': '/my/orders/%s' % self.id,
'target': 'self',
'res_id': self.id,
}
else:
pass
else:
return {
'type': 'ir.actions.act_url',
'url': '/my/orders/%s?access_token=%s' % (self.id, self.access_token),
'target': 'self',
'res_id': self.id,
}
return super(SaleOrder, self).get_access_action(access_uid)
def get_mail_url(self):
return self.get_share_url()
def get_portal_confirmation_action(self):
return self.env['ir.config_parameter'].sudo().get_param('sale.sale_portal_confirmation_options', default='none')
@api.multi
def _notification_recipients(self, message, groups):
groups = super(SaleOrder, self)._notification_recipients(message, groups)
@@ -190,6 +190,12 @@ class SaleOrder(models.Model):
return '/quote/%s/%s?' % (self.id, self.access_token) + auth_param
return super(SaleOrder, self).get_mail_url()
def get_portal_confirmation_action(self):
""" Template override default behavior of pay / sign chosen in sales settings """
if self.template_id:
return 'sign' if self.require_payment == 1 else 'pay'
return super(SaleOrder, self).get_portal_confirmation_action()
@api.multi
def _confirm_online_quote(self, transaction):
""" Payment callback: validate the order and write transaction details in chatter """