[IMP] stock.picking return wizard: properly use uom + correct validation
bzr revid: odo@openerp.com-20100928172547-ngdqyn7g0etdz0u4
This commit is contained in:
@@ -69,15 +69,23 @@ class stock_return_picking(osv.osv_memory):
|
||||
if record_id:
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id)
|
||||
if pick.state not in ['done','confirmed','assigned']:
|
||||
raise osv.except_osv(_('Warning !'), _("You may only return pickings that are Confirmed, Available or Done!"))
|
||||
return_history = {}
|
||||
valid_lines = 0
|
||||
for m in [line for line in pick.move_lines]:
|
||||
if m.state=='done':
|
||||
if 'return%s'%(m.id) not in self._columns:
|
||||
self._columns['return%s'%(m.id)] = fields.float(string=m.name, required=True)
|
||||
if 'invoice_state' not in self._columns:
|
||||
self._columns['invoice_state'] = fields.selection([('2binvoiced', 'To be Invoiced'), ('none', 'None')], string='Invoice State', required=True)
|
||||
for rec in m.move_history_ids2:
|
||||
if rec.product_qty==m.product_qty:
|
||||
raise osv.except_osv(_('Warning !'), _("There is no product to return!"))
|
||||
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)
|
||||
if m.product_qty * m.product_uom.factor > return_history[m.id]:
|
||||
valid_lines += 1
|
||||
if 'return%s'%(m.id) not in self._columns:
|
||||
self._columns['return%s'%(m.id)] = fields.float(string=m.name, required=True)
|
||||
if 'invoice_state' not in self._columns:
|
||||
self._columns['invoice_state'] = fields.selection([('2binvoiced', 'To be Invoiced'), ('none', 'None')], string='Invoice State', required=True)
|
||||
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)!"))
|
||||
return res
|
||||
|
||||
def fields_view_get(self, cr, uid, view_id=None, view_type='form',
|
||||
@@ -98,16 +106,13 @@ class stock_return_picking(osv.osv_memory):
|
||||
if record_id:
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id)
|
||||
if pick.state not in['done','confirmed']:
|
||||
raise osv.except_osv(_('Warning !'), _("The Picking is not completed yet!\nYou cannot return picking which is not in 'Done' state!"))
|
||||
return_history = {}
|
||||
for m_line in pick.move_lines:
|
||||
return_history[m_line.id] = 0
|
||||
for rec in m_line.move_history_ids2:
|
||||
return_history[m_line.id] += rec.product_qty
|
||||
res['fields'].clear()
|
||||
arch_lst=['<?xml version="1.0"?>', '<form string="%s">' % _('Return lines'), '<label string="%s" colspan="4"/>' % _('Provide the quantities of the returned products.')]
|
||||
for m in [line for line in pick.move_lines]:
|
||||
for m in pick.move_lines:
|
||||
return_history[m.id] = 0
|
||||
for rec in m.move_history_ids2:
|
||||
return_history[m.id] += rec.product_qty
|
||||
quantity = m.product_qty
|
||||
if m.state=='done' and quantity > return_history[m.id]:
|
||||
arch_lst.append('<field name="return%s"/>\n<newline/>' % (m.id,))
|
||||
@@ -146,6 +151,7 @@ class stock_return_picking(osv.osv_memory):
|
||||
|
||||
move_ids = [m.id for m in [line for line in pick.move_lines]]
|
||||
set_invoice_state_to_none = True
|
||||
returned_lines = 0
|
||||
for move in move_obj.browse(cr, uid, move_ids):
|
||||
if not new_picking:
|
||||
if pick.type=='out':
|
||||
@@ -167,34 +173,36 @@ class stock_return_picking(osv.osv_memory):
|
||||
|
||||
if returned_qty != new_qty:
|
||||
set_invoice_state_to_none = False
|
||||
|
||||
new_move=move_obj.copy(cr, uid, move.id, {
|
||||
'product_qty': new_qty,
|
||||
'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
|
||||
new_qty, move.product_uos.id),
|
||||
'picking_id':new_picking, 'state':'draft',
|
||||
'location_id':new_location, 'location_dest_id':move.location_id.id,
|
||||
'date':date_cur,})
|
||||
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
|
||||
|
||||
|
||||
if new_qty:
|
||||
returned_lines += 1
|
||||
new_move=move_obj.copy(cr, uid, move.id, {
|
||||
'product_qty': new_qty,
|
||||
'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
|
||||
new_qty, move.product_uos.id),
|
||||
'picking_id':new_picking, 'state':'draft',
|
||||
'location_id':new_location, 'location_dest_id':move.location_id.id,
|
||||
'date':date_cur,})
|
||||
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
|
||||
|
||||
if not returned_lines:
|
||||
raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!"))
|
||||
|
||||
if set_invoice_state_to_none:
|
||||
pick_obj.write(cr, uid, [pick.id], {'invoice_state':'none'})
|
||||
if new_picking:
|
||||
if new_picking:
|
||||
wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)
|
||||
pick_obj.force_assign(cr, uid, [new_picking], context)
|
||||
return {
|
||||
'domain': "[('id', 'in', ["+str(new_picking)+"])]",
|
||||
'name': 'Picking List',
|
||||
'view_type':'form',
|
||||
'view_mode':'tree,form',
|
||||
'res_model':'stock.picking',
|
||||
'view_id':False,
|
||||
'type':'ir.actions.act_window',
|
||||
'context':context,
|
||||
}
|
||||
return {}
|
||||
|
||||
wf_service.trg_validate(uid, 'stock.picking', new_picking, 'button_confirm', cr)
|
||||
pick_obj.force_assign(cr, uid, [new_picking], context)
|
||||
return {
|
||||
'domain': "[('id', 'in', ["+str(new_picking)+"])]",
|
||||
'name': 'Picking List',
|
||||
'view_type':'form',
|
||||
'view_mode':'tree,form',
|
||||
'res_model':'stock.picking',
|
||||
'view_id':False,
|
||||
'type':'ir.actions.act_window',
|
||||
'context':context,
|
||||
}
|
||||
|
||||
stock_return_picking()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
Reference in New Issue
Block a user