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; |
||||
|
}); |
Loading…
Reference in new issue