Exemplo n.º 1
0
 def decline(self, order_id, token, **post):
     Order = request.env['sale.order'].sudo().browse(order_id)
     if token != Order.access_token:
         return request.render('website.404')
     if Order.state != 'sent':
         return werkzeug.utils.redirect("/quote/%s/%s?message=4" % (order_id, token))
     Order.action_cancel()
     message = post.get('decline_message')
     if message:
         _message_post_helper(message=message, res_id=order_id, res_model='sale.order', **{'token': token, 'token_field': 'access_token'} if token else {})
     return werkzeug.utils.redirect("/quote/%s/%s?message=2" % (order_id, token))
Exemplo n.º 2
0
 def accept(self, order_id, token=None, signer=None, sign=None, **post):
     Order = request.env['sale.order'].sudo().browse(order_id)
     if token != Order.access_token or Order.require_payment:
         return request.render('website.404')
     if Order.state != 'sent':
         return False
     attachments = [('signature.png', sign.decode('base64'))] if sign else []
     Order.action_confirm()
     message = _('Order signed by %s') % (signer,)
     _message_post_helper(message=message, res_id=order_id, res_model='sale.order', attachments=attachments, **({'token': token, 'token_field': 'access_token'} if token else {}))
     return True
Exemplo n.º 3
0
    def accept(self,
               order_id,
               token=None,
               pantone=None,
               order_ref=None,
               signer=None,
               sign=None,
               **post):
        Order = request.env['sale.order'].sudo().browse(order_id)
        #Jagadeesh new
        values = {}
        if pantone:
            values.update({'pantone': pantone})
        if order_ref:
            values.update({'client_order_ref': order_ref})
        if values:
            Order.sudo().write(values)

#Jagadeesh end
        if token != Order.access_token or Order.require_payment:
            return request.render('website.404')
        if Order.state != 'sent':
            return False
        attachments = [('signature.png',
                        sign.decode('base64'))] if sign else []
        Order.action_confirm()
        message = _('Order signed by %s') % (signer, )
        _message_post_helper(message=message,
                             res_id=order_id,
                             res_model='sale.order',
                             attachments=attachments,
                             **({
                                 'token': token,
                                 'token_field': 'access_token'
                             } if token else {}))
        return True
Exemplo n.º 4
0
    def view(self, order_id, pdf=None, token=None, message=False, **post):
        # use sudo to allow accessing/viewing orders for public user
        # only if he knows the private token
        now = fields.Date.today()
        if token:
            Order = request.env['sale.order'].sudo().search([
                ('id', '=', order_id), ('access_token', '=', token)
            ])
        else:
            Order = request.env['sale.order'].search([('id', '=', order_id)])
        # Log only once a day
        if Order and request.session.get(
                'view_quote') != now and request.env.user.share:
            request.session['view_quote'] = now
            body = _('Quotation viewed by customer')
            _message_post_helper(
                res_model='sale.order',
                res_id=Order.id,
                message=body,
                token=token,
                token_field="access_token",
                message_type='notification',
                subtype="mail.mt_note",
                partner_ids=Order.user_id.sudo().partner_id.ids)
        if not Order:
            return request.render('website.404')

        # Token or not, sudo the order, since portal user has not access on
        # taxes, required to compute the total_amout of SO.
        order_sudo = Order.sudo()

        days = 0
        if order_sudo.validity_date:
            days = (fields.Date.from_string(order_sudo.validity_date) -
                    fields.Date.from_string(fields.Date.today())).days + 1
        if pdf:
            pdf = request.env.ref(
                'website_quote.report_web_quote').sudo().with_context(
                    set_viewport_size=True).render_qweb_pdf([order_sudo.id])[0]
            pdfhttpheaders = [('Content-Type', 'application/pdf'),
                              ('Content-Length', len(pdf))]
            return request.make_response(pdf, headers=pdfhttpheaders)
        transaction_id = request.session.get('quote_%s_transaction_id' %
                                             order_sudo.id)
        if not transaction_id:
            Transaction = request.env['payment.transaction'].sudo().search([
                ('reference', '=', order_sudo.name)
            ])
        else:
            Transaction = request.env['payment.transaction'].sudo().browse(
                transaction_id)
        values = {
            'quotation':
            order_sudo,
            'message':
            message and int(message) or False,
            'option':
            any(not x.line_id for x in order_sudo.options),
            'order_valid': (not order_sudo.validity_date)
            or (now <= order_sudo.validity_date),
            'days_valid':
            days,
            'action':
            request.env.ref('sale.action_quotations').id,
            'breadcrumb':
            request.env.user.partner_id == order_sudo.partner_id,
            'tx_id':
            Transaction.id if Transaction else False,
            'tx_state':
            Transaction.state if Transaction else False,
            'tx_post_msg':
            Transaction.acquirer_id.post_msg if Transaction else False,
            'need_payment':
            order_sudo.invoice_status == 'to invoice'
            and Transaction.state in ['draft', 'cancel', 'error'],
            'token':
            token,
        }

        if order_sudo.require_payment or values['need_payment']:
            values['acquirers'] = list(
                request.env['payment.acquirer'].sudo().search([
                    ('website_published', '=', True),
                    ('company_id', '=', order_sudo.company_id.id)
                ]))
            extra_context = {
                'submit_class': 'btn btn-primary',
                'submit_txt': _('Pay & Confirm')
            }
            values['buttons'] = {}
            for acquirer in values['acquirers']:
                values['buttons'][acquirer.id] = acquirer.with_context(
                    **extra_context
                ).render(
                    '/',
                    order_sudo.amount_total,
                    order_sudo.pricelist_id.currency_id.id,
                    values={
                        'return_url':
                        '/quote/%s/%s' %
                        (order_id, token) if token else '/quote/%s' % order_id,
                        'type':
                        'form',
                        'alias_usage':
                        _('If we store your payment information on our server, subscription payments will be made automatically.'
                          ),
                        'partner_id':
                        order_sudo.partner_id.id,
                    })
        history = request.session.get('my_quotes_history', [])
        values.update(get_records_pager(history, order_sudo))
        return request.render('website_quote.so_quotation', values)
