From d7ac037de59832bf17d62e83dbd5d6911351048d Mon Sep 17 00:00:00 2001 From: rhe-odoo Date: Fri, 29 Jul 2022 08:50:39 +0000 Subject: [PATCH] [FIX] pos_restaurant: don't clean orders with paiements When you have orders that have paiement and not lines anymore they can be removed from the local storage if the screen is refreshed. That may lead to loss of paiements. closes odoo/odoo#104363 X-original-commit: 49381e5f821368c0c4d6e20207ce7d51abbe8be0 Signed-off-by: Masereel Pierre --- .../js/Screens/ProductScreen/ProductScreen.js | 2 ++ addons/point_of_sale/static/src/js/db.js | 27 +++++++++---------- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js index 19d935e3426..6afa8e13e58 100644 --- a/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js +++ b/addons/point_of_sale/static/src/js/Screens/ProductScreen/ProductScreen.js @@ -168,6 +168,8 @@ odoo.define('point_of_sale.ProductScreen', function(require) { async _updateSelectedOrderline(event) { if (this.env.pos.numpadMode === 'quantity' && this.env.pos.disallowLineQuantityChange()) { let order = this.env.pos.get_order(); + if(!order.orderlines.length) + return; let selectedLine = order.get_selected_orderline(); let orderlines = order.orderlines; let lastId = orderlines.length !== 0 && orderlines.at(orderlines.length - 1).cid; diff --git a/addons/point_of_sale/static/src/js/db.js b/addons/point_of_sale/static/src/js/db.js index b627361ba09..0eda21f8b7b 100644 --- a/addons/point_of_sale/static/src/js/db.js +++ b/addons/point_of_sale/static/src/js/db.js @@ -27,7 +27,7 @@ var PosDB = core.Class.extend({ options = options || {}; this.name = options.name || this.name; this.limit = options.limit || this.limit; - + if (options.uuid) { this.name = this.name + '_' + options.uuid; } @@ -52,7 +52,7 @@ var PosDB = core.Class.extend({ this.category_search_string = {}; }, - /** + /** * sets an uuid to prevent conflict in locally stored data between multiple PoS Configs. By * using the uuid of the config the local storage from other configs will not get effected nor * loaded in sessions that don't belong to them. @@ -64,8 +64,8 @@ var PosDB = core.Class.extend({ }, /* returns the category object from its id. If you pass a list of id as parameters, you get - * a list of category objects. - */ + * a list of category objects. + */ get_category_by_id: function(categ_id){ if(categ_id instanceof Array){ var list = []; @@ -82,7 +82,7 @@ var PosDB = core.Class.extend({ return this.category_by_id[categ_id]; } }, - /* returns a list of the category's child categories ids, or an empty list + /* returns a list of the category's child categories ids, or an empty list * if a category has no childs */ get_category_childs_ids: function(categ_id){ return this.category_childs[categ_id] || []; @@ -98,7 +98,7 @@ var PosDB = core.Class.extend({ return this.category_parent[categ_id] || this.root_category_id; }, /* adds categories definitions to the database. categories is a list of categories objects as - * returned by the openerp server. Categories must be inserted before the products or the + * returned by the openerp server. Categories must be inserted before the products or the * product/ categories association may (will) not work properly */ add_categories: function(categories){ var self = this; @@ -276,9 +276,9 @@ var PosDB = core.Class.extend({ // FIXME: The write_date is stored with milisec precision in the database // but the dates we get back are only precise to the second. This means when // you read partners modified strictly after time X, you get back partners that were - // modified X - 1 sec ago. + // modified X - 1 sec ago. continue; - } else if ( new_write_date < partner.write_date ) { + } else if ( new_write_date < partner.write_date ) { new_write_date = partner.write_date; } if (!this.partner_by_id[partner.id]) { @@ -292,7 +292,7 @@ var PosDB = core.Class.extend({ this.partner_write_date = new_write_date || this.partner_write_date; if (updated_count) { - // If there were updates, we need to completely + // If there were updates, we need to completely // rebuild the search string and the barcode indexing this.partner_search_string = ""; @@ -394,7 +394,7 @@ var PosDB = core.Class.extend({ }, /* returns a list of products with : * - a category that is or is a child of category_id, - * - a name, package or barcode containing the query (case insensitive) + * - a name, package or barcode containing the query (case insensitive) */ search_product_in_category: function(category_id, query){ try { @@ -523,12 +523,12 @@ var PosDB = core.Class.extend({ */ get_unpaid_orders_to_sync: function(ids){ const savedOrders = this.load('unpaid_orders',[]); - return savedOrders.filter(order => ids.includes(order.id)); + return savedOrders.filter(order => ids.includes(order.id) && (order.data.server_id || order.data.lines.length || order.data.statement_ids.length)); }, /** * Add a given order to the orders to be removed from the server. * - * If an order is removed from a table it also has to be removed from the server to prevent it from reapearing + * If an order is removed from a table it also has to be removed from the server to prevent it from reapearing * after syncing. This function will add the server_id of the order to a list of orders still to be removed. * @param {object} order object. */ @@ -552,7 +552,7 @@ var PosDB = core.Class.extend({ */ set_ids_removed_from_server: function(ids){ var to_remove = this.load('unpaid_orders_to_remove',[]); - + to_remove = _.filter(to_remove, function(id){ return !ids.includes(id); }); @@ -563,4 +563,3 @@ var PosDB = core.Class.extend({ return PosDB; }); -