Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

odoo 12 custom pos lock screen module this.pos is null

Subscribe

Get notified when there's activity on this post

This question has been flagged
point_of_saleodoo12
4830 Views
Avatar
akram sahbi

Hello, i made a module for odoo 12 to lock the pos screen. in the models.js, i want to switch the orders of different cashiers but this.pos is not initialized, what should i do so that it becomes initialized?
here is my code:

odoo.define('pos_user_lock.models',

//['point_of_sale.models','point_of_sale.screens','point_of_sale.chrome'

//,'web.ajax','web.core'], 

function (require) {

"use strict";


var ajax = require('web.ajax');

var screens = require('point_of_sale.screens');

var models = require('point_of_sale.models');

var chrome = require('point_of_sale.chrome');

var core = require('web.core');

var QWeb = core.qweb;

var _t = core._t;





models.Order = models.Order.extend({

    initialize: function(attributes,options){

        var order =  models.Order.__super__.initialize.call(this,attributes,options);

        if (!this.cashier)

        {

            this.cashier = this.pos.cashier || this.pos.user;

        }

        

        

        this.is_last_selected = (this.is_last_selected === undefined) ? false:this.is_last_selected;

        return order;

    },

    finalize: function() {

        var res =  models.Order.__super__.finalize.call(this);

        this.pos.lock_user_screen();

    },

    init_from_JSON: function(json) {

        var user = this.get_user_by_id(json.user_id);

        if (user)

            this.cashier = user;

        this.is_last_selected = json.is_last_selected;

        models.Order.__super__.init_from_JSON.call(this, json);

    },

    export_as_JSON: function() {

        var res =  models.Order.__super__.export_as_JSON.call(this);

        if (this.cashier)

            res.user_id = this.cashier.id ;

        if(this.pos && this.pos.get_cashier())

            res.user_id = this.pos.get_cashier().id ;

        res.is_last_selected = this.is_last_selected;

        return res;

    },

    get_user_by_id: function(id) {

        var users = this.pos.users;

        for (var i = 0; i < users.length; i++) {

            var user = users[i];

            if (user.id == id)

                return user;

        }

    },


});


models.PosModel = models.PosModel.extend({

    initialize: function(session, attributes) {

        models.PosModel.__super__.initialize.call(this, session, attributes);

        

        var self = this;

        alert(JSON.stringify(attributes.pos));

        this.ready.then(function(){

            if (self.config.auto_push_order)

                self.config.iface_precompute_cash = true;

        });

    },

    is_locked: function(){

        if (

            this.gui.current_popup 

            && this.gui.current_popup.template == 'PasswordPinPopupWidget'

        ){

            return true;

        }

        return false;

    },

    unlock: function(){

        if (this.is_locked()){

            this.gui.close_popup();

        }

    },

    lock_user_screen: function(){

        var self = this;

        if (!this.config.lock_users) return;

        this.gui.show_popup('passwordPin',{

            'title': _t('Insert password or scan your barcode'),

        });

    },

    get_last_order: function(){

        var orders = this.get_order_list();

        for (var i = 0; i < orders.length; i++) {

            if (orders[i].is_last_selected) {

                return orders[i];

            }

        }

        return null;

    },

    set_last_order: function(order){

        var orders = this.get_order_list();

        for (var i = 0; i < orders.length; i++) {

            if (orders[i].uid == order.uid) {

                orders[i].is_last_selected = true;

            }else{

                orders[i].is_last_selected = false;

            }

        }

        return null;

    },

    set_order: function(order){

        models.PosModel.__super__.set_order.call(this, order);

        this.set_last_order(order);

    },

    get_order_list: function(){

        var orders = models.PosModel.__super__.get_order_list.call(this);

        var c_orders = [];

        var cashier = this.cashier || this.user;

        for (var i = 0; i < orders.length; i++) {

            if (cashier && orders[i].cashier.id === cashier.id) {

                c_orders.push(orders[i]);

            }

        }

        return c_orders;

    },

    switch_order: function(){

        var self = this;

        if(self.pos)

        {

        }

        else

        {

            alert("self.pos is null");

        }

        if(self !== undefined && self != null && self.pos !== undefined && self.pos.currency != null)

        {

            alert("in switch order");

            //console.log(this.pos.currency);

                if (!self.config.lock_users) return;

                var user = self.pos.get_cashier() || self.user;

                

                var orders = self.get_order_list();

                

                var last_order = self.get_last_order() || orders[0];

                

                if (orders.length) {

                    

                    self.set_order(last_order);

                    

                } 

                else {

                    

                    self.add_new_order();

                    

                }

                        

        }

        

    },

    set_cashier: function(user){

        models.PosModel.__super__.set_cashier.call(this,user);

        if(this.pos)

        {

            alert("this.pos is not null in set_cashier");

        }

        else

        {

            alert("this.pos is null in set_cashier");

        }

        this.switch_order(this);

        if (!this.table && this.config.iface_floorplan)

            this.set_table(null);

    },



});

return models;


});

0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Sign up
Related Posts Replies Views Activity
"AttributeError: 'bool' object has no attribute 'date'" when trying to access the point of sale module. Solved
bugs point_of_sale odoo12
Avatar
Avatar
2
May 23
11927
Why POS is making this error?
js point_of_sale odoo12
Avatar
0
Jun 22
2511
Point of sale access error
point_of_sale ErrorTraceback odoo12
Avatar
2
Jun 20
4358
Point of sale access error
point_of_sale access_error odoo12
Avatar
0
Jun 20
3190
Configuring Advanced Rights to Hide 'Cost' on POS Screen for Employees
point_of_sale
Avatar
Avatar
1
Jul 25
2693
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now