5 changed files with 136 additions and 77 deletions
@ -0,0 +1,11 @@ |
|||
//@odoo-module
|
|||
import { PosGlobalState} from 'point_of_sale.models'; |
|||
import Registries from 'point_of_sale.Registries'; |
|||
const StockLotGlobalState = (PosGlobalState) => class StockLotGlobalState extends PosGlobalState { |
|||
async _processData(loadedData) { |
|||
await super._processData(...arguments); |
|||
this.db.product_by_lot = loadedData['multi.barcode.products']; |
|||
this.db.product_by_lot_id = loadedData['multi_barcode'] |
|||
} |
|||
} |
|||
Registries.Model.extend(PosGlobalState, StockLotGlobalState); |
@ -0,0 +1,38 @@ |
|||
odoo.define('pos_product_search_by_ref.product_product', function (require) { |
|||
'use strict'; |
|||
const DB = require('point_of_sale.DB'); |
|||
var core = require('web.core'); |
|||
var utils = require('web.utils'); |
|||
DB.include({ |
|||
search_product_in_category: function(category_id, query){ |
|||
var old_query = query |
|||
try { |
|||
query = query.replace(/[\[\]\(\)\+\*\?\.\-\!\&\^\$\|\~\_\{\}\:\,\\\/]/g,'.'); |
|||
query = query.replace(/ /g,'.+'); |
|||
var re = RegExp("([0-9]+):.*?"+utils.unaccent(query),"gi"); |
|||
}catch(_e){ |
|||
return []; |
|||
} |
|||
var results = []; |
|||
for(var i = 0; i < this.limit; i++){ |
|||
var r = re.exec(this.category_search_string[category_id]); |
|||
if(r){ |
|||
var id = Number(r[1]); |
|||
const product = this.get_product_by_id(id); |
|||
if (!(product.active && product.available_in_pos)) continue; |
|||
results.push(product); |
|||
}else if(this.product_by_lot_id[old_query]){ |
|||
const product = this.get_product_by_id(this.product_by_lot_id[old_query]); |
|||
if (!(product.active && product.available_in_pos)) continue; |
|||
if(!results.includes(product)){ |
|||
results.push(product); |
|||
} |
|||
}else{ |
|||
break; |
|||
} |
|||
} |
|||
return results; |
|||
} |
|||
}) |
|||
return DB; |
|||
}); |
@ -1,73 +1,73 @@ |
|||
odoo.define('multi_barcodes_pos.product', function (require) { |
|||
odoo.define('multi_barcodes_pos.product', function(require) { |
|||
"use strict"; |
|||
var rpc = require('web.rpc'); |
|||
var models = require('point_of_sale.models'); |
|||
var DB = require('point_of_sale.DB'); |
|||
var utils = require('web.utils'); |
|||
var rpc = require('web.rpc'); |
|||
var models = require('point_of_sale.models'); |
|||
var DB = require('point_of_sale.DB'); |
|||
var utils = require('web.utils'); |
|||
|
|||
const Registries = require('point_of_sale.Registries'); |
|||
const Registries = require('point_of_sale.Registries'); |
|||
|
|||
DB.include({ |
|||
DB.include({ |
|||
|
|||
init: function(options){ |
|||
this._super.apply(this, arguments); |
|||
}, |
|||
add_products: function(products){ |
|||
var stored_categories = this.product_by_category_id; |
|||
if(!products instanceof Array){ |
|||
products = [products]; |
|||
} |
|||
for(var i = 0, len = products.length; i < len; i++){ |
|||
var product = products[i]; |
|||
if (product.id in this.product_by_id) continue; |
|||
if (product.available_in_pos){ |
|||
var search_string = utils.unaccent(this._product_search_string(product)); |
|||
var categ_id = product.pos_categ_id ? product.pos_categ_id[0] : this.root_category_id; |
|||
product.product_tmpl_id = product.product_tmpl_id[0]; |
|||
if(!stored_categories[categ_id]){ |
|||
stored_categories[categ_id] = []; |
|||
} |
|||
stored_categories[categ_id].push(product.id); |
|||
init: function(options) { |
|||
this._super.apply(this, arguments); |
|||
}, |
|||
add_products: function(products) { |
|||
var stored_categories = this.product_by_category_id; |
|||
if (!products instanceof Array) { |
|||
products = [products]; |
|||
} |
|||
// console.log(products.length)
|
|||
for (var i = 0, len = products.length; i < len; i++) { |
|||
var product = products[i]; |
|||
// console.log(product)
|
|||
if (product.id in this.product_by_id) continue; |
|||
if (product.available_in_pos) { |
|||
var search_string = utils.unaccent(this._product_search_string(product)); |
|||
var categ_id = product.pos_categ_id ? product.pos_categ_id[0] : this.root_category_id; |
|||
product.product_tmpl_id = product.product_tmpl_id[0]; |
|||
if (!stored_categories[categ_id]) { |
|||
stored_categories[categ_id] = []; |
|||
} |
|||
stored_categories[categ_id].push(product.id); |
|||
|
|||
if(this.category_search_string[categ_id] === undefined){ |
|||
this.category_search_string[categ_id] = ''; |
|||
} |
|||
this.category_search_string[categ_id] += search_string; |
|||
if (this.category_search_string[categ_id] === undefined) { |
|||
this.category_search_string[categ_id] = ''; |
|||
} |
|||
this.category_search_string[categ_id] += search_string; |
|||
|
|||
var ancestors = this.get_category_ancestors_ids(categ_id) || []; |
|||
var ancestors = this.get_category_ancestors_ids(categ_id) || []; |
|||
|
|||
for(var j = 0, jlen = ancestors.length; j < jlen; j++){ |
|||
var ancestor = ancestors[j]; |
|||
if(! stored_categories[ancestor]){ |
|||
stored_categories[ancestor] = []; |
|||
} |
|||
stored_categories[ancestor].push(product.id); |
|||
for (var j = 0, jlen = ancestors.length; j < jlen; j++) { |
|||
var ancestor = ancestors[j]; |
|||
if (!stored_categories[ancestor]) { |
|||
stored_categories[ancestor] = []; |
|||
} |
|||
stored_categories[ancestor].push(product.id); |
|||
|
|||
if( this.category_search_string[ancestor] === undefined){ |
|||
this.category_search_string[ancestor] = ''; |
|||
if (this.category_search_string[ancestor] === undefined) { |
|||
this.category_search_string[ancestor] = ''; |
|||
} |
|||
this.category_search_string[ancestor] += search_string; |
|||
} |
|||
this.category_search_string[ancestor] += search_string; |
|||
} |
|||
} |
|||
this.product_by_id[product.id] = product; |
|||
if(product.barcode){ |
|||
this.product_by_barcode[product.barcode] = product; |
|||
} |
|||
|
|||
for(var t=0;t < product.product_multi_barcodes.length;t++){ |
|||
var self = this; |
|||
rpc.query({ |
|||
model: 'multi.barcode.products', |
|||
method: 'get_barcode_val', |
|||
args: [product.product_multi_barcodes[t], product.id], |
|||
}).then(function (barcode_val) { |
|||
this.product_by_id[product.id] = product; |
|||
if (product.barcode) { |
|||
this.product_by_barcode[product.barcode] = product; |
|||
} |
|||
for (var t = 0; t < product.product_multi_barcodes.length; t++) { |
|||
var self = this; |
|||
rpc.query({ |
|||
model: 'multi.barcode.products', |
|||
method: 'get_barcode_val', |
|||
args: [product.product_multi_barcodes[t], product.id], |
|||
}).then(function(barcode_val) { |
|||
self.product_by_barcode[barcode_val[0]] = self.product_by_id[barcode_val[1]]; |
|||
}); |
|||
} |
|||
|
|||
self.product_by_barcode[barcode_val[0]] = self.product_by_id[barcode_val[1]]; |
|||
}); |
|||
} |
|||
|
|||
} |
|||
}, |
|||
}, |
|||
}); |
|||
|
|||
}); |
|||
}); |
Loading…
Reference in new issue