valid_lines = 0
return_history = self.get_return_history(cr, uid, record_id, context)
for m in pick.move_lines:
- if (return_history.get(m.id) == 0) and (m.product_qty * m.product_uom.factor > return_history[m.id]):
+ if (return_history.get(m.id) is not None) and (m.product_qty * m.product_uom.factor > return_history[m.id]):
valid_lines += 1
if not valid_lines:
raise osv.except_osv(_('Warning !'), _("There are no products to return (only lines in Done state and not fully returned yet can be returned)!"))
if m.state == 'done':
return_history[m.id] = 0
for rec in m.move_history_ids2:
- return_history[m.id] += (rec.product_qty * rec.product_uom.factor)
+ # only take into account 'product return' stock move
+ # (i.e move with exact opposite of ours:
+ # (location, dest location) = (dest location, location))
+ if rec.location_dest_id.id == m.location_id.id \
+ and rec.location_id.id == m.location_dest_id.id:
+ return_history[m.id] += (rec.product_qty * rec.product_uom.factor)
return return_history
def create_returns(self, cr, uid, ids, context=None):
new_type = 'out'
else:
new_type = 'internal'
- new_picking = pick_obj.copy(cr, uid, pick.id, {'name':'%s-return' % pick.name,
+ seq_obj_name = 'stock.picking.' + new_type
+ new_pick_name = self.pool.get('ir.sequence').get(cr, uid, seq_obj_name)
+ new_picking = pick_obj.copy(cr, uid, pick.id, {'name':'%s-%s-return' % (new_pick_name, pick.name),
'move_lines':[], 'state':'draft', 'type':new_type,
'date':date_cur, 'invoice_state':data['invoice_state'],})
move = move_obj.browse(cr, uid, mov_id, context=context)
new_location = move.location_dest_id.id
returned_qty = move.product_qty
+ if new_qty > returned_qty:
+ precision = self.pool.get('decimal.precision').precision_get(cr, uid, 'Product UoM')
+ raise osv.except_osv(_('Returning Error'),
+ _('Returning quantity %.*f for %s is larger than the available quantity %.*f!')\
+ % (precision, new_qty, move.product_id.name, precision, returned_qty))
for rec in move.move_history_ids2:
returned_qty -= rec.product_qty