Client ODOO Error: QWeb is not defined

1.2k Views Asked by At

I hope you could help me, I already use odoo .v8, well I'm working over Point of Sale module, and I'm tring to inherit some methods for printing, everything was good until when I redefine validate_order I get this error on client side:

Uncaught ReferenceError: QWeb is not defined

this is my code how I redefine validate_order method:

 function openerp_tpv_screens(instance, module){
 var Qweb = instance.web.qweb;
 var _t = instance.web._t;

 module.PaymentScreenWidget=module.PaymentScreenWidget.extend({

 validate_order: function(options) {
        var self = this;
        options = options || {};

        var currentOrder = this.pos.get('selectedOrder');

        if(currentOrder.get('orderLines').models.length === 0){
            this.pos_widget.screen_selector.show_popup('error',{
                'message': _t('Empty Order'),
                'comment': _t('There must be at least one product in your order before it can be validated'),
            });
            return;
        }

        var plines = currentOrder.get('paymentLines').models;
        for (var i = 0; i < plines.length; i++) {
            if (plines[i].get_type() === 'bank' && plines[i].get_amount() < 0) {
                this.pos_widget.screen_selector.show_popup('error',{
                    'message': _t('Negative Bank Payment'),
                    'comment': _t('You cannot have a negative amount in a Bank payment. Use a cash payment method to return money to the customer.'),
                });
                return;
            }
        }

        if(!this.is_paid()){
            return;
        }

        // The exact amount must be paid if there is no cash payment method defined.
        if (Math.abs(currentOrder.getTotalTaxIncluded() - currentOrder.getPaidTotal()) > 0.00001) {
            var cash = false;
            for (var i = 0; i < this.pos.cashregisters.length; i++) {
                cash = cash || (this.pos.cashregisters[i].journal.type === 'cash');
            }
            if (!cash) {
                this.pos_widget.screen_selector.show_popup('error',{
                    message: _t('Cannot return change without a cash payment method'),
                    comment: _t('There is no cash payment method available in this point of sale to handle the change.\n\n Please pay the exact amount or add a cash payment method in the point of sale configuration'),
                });
                return;
            }
        }

        if (this.pos.config.iface_cashdrawer) {
                this.pos.proxy.open_cashbox();
        }

        if(options.invoice){
            // deactivate the validation button while we try to send the order
            this.pos_widget.action_bar.set_button_disabled('validation',true);
            this.pos_widget.action_bar.set_button_disabled('invoice',true);
            this.pos_widget.action_bar.set_button_disabled('invoice_03',true);

            var invoiced = this.pos.push_and_invoice_order(currentOrder);

            invoiced.fail(function(error){
                if(error === 'error-no-client' || error === 'error-generic-client'){
                    self.pos_widget.screen_selector.show_popup('error',{
                        message: _t('An anonymous order cannot be invoiced'),
                        comment: _t('Please select a client for this order. This can be done by clicking the order tab'),
                    });
                }else if(error === 'error-no-generic-client'){
                    self.pos_widget.screen_selector.show_popup('error',{
                        message: _t('An anonymous order cannot be invoiced'),
                        comment: _t('No se debe seleccionar un Cliente Genérico.'),
                    });
                }else{
                    self.pos_widget.screen_selector.show_popup('error',{
                        message: _t('The order could not be sent'),
                        comment: _t('Check your internet connection and try again.'),
                    });
                }
                self.pos_widget.action_bar.set_button_disabled('validation',false);
                self.pos_widget.action_bar.set_button_disabled('invoice',false);
                self.pos_widget.action_bar.set_button_disabled('invoice_03',false);
            });

            invoiced.done(function(){
                self.pos_widget.action_bar.set_button_disabled('validation',false);
                self.pos_widget.action_bar.set_button_disabled('invoice',false);
                self.pos_widget.action_bar.set_button_disabled('invoice_03',false);
                self.pos.get('selectedOrder').destroy();
            });

        }else{
            this.pos.push_order(currentOrder) 
            if(this.pos.config.iface_print_via_proxy){
                var receipt = currentOrder.export_for_printing();
                this.pos.proxy.print_receipt(QWeb.render('XmlReceipt',{
                    receipt: receipt, widget: self,
                }));
                this.pos.get('selectedOrder').destroy();    //finish order and go back to scan screen
            }else{
                this.pos_widget.screen_selector.set_current_screen(this.next_screen);
            }
        }

        // hide onscreen (iOS) keyboard 
        setTimeout(function(){
            document.activeElement.blur();
            $("input").blur();
        },250);
    },

});

the specific line that give me the error is:

 this.pos.proxy.print_receipt(QWeb.render('XmlReceipt',{
                    receipt: receipt, widget: self,
                }));`

Qweb is not defined is the error but I did it: var Qweb = instance.web.qweb;enter image description here

Thanks for your time.

1

There are 1 best solutions below

3
On

Try to pass your rendered template in an object and call this object in your code. After that if it didn't work check your __openerp__.py file. In that check your path of Qweb template it should be like this:

'qweb': ['static/src/xml/pos.xml']

After that don't forget to check your js file path in xml file it should be like this:

<template id="assets_backend" name="pos assets" inherit_id="web.assets_backend">
        <xpath expr="." position="inside">
            <script type="text/javascript" src="/module_name/static/src/js/file_name.js"></script>
    </template>

After this run again and check weather error is resolved or not.