Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • How to modify javascript function in point of sale in odoo 9

    • 0
    • 0
    • 0
    • 0
    • 2
    • 0
    • 0
    • 0
    • 1.97k
    Comment on it

    To modify javascript in Odoo-9 follow the below steps
    Go to point of sale module ->static file->src->js->screens.js
    For example you can use the below code in screens.js file.

    function openerp_pos_screens(instance, module){ //module is instance.point_of_sale
        var QWeb = instance.web.qweb;
    
        module.ScreenSelector = instance.web.Class.extend({
            init: function(options){
                this.pos = options.pos;
    
                this.screen_set = options.screen_set || {};
    
                this.popup_set = options.popup_set || {};
    
                this.default_client_screen = options.default_client_screen;
                this.default_cashier_screen = options.default_cashier_screen;
    
                this.current_popup = null;
    
                this.current_mode = options.default_mode || 'client';
    
                this.current_screen = null; 
    
                for(screen_name in this.screen_set){
                    this.screen_set[screen_name].hide();
                }
    
                for(popup_name in this.popup_set){
                    this.popup_set[popup_name].hide();
                }
    
                this.selected_order = this.pos.get('selectedOrder');
                this.selected_order.set_screen_data({
                    client_screen: this.default_client_screen,
                    cashier_screen: this.default_cashier_screen,
                });
    
                this.pos.bind('change:selectedOrder', this.load_saved_screen, this);
            },
            add_screen: function(screen_name, screen){
                screen.hide();
                this.screen_set[screen_name] = screen;
                return this;
            },
            show_popup: function(name){
                if(this.current_popup){
                    this.close_popup();
                }
                this.current_popup = this.popup_set[name];
                this.current_popup.show();
            },
            close_popup: function(){
                if(this.current_popup){
                    this.current_popup.close();
                    this.current_popup.hide();
                    this.current_popup = null;
                }
            },
            load_saved_screen:  function(){
                this.close_popup();
    
                var selectedOrder = this.pos.get('selectedOrder');
    
                if(this.current_mode === 'client'){
                    this.set_current_screen(selectedOrder.get_screen_data('client_screen') || this.default_client_screen,null,'refresh');
                }else if(this.current_mode === 'cashier'){
                    this.set_current_screen(selectedOrder.get_screen_data('cashier_screen') || this.default_cashier_screen,null,'refresh');
                }
                this.selected_order = selectedOrder;
            },
            set_user_mode: function(user_mode){
                if(user_mode !== this.current_mode){
                    this.close_popup();
                    this.current_mode = user_mode;
                    this.load_saved_screen();
                }
            },
            get_user_mode: function(){
                return this.current_mode;
            },
            set_current_screen: function(screen_name,params,refresh){
                var screen = this.screen_set[screen_name];
                if(!screen){
                    console.error("ERROR: set_current_screen("+screen_name+") : screen not found");
                }
    
                this.close_popup();
                var selectedOrder = this.pos.get('selectedOrder');
                if(this.current_mode === 'client'){
                    selectedOrder.set_screen_data('client_screen',screen_name);
                    if(params){ 
                        selectedOrder.set_screen_data('client_screen_params',params); 
                    }
                }else{
                    selectedOrder.set_screen_data('cashier_screen',screen_name);
                    if(params){
                        selectedOrder.set_screen_data('cashier_screen_params',params);
                    }
                }
    
                if(screen && (refresh || screen !== this.current_screen)){
                    if(this.current_screen){
                        this.current_screen.close();
                        this.current_screen.hide();
                    }
                    this.current_screen = screen;
                    this.current_screen.show();
                }
            },
            get_current_screen_param: function(param){
                var selected_order = this.pos.get('selectedOrder');
                if(this.current_mode === 'client'){
                    var params = selected_order.get_screen_data('client_screen_params');
                }else{
                    var params = selected_order.get_screen_data('cashier_screen_params');
                }
                if(params){
                    return params[param];
                }else{
                    return undefined;
                }
            },
            set_default_screen: function(){
                this.set_current_screen(this.current_mode === 'client' ? this.default_client_screen : this.default_cashier_screen);
            },
        });
    
        module.ScreenWidget = module.PosBaseWidget.extend({
    
            show_numpad:     true,  
            show_leftpane:   true,
    
            init: function(parent,options){
                this._super(parent,options);
                this.hidden = false;
            },
    
            help_button_action: function(){
                this.pos_widget.screen_selector.show_popup('help');
            },
    
            barcode_product_screen:         'products',     //if defined, this screen will be loaded when a product is scanned
            barcode_product_error_popup:    'error-product',    //if defined, this popup will be loaded when there's an error in the popup
    
            // what happens when a product is scanned : 
            // it will add the product to the order and go to barcode_product_screen. Or show barcode_product_error_popup if 
            // there's an error.
            barcode_product_action: function(ean){
                var self = this;
                if(self.pos.scan_product(ean)){
                    self.pos.proxy.scan_item_success(ean);
                    if(self.barcode_product_screen){ 
                        self.pos_widget.screen_selector.set_current_screen(self.barcode_product_screen);
                    }
                }else{
                    self.pos.proxy.scan_item_error_unrecognized(ean);
                    if(self.barcode_product_error_popup && self.pos_widget.screen_selector.get_user_mode() !== 'cashier'){
                        self.pos_widget.screen_selector.show_popup(self.barcode_product_error_popup);
                    }
                }
            },
    
            // what happens when a cashier id barcode is scanned.
            // the default behavior is the following : 
            // - if there's a user with a matching ean, put it as the active 'cashier', go to cashier mode, and return true
            // - else : do nothing and return false. You probably want to extend this to show and appropriate error popup... 
            barcode_cashier_action: function(ean){
                var users = this.pos.get('user_list');
                for(var i = 0, len = users.length; i < len; i++){
                    if(users[i].ean13 === ean.ean){
                        this.pos.set('cashier',users[i]);
                        this.pos_widget.username.refresh();
                        this.pos.proxy.cashier_mode_activated();
                        this.pos_widget.screen_selector.set_user_mode('cashier');
                        return true;
                    }
                }
                this.pos.proxy.scan_item_error_unrecognized(ean);
                return false;
            },
    
            // what happens when a client id barcode is scanned.
            // the default behavior is the following : 
            // - if there's a user with a matching ean, put it as the active 'client' and return true
            // - else : return false. 
            barcode_client_action: function(ean){
                var partners = this.pos.get('partner_list');
                for(var i = 0, len = partners.length; i < len; i++){
                    if(partners[i].ean13 === ean.ean){
                        this.pos.get('selectedOrder').set_client(partners[i]);
                        this.pos_widget.username.refresh();
                        this.pos.proxy.scan_item_success(ean);
                        return true;
                    }
                }
                this.pos.proxy.scan_item_error_unrecognized(ean);
                return false;

 2 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: