From a2bf8d640c35760b531fdb9ec2af70fda5a83134 Mon Sep 17 00:00:00 2001 From: Cedric Snauwaert Date: Fri, 7 Mar 2014 17:37:47 +0100 Subject: [PATCH] [WIP]barcode interface, add a barcode to location and allow the use of scanner to filter by location bzr revid: csn@openerp.com-20140307163747-cua6u44t6u6r8juh --- addons/stock/static/src/js/widgets.js | 29 +++++++++++++------------ addons/stock/static/src/xml/picking.xml | 2 +- addons/stock/stock.py | 15 +++++++++++++ addons/stock/stock_view.xml | 1 + 4 files changed, 32 insertions(+), 15 deletions(-) diff --git a/addons/stock/static/src/js/widgets.js b/addons/stock/static/src/js/widgets.js index 7e347b4b466..8b28550bfb2 100644 --- a/addons/stock/static/src/js/widgets.js +++ b/addons/stock/static/src/js/widgets.js @@ -219,7 +219,6 @@ function openerp_picking_widgets(instance){ this.pickings_by_type = {}; this.pickings_by_id = {}; this.picking_search_string = ""; - }, load: function(){ var self = this; @@ -574,9 +573,21 @@ function openerp_picking_widgets(instance){ var self = this; new instance.web.Model('stock.picking') .call('process_barcode_from_ui', [self.picking.id, ean]) - .then(function(){ - self.reset_selected_operation(); - return self.refresh_ui(self.picking.id); + .then(function(result){ + if (typeof(result)!="boolean"){ + //check if we have receive a location as answer + if (result.filter_loc !== undefined){ + self.$('.oe_searchbox').val(result.filter_loc); + self.on_searchbox(result.filter_loc); + } + } + else{ + return self.refresh_ui(self.picking.id); + //TODO add a then to highlight the line that was scanned, do same to scan_product_id + // .then(function(product_id){ + // self. + // }); + } }); }, scan_product_id: function(product_id){ //performs the same operation as a scan, but with product id instead @@ -584,7 +595,6 @@ function openerp_picking_widgets(instance){ new instance.web.Model('stock.picking') .call('process_product_id_from_ui', [self.picking.id, product_id]) .then(function(){ - self.reset_selected_operation(); return self.refresh_ui(self.picking.id); }); }, @@ -730,15 +740,6 @@ function openerp_picking_widgets(instance){ return null; } }, - reset_selected_operation: function(){ - if(this.selected_operation.picking_id === this.picking.id){ - this.selected_operation.id = null; - } - }, - set_selected_operation: function(id){ - this.selected_operation.picking_id = this.picking.id; - this.selected_operation.id = id; - }, set_operation_quantity: function(quantity){ var self = this; var op = this.get_selected_operation(); diff --git a/addons/stock/static/src/xml/picking.xml b/addons/stock/static/src/xml/picking.xml index 65c671641b6..8303f8c0363 100644 --- a/addons/stock/static/src/xml/picking.xml +++ b/addons/stock/static/src/xml/picking.xml @@ -64,7 +64,7 @@ - ➔ + ➔ / : diff --git a/addons/stock/stock.py b/addons/stock/stock.py index 82879e88f4c..4516b99b288 100644 --- a/addons/stock/stock.py +++ b/addons/stock/stock.py @@ -127,6 +127,7 @@ class stock_location(osv.osv): 'scrap_location': fields.boolean('Is a Scrap Location?', help='Check this box to allow using this location to put scrapped/damaged goods.'), 'removal_strategy_ids': fields.one2many('product.removal', 'location_id', 'Removal Strategies'), 'putaway_strategy_ids': fields.one2many('product.putaway', 'location_id', 'Put Away Strategies'), + 'loc_barcode': fields.char('Location barcode'), } _defaults = { 'active': True, @@ -137,6 +138,12 @@ class stock_location(osv.osv): 'posz': 0, 'scrap_location': False, } + _sql_constraints = [('loc_barcode_company_uniq', 'unique (loc_barcode,company_id)', 'The barcode for a location must be unique per company !')] + + def create(self, cr, uid, default, context=None): + if not default.get('loc_barcode', False): + default.update({'loc_barcode': default.get('complete_name', False)}) + return super(stock_location,self).create(cr, uid, default, context=context) def get_putaway_strategy(self, cr, uid, location, product, context=None): pa = self.pool.get('product.putaway') @@ -1255,6 +1262,13 @@ class stock_picking(osv.osv): package_obj = self.pool.get('stock.quant.package') product_obj = self.pool.get('product.product') stock_operation_obj = self.pool.get('stock.pack.operation') + stock_location_obj = self.pool.get('stock.location') + #check if the barcode correspond to a location + matching_location_ids = stock_location_obj.search(cr, uid, [('loc_barcode', '=', barcode_str)], context=context) + if matching_location_ids: + #if we have a location, return immediatly with the location name + location = stock_location_obj.browse(cr, uid, matching_location_ids[0], context=None) + return {'filter_loc': stock_location_obj._name_get(cr, uid, location, context=None)} #check if the barcode correspond to a product matching_product_ids = product_obj.search(cr, uid, ['|', ('ean13', '=', barcode_str), ('default_code', '=', barcode_str)], context=context) if matching_product_ids: @@ -1271,6 +1285,7 @@ class stock_picking(osv.osv): if matching_package_ids: stock_operation_obj._search_and_increment(cr, uid, picking_id, [('package_id', '=', matching_package_ids[0])], context=context) + return False class stock_production_lot(osv.osv): _name = 'stock.production.lot' diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml index ffa3d6d7f54..2112451df42 100644 --- a/addons/stock/stock_view.xml +++ b/addons/stock/stock_view.xml @@ -375,6 +375,7 @@ +