- #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)
- answer['filter_loc'] = stock_location_obj._name_get(cr, uid, location, context=None)
- answer['filter_loc_id'] = matching_location_ids[0]
- return answer
- #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:
- op_id = stock_operation_obj._search_and_increment(cr, uid, picking_id, [('product_id', '=', matching_product_ids[0])], filter_visible=True, visible_op_ids=visible_op_ids, increment=True, context=context)
- answer['operation_id'] = op_id
- return answer
+
+ # Barcode Nomenclatures
+ picking_type_id = self.browse(cr, uid, [picking_id], context=context).picking_type_id.id
+ barcode_nom = self.pool.get('stock.picking.type').browse(cr, uid, [picking_type_id], context=context).barcode_nomenclature_id
+ parsed_result = barcode_nom.parse_barcode(barcode_str)
+
+ #check if the barcode is a weighted barcode or simply a product
+ if parsed_result['type'] in ['weight', 'product', 'package']:
+ weight=1
+ if parsed_result['type'] == 'weight':
+ domain = ['|', ('barcode', '=', parsed_result['base_code']), ('default_code', '=', parsed_result['base_code'])]
+ weight=parsed_result['value']
+ obj = self.pool.get('product.product')
+ id_in_operation = 'product_id'
+ elif parsed_result['type'] == 'product':
+ domain = ['|', ('barcode', '=', parsed_result['code']), ('default_code', '=', parsed_result['code'])]
+ obj = self.pool.get('product.product')
+ id_in_operation = 'product_id'
+ else:
+ domain = [('name', '=', parsed_result['code'])]
+ obj = self.pool.get('stock.quant.package')
+ id_in_operation = 'package_id'
+
+ matching_product_ids = obj.search(cr, uid, domain, context=context)
+ if matching_product_ids:
+ op_id = stock_operation_obj._search_and_increment(cr, uid, picking_id, [(id_in_operation, '=', matching_product_ids[0])], filter_visible=True, visible_op_ids=visible_op_ids, increment=weight, context=context)
+ answer['operation_id'] = op_id
+ return answer
+