diff --git a/addons/website_quotation/controllers/main.py b/addons/website_quotation/controllers/main.py index 17b31fd60f5..e012fabf385 100644 --- a/addons/website_quotation/controllers/main.py +++ b/addons/website_quotation/controllers/main.py @@ -37,25 +37,35 @@ class sale_quote(http.Controller): values = { 'quotation': order, 'message': message, - 'new_post' : request.httprequest.session.get('new_post',False) + 'new_post' : request.httprequest.session.get('new_post',False), + 'option': self._check_option_len(order), } return request.website.render('website_quotation.so_quotation', values) + def _check_option_len(self, order): + for option in order.options: + if not option.line_id: + return True + return False @http.route(['/quote/accept'], type='json', auth="public", website=True) def accept(self, order_id=None, token=None, signer=None, sign=None, **post): order_obj = request.registry.get('sale.order') order = order_obj.browse(request.cr, SUPERUSER_ID, order_id) assert token == order.access_token, 'Access denied, wrong token!' - attachment = { - 'name': 'sign.png', - 'datas':sign, - 'datas_fname': 'sign.png', - 'res_model': 'sale.order', - 'res_id': order_id, - } - request.registry['ir.attachment'].create(request.cr, request.uid, attachment, context=request.context) - order_obj.write(request.cr, request.uid, [order_id], {'signer_name':signer,'state': 'manual'}) - return [] + error = {} + if not signer: error['signer'] = 'missing' + if not sign: error['sign'] = 'missing' + if not error: + attachment = { + 'name': 'sign.png', + 'datas':sign, + 'datas_fname': 'sign.png', + 'res_model': 'sale.order', + 'res_id': order_id, + } + request.registry['ir.attachment'].create(request.cr, request.uid, attachment, context=request.context) + order_obj.write(request.cr, request.uid, [order_id], {'signer_name':signer,'state': 'manual'}) + return [error] @http.route(['/quote///decline'], type='http', auth="public", website=True) def decline(self, order_id, token, **post): @@ -107,7 +117,7 @@ class sale_quote(http.Controller): order_line_obj.write(request.cr, SUPERUSER_ID, [line_id], {'product_uom_qty': (quantity)}, context=request.context) return quantity - @http.route(["/template/"], type='http', auth="public", website=True) + @http.route(["/template/"], type='http', auth="user", website=True) def template_view(self, quote, **post): values = { 'template': quote, @@ -135,6 +145,6 @@ class sale_quote(http.Controller): }) line = request.registry.get('sale.order.line').create(request.cr, SUPERUSER_ID, vals, context=request.context) option_obj.write(request.cr, SUPERUSER_ID, [option.id], {'line_id': line}, context=request.context) - return werkzeug.utils.redirect("/quote/%s/%s" % (order.id, token)) + return werkzeug.utils.redirect("/quote/%s/%s#pricing" % (order.id, token)) diff --git a/addons/website_quotation/static/src/js/website_quotation.js b/addons/website_quotation/static/src/js/website_quotation.js index 51d40c6b284..825d655eabd 100644 --- a/addons/website_quotation/static/src/js/website_quotation.js +++ b/addons/website_quotation/static/src/js/website_quotation.js @@ -37,16 +37,29 @@ $(document).ready(function () { var href = $link.attr("action"); var order_id = href.match(/accept\/([0-9]+)/); var token = href.match(/token=(.*)/); - var datapair = $("#signature").jSignature("getData",'image') + var sign = false; + var signer_name = false; + if($('#signature').length > 0){ + var isSignature=$("#signature").jSignature('getData','base30')[1].length>1?true:false; + if (isSignature) + sign = JSON.stringify($("#signature").jSignature("getData",'image')[1]); + signer_name = $("#name").val(); + } openerp.jsonRpc("/quote/accept/", 'call', { 'order_id': parseInt(order_id[1]), 'token': token[1], - 'signer': $("#signer").val(), - 'sign': JSON.stringify(datapair[1]), + 'signer': signer_name, + 'sign': sign, }) .then(function (data) { - $('#modelaccept').modal('hide'); - location.reload(); + if(!_.isEmpty(data)){ + $('#modelaccept').modal('hide'); + var url = location.protocol+'//'+location.hostname+(location.port ? ':'+location.port : "") + window.location.replace(url +'/quote/'+order_id[1]+'/'+token[1]+'?message=3'); + } else{ + if (data[0]['signer']) $('#signer').addClass('has-error'); else $('#signer').removeClass('has-error'); + if (data[0]['sign']) $('#drawsign').addClass('panel-danger'); else $('#drawsign').removeClass('panel-danger'); + } }); return false }); @@ -54,7 +67,7 @@ $(document).ready(function () { var ul = $('[data-id="quote_sidebar"]'); var sub_li = null; var sub_ul = null; - + ul.empty(); $("section h1, section h2").each(function() { switch (this.tagName.toLowerCase()) { case "h1": diff --git a/addons/website_quotation/views/website_quotation.xml b/addons/website_quotation/views/website_quotation.xml index 87a918b7dd4..0fe8951de04 100644 --- a/addons/website_quotation/views/website_quotation.xml +++ b/addons/website_quotation/views/website_quotation.xml @@ -94,8 +94,8 @@ + + + + +