[IMP] stock: completing a bit of the packages methods
bzr revid: qdp-launchpad@openerp.com-20130624154018-s0dkx0k1eofjwkqv
This commit is contained in:
parent
31ae5c4058
commit
388e82dbe5
|
@ -3650,6 +3650,37 @@ class stock_pack_operation(osv.osv):
|
|||
pass
|
||||
#return {'warnings': '', 'stock_move_to_update': [{}], 'package_to_update': [{}]}
|
||||
|
||||
def get_barcode_and_return_todo_stuff(self, barcode_str):
|
||||
return {'warnings': 'You shall not pass!', 'stock_move_to_update': [{'id': 1, 'remaining_qty': 0}], 'package_to_update': [{}]}
|
||||
def _search_and_increment(self, cr, uid, picking_id, key, context=None):
|
||||
'''Search for an operation on an existing key in a picking, if it exists increment the qty (+1) otherwise create it
|
||||
|
||||
:param key: tuple directly reusable in a domain
|
||||
'''
|
||||
|
||||
existing_operation_ids = self.search(cr, uid, [('picking_id', '=', picking_id), key], context=context)
|
||||
if existing_operation_ids:
|
||||
#existing operation found for the given key and picking => increment its quantity
|
||||
qty = self.browse(cr, uid, existing_operation_ids[0], context=context).product_qty
|
||||
return self.write(cr, uid, existing_operation_ids[0], {'product_qty': qty + 1}, context=context)
|
||||
#no existing operation found for the given key and picking => create a new one
|
||||
var_name, dummy, value = key
|
||||
return self.create(cr, uid, {
|
||||
'picking_id': picking_id,
|
||||
var_name: value,
|
||||
'product_qty': 1,
|
||||
}, context=context)
|
||||
|
||||
def get_barcode_and_return_todo_stuff(self, cr, uid, picking_id, barcode_str, context=None):
|
||||
'''This function is called each time there barcode scanner reads an input'''
|
||||
error_msg = ''
|
||||
sample_struct = {'warnings': 'You shall not pass!', 'stock_move_to_update': [{'id': 1, 'remaining_qty': 0}], 'package_to_update': [{}]}
|
||||
return sample_struct
|
||||
matching_quant_ids = self.pool.get('stock.quant').search(cr, uid, [('name', '=', barcode_str)], context=context)
|
||||
if matching_quant_ids:
|
||||
self._search_and_increment(cr, uid, picking_id, ('quant_id', '=', matching_quant_ids[0]), context=context)
|
||||
matching_product_ids = self.pool.get('product.product').search(cr, uid, ['|', ('code', '=', barcode_str), ('ean', '=', barcode_str)], context=context)
|
||||
if matching_product_ids:
|
||||
if len(matching_product_ids) > 1:
|
||||
error_msg = _('Wrong bar code detected: more than one product matching the given barcode')
|
||||
self.search_and_increment(cr, uid, picking_id, ('product_id', '=', matching_product_ids[0]), context=context)
|
||||
return {'warnings': error_msg, 'stock_move_to_update': [{}], 'package_to_update': [{}]}
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
Loading…
Reference in New Issue