Exemplo n.º 5
0
    def view(self, order_id, pdf=None, token=None, message=False, **post):
        # use sudo to allow accessing/viewing orders for public user
        # only if he knows the private token

        #Jagadeesh added
        no_pantone = False
        no_customer_ref = False
        #print 'before===============',no_pantone,no_customer_ref
        sale_order_obj = request.env['sale.order'].sudo().browse(order_id)
        if sale_order_obj.product_branding2_ids and not sale_order_obj.pantone:
            no_pantone = True

        if not sale_order_obj.client_order_ref:
            no_customer_ref = True
        #Jagadeesh end
#print 'after===============',no_pantone,no_customer_ref

        now = fields.Date.today()
        if token:
            Order = request.env['sale.order'].sudo().search([
                ('id', '=', order_id), ('access_token', '=', token)
            ])
            # Log only once a day
            if Order and request.session.get('view_quote') != now:
                request.session['view_quote'] = now
                body = _('Quotation viewed by customer')
                _message_post_helper(res_model='sale.order',
                                     res_id=Order.id,
                                     message=body,
                                     token=token,
                                     token_field="access_token",
                                     message_type='notification',
                                     subtype="mail.mt_note",
                                     partner_ids=Order.user_id.partner_id.ids)
        else:
            Order = request.env['sale.order'].search([('id', '=', order_id)])

        if not Order:
            return request.render('website.404')
        request.session['sale_order_id'] = Order.id

        days = 0
        if Order.validity_date:
            days = (fields.Date.from_string(Order.validity_date) -
                    fields.Date.from_string(fields.Date.today())).days + 1
        if pdf:
            pdf = request.env['report'].sudo().with_context(
                set_viewport_size=True).get_pdf([Order.id],
                                                'website_quote.report_quote')
            pdfhttpheaders = [('Content-Type', 'application/pdf'),
                              ('Content-Length', len(pdf))]
            return request.make_response(pdf, headers=pdfhttpheaders)
        transaction_id = request.session.get('quote_%s_transaction_id' %
                                             Order.id)
        if not transaction_id:
            Transaction = request.env['payment.transaction'].sudo().search([
                ('reference', '=', Order.name)
            ])
        else:
            Transaction = request.env['payment.transaction'].sudo().browse(
                transaction_id)
        values = {
            'quotation':
            Order,
            'message':
            message and int(message) or False,
            'option':
            bool(filter(lambda x: not x.line_id, Order.options)),
            'order_valid': (not Order.validity_date)
            or (now <= Order.validity_date),
            'days_valid':
            days,
            'action':
            request.env.ref('sale.action_quotations').id,
            'breadcrumb':
            request.env.user.partner_id == Order.partner_id,
            'tx_id':
            Transaction.id if Transaction else False,
            'tx_state':
            Transaction.state if Transaction else False,
            'tx_post_msg':
            Transaction.acquirer_id.post_msg if Transaction else False,
            'need_payment':
            Order.invoice_status == 'to invoice'
            and Transaction.state in ['draft', 'cancel', 'error'],
            'token':
            token,
        }

        if Order.require_payment or values['need_payment']:
            values['acquirers'] = list(
                request.env['payment.acquirer'].sudo().search([
                    ('website_published', '=', True),
                    ('company_id', '=', Order.company_id.id)
                ]))
            extra_context = {
                'submit_class': 'btn btn-primary',
                'submit_txt': _('Pay & Confirm')
            }
            values['buttons'] = {}
            for acquirer in values['acquirers']:
                values['buttons'][acquirer.id] = acquirer.with_context(
                    **extra_context
                ).render(
                    '/',
                    Order.amount_total,
                    Order.pricelist_id.currency_id.id,
                    values={
                        'return_url':
                        '/quote/%s/%s' %
                        (order_id, token) if token else '/quote/%s' % order_id,
                        'type':
                        'form',
                        'alias_usage':
                        _('If we store your payment information on our server, subscription payments will be made automatically.'
                          ),
                        'partner_id':
                        Order.partner_id.id,
                    })
        #Jagadeesh added
        return_url = '/quote/%s/%s' % (
            order_id, token) if token else '/quote/%s' % order_id
        #print 'vals===========',no_pantone,no_customer_ref
        values.update({
            'no_pantone': no_pantone,
            'no_customer_ref': no_customer_ref,
            'quote_id': order_id,
            'return_url': return_url
        })
        #Jagadeesh end
        return request.render('website_quote.so_quotation', values)
Exemplo n.º 6
0
    def view(self, order_id, pdf=None, token=None, message=False, **post):
        # use sudo to allow accessing/viewing orders for public user
        # only if he knows the private token
        now = fields.Date.today()
        if token:
            Order = request.env['sale.order'].sudo().search([('id', '=', order_id), ('access_token', '=', token)])
            # Log only once a day
            if Order and request.session.get('view_quote') != now:
                request.session['view_quote'] = now
                body = _('Quotation viewed by customer')
                _message_post_helper(res_model='sale.order', res_id=Order.id, message=body, token=token, token_field="access_token", message_type='notification', subtype="mail.mt_note", partner_ids=Order.user_id.partner_id.ids)
        else:
            Order = request.env['sale.order'].search([('id', '=', order_id)])

        if not Order:
            return request.render('website.404')
        request.session['sale_order_id'] = Order.id

        days = 0
        if Order.validity_date:
            days = (fields.Date.from_string(Order.validity_date) - fields.Date.from_string(fields.Date.today())).days + 1
        if pdf:
            pdf = request.env['report'].sudo().with_context(set_viewport_size=True).get_pdf([Order.id], 'website_quote.report_quote')
            pdfhttpheaders = [('Content-Type', 'application/pdf'), ('Content-Length', len(pdf))]
            return request.make_response(pdf, headers=pdfhttpheaders)
        transaction_id = request.session.get('quote_%s_transaction_id' % Order.id)
        if not transaction_id:
            Transaction = request.env['payment.transaction'].sudo().search([('reference', '=', Order.name)])
        else:
            Transaction = request.env['payment.transaction'].sudo().browse(transaction_id)
        values = {
            'quotation': Order,
            'message': message and int(message) or False,
            'option': bool(filter(lambda x: not x.line_id, Order.options)),
            'order_valid': (not Order.validity_date) or (now <= Order.validity_date),
            'days_valid': days,
            'action': request.env.ref('sale.action_quotations').id,
            'breadcrumb': request.env.user.partner_id == Order.partner_id,
            'tx_id': Transaction.id if Transaction else False,
            'tx_state': Transaction.state if Transaction else False,
            'tx_post_msg': Transaction.acquirer_id.post_msg if Transaction else False,
            'need_payment': Order.invoice_status == 'to invoice' and Transaction.state in ['draft', 'cancel', 'error'],
            'token': token,
        }

        if Order.require_payment or values['need_payment']:
            values['acquirers'] = list(request.env['payment.acquirer'].sudo().search([('website_published', '=', True), ('company_id', '=', Order.company_id.id)]))
            extra_context = {
                'submit_class': 'btn btn-primary',
                'submit_txt': _('Pay & Confirm')
            }
            values['buttons'] = {}
            for acquirer in values['acquirers']:
                values['buttons'][acquirer.id] = acquirer.with_context(**extra_context).render(
                    '/',
                    Order.amount_total,
                    Order.pricelist_id.currency_id.id,
                    values={
                        'return_url': '/quote/%s/%s' % (order_id, token) if token else '/quote/%s' % order_id,
                        'type': 'form',
                        'alias_usage': _('If we store your payment information on our server, subscription payments will be made automatically.'),
                        'partner_id': Order.partner_id.id,
                    })
        return request.render('website_quote.so_quotation', values)