Commit 7a543c46 by Damien Moulard

Merge branch '4074' into 'dev_cooperatic'

#4074 : add product to order if scanned in search input

See merge request !55
parents 1f4f45bf 8eeca293
...@@ -128,7 +128,7 @@ odoo.define('lacagette_custom_pos.DB', function(require) { ...@@ -128,7 +128,7 @@ odoo.define('lacagette_custom_pos.DB', function(require) {
this.category_cache = new screens.DomCache(); this.category_cache = new screens.DomCache();
this.start_categ_id = this.pos.config.iface_start_categ_id ? this.pos.config.iface_start_categ_id[0] : 0; this.start_categ_id = this.pos.config.iface_start_categ_id ? this.pos.config.iface_start_categ_id[0] : 0;
this.set_category(this.pos.db.get_category_by_id(this.start_categ_id)); this.set_category(this.pos.db.get_category_by_id(this.start_categ_id));
this.switch_category_handler = function(event){ this.switch_category_handler = function(event){
self.set_category(self.pos.db.get_category_by_id(Number(this.dataset.categoryId))); self.set_category(self.pos.db.get_category_by_id(Number(this.dataset.categoryId)));
self.renderElement(); self.renderElement();
...@@ -153,10 +153,52 @@ odoo.define('lacagette_custom_pos.DB', function(require) { ...@@ -153,10 +153,52 @@ odoo.define('lacagette_custom_pos.DB', function(require) {
// Add timeout: loose focus after 5s without a keypress // Add timeout: loose focus after 5s without a keypress
clearTimeout(blur_timeout) clearTimeout(blur_timeout)
blur_timeout = setTimeout(function() { blur_timeout = setTimeout(function() {
$('.searchbox input').blur() $('.searchbox input').blur()
this.lastSubmittedQuery = null;
}, 5000) }, 5000)
} }
}; };
// If a barcode has been search, let's add it to the order
this.perform_search = function(category, query, buy_result){
// redefine odoo/addons/point_of_sale/static/src/js/screens.js to fit need
var products;
if(query){
// let's prepare query string to find out whether it corresponds to a product barcode
let significant_string = query.replace(/[^0-9]/g, '')
if (significant_string.length > 13) {
// The last scanned barcode is the last 13 figures
significant_string = significant_string.substring(significant_string.length - 13)
}
if (significant_string.length >= 8) {
// A minimum 8 characters long figures string has been extracted : let's add corresponding product if possible
const scan_result = this.pos.barcode_reader.barcode_parser.parse_barcode(significant_string)
significant_string = scan_result.base_code
var found_product;
found_product = this.pos.db.get_product_by_barcode(significant_string)
if (found_product) {
this.pos.scan_product(scan_result) // scan_result contain eventually weight quantity or other encodeded data
this.clear_search();
$('.searchbox input').blur();
}
} else {
products = this.pos.db.search_product_in_category(category.id,query);
if(buy_result && products.length === 1){
this.pos.get_order().add_product(products[0]);
this.clear_search();
}else{
this.product_list_widget.set_product_list(products);
}
}
}else{
products = this.pos.db.get_product_by_category(this.category.id);
this.product_list_widget.set_product_list(products);
}
}
} }
}) })
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment