From a3e048a001fafd870b9c0d0142a2e7a2eb5a7171 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 25 Aug 2017 13:30:51 +0200 Subject: [PATCH] [IMP] sale: support quote confirmation and sign in customer portal Purpose is to allow customers to accept and confirm orders on the customer portal without having to rely on advanced website_quote (online quotation) features. Including : * add quote confirmation route; * add support in customer portal using the newly-introduced signature widget; * add action button on the order page view; --- addons/sale/controllers/portal.py | 36 ++++++++++++++++++++- addons/sale/views/assets.xml | 6 ++-- addons/sale/views/sale_portal_templates.xml | 28 ++++++++++++++-- 3 files changed, 64 insertions(+), 6 deletions(-) diff --git a/addons/sale/controllers/portal.py b/addons/sale/controllers/portal.py index af548cfe57e..baf3078d87a 100644 --- a/addons/sale/controllers/portal.py +++ b/addons/sale/controllers/portal.py @@ -1,11 +1,13 @@ # -*- coding: utf-8 -*- # Part of Odoo. See LICENSE file for full copyright and licensing details. +import base64 + from odoo import http, _ from odoo.exceptions import AccessError from odoo.http import request from odoo.tools import consteq - +from odoo.addons.portal.controllers.mail import _message_post_helper from odoo.addons.portal.controllers.portal import CustomerPortal, pager as portal_pager, get_records_pager @@ -54,6 +56,8 @@ class CustomerPortal(CustomerPortal): } if access_token: values['no_breadcrumbs'] = True + values['access_token'] = access_token + values['portal_confirmation'] = request.env['ir.config_parameter'].sudo().get_param('sale.sale_portal_confirmation_options', default='none') if kwargs.get('error'): values['error'] = kwargs['error'] @@ -64,6 +68,7 @@ class CustomerPortal(CustomerPortal): history = request.session.get('my_orders_history', []) values.update(get_records_pager(history, order)) + return values @http.route(['/my/quotes', '/my/quotes/page/'], type='http', auth="user", website=True) @@ -192,3 +197,32 @@ class CustomerPortal(CustomerPortal): ('Content-Length', len(pdf)), ] return request.make_response(pdf, headers=pdfhttpheaders) + + @http.route(['/my/quotes/accept'], type='json', auth="public", website=True) + def portal_quote_accept(self, res_id, access_token=None, partner_name=None, signature=None): + if request.env['ir.config_parameter'].sudo().get_param( + 'sale.sale_portal_confirmation_options', default='none') not in ('pay', 'sign'): + return False + try: + order_sudo = self._order_check_access(res_id, access_token=access_token) + except AccessError: + return { + 'error': _('Invalid order') + } + + if order_sudo.state != 'sent': + return { + 'error': _('Order is not in a state requiring customer validation.') + } + order_sudo.action_confirm() + + _message_post_helper( + res_model='sale.order', + res_id=order_sudo.id, + message=_('Order signed by %s') % (partner_name,), + attachments=[('signature.png', base64.b64decode(signature))] if signature else [], + **({'token': access_token, 'token_field': 'access_token'} if access_token else {})) + return { + 'success': _('Your Order has been confirmed.'), + 'redirect_url': '/my/orders/%s?%s' % (order_sudo.id, access_token and 'access_token=%s' % order_sudo.access_token or ''), + } diff --git a/addons/sale/views/assets.xml b/addons/sale/views/assets.xml index ac906fd317f..9f89db5ab72 100644 --- a/addons/sale/views/assets.xml +++ b/addons/sale/views/assets.xml @@ -7,8 +7,8 @@ diff --git a/addons/sale/views/sale_portal_templates.xml b/addons/sale/views/sale_portal_templates.xml index e0165be86b2..bed706cd64d 100644 --- a/addons/sale/views/sale_portal_templates.xml +++ b/addons/sale/views/sale_portal_templates.xml @@ -131,6 +131,8 @@