[MERGE] return picking
bzr revid: qdp-launchpad@openerp.com-20130807092433-jjhbd4va2cyrp7rs
This commit is contained in:
@@ -514,8 +514,7 @@ class stock_picking(osv.osv):
|
||||
picking_obj = self.browse(cr, uid, id, context=context)
|
||||
if ('name' not in default) or (picking_obj.name == '/'):
|
||||
default['name'] = '/'
|
||||
default['origin'] = ''
|
||||
default['backorder_id'] = False
|
||||
default['backorder_id'] = False
|
||||
return super(stock_picking, self).copy(cr, uid, id, default, context)
|
||||
|
||||
def action_confirm(self, cr, uid, ids, context=None):
|
||||
@@ -977,6 +976,8 @@ class stock_move(osv.osv):
|
||||
'picking_type_id': fields.many2one('stock.picking.type', 'Picking Type'),
|
||||
'inventory_id': fields.many2one('stock.inventory', 'Inventory'),
|
||||
'lot_ids': fields.function(_get_lot_ids, type='many2many', relation='stock.quant', string='Lots'),
|
||||
'origin_returned_move_id': fields.many2one('stock.move', 'Origin return move', help='move that created the return move'),
|
||||
'returned_move_ids': fields.one2many('stock.move', 'origin_returned_move_id', 'All returned moves', help='Optional: all returned moves created from this move'),
|
||||
}
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
@@ -986,6 +987,8 @@ class stock_move(osv.osv):
|
||||
default['move_orig_ids'] = []
|
||||
default['quant_ids'] = []
|
||||
default['reserved_quant_ids'] = []
|
||||
default['returned_move_ids'] = []
|
||||
default['origin_returned_move_id'] = False
|
||||
default['state'] = 'draft'
|
||||
return super(stock_move, self).copy(cr, uid, id, default, context)
|
||||
|
||||
@@ -2203,10 +2206,11 @@ class stock_picking_type(osv.osv):
|
||||
'auto_force_assign': fields.boolean('Automatic Availability', help='This picking type does\'t need to check for the availability in stock'),
|
||||
'color': fields.integer('Color Index'),
|
||||
'delivery': fields.boolean('Print delivery'),
|
||||
'sequence_id': fields.many2one('ir.sequence', 'Sequence', required = True),
|
||||
'sequence_id': fields.many2one('ir.sequence', 'Sequence', required=True),
|
||||
'default_location_src_id': fields.many2one('stock.location', 'Default Source Location'),
|
||||
'default_location_dest_id': fields.many2one('stock.location', 'Default Destination Location'),
|
||||
'code_id': fields.many2one('stock.picking.code', 'Picking type code', required = True),
|
||||
'code_id': fields.many2one('stock.picking.code', 'Picking type code', required=True),
|
||||
'return_picking_type_id': fields.many2one('stock.picking.type', 'Picking Type for Returns'),
|
||||
|
||||
# Statistics for the kanban view
|
||||
'weekly_picking': fields.function(_get_picking_data,
|
||||
|
||||
@@ -1210,6 +1210,7 @@
|
||||
<group>
|
||||
<field name="default_location_src_id"/>
|
||||
<field name="default_location_dest_id"/>
|
||||
<field name="return_picking_type_id"/>
|
||||
</group>
|
||||
</form>
|
||||
</field>
|
||||
|
||||
@@ -21,31 +21,28 @@
|
||||
|
||||
import time
|
||||
|
||||
from openerp.osv import osv,fields
|
||||
from openerp.osv import osv, fields
|
||||
from openerp.tools.translate import _
|
||||
import openerp.addons.decimal_precision as dp
|
||||
|
||||
class stock_return_picking_memory(osv.osv_memory):
|
||||
_name = "stock.return.picking.memory"
|
||||
class stock_return_picking_line(osv.osv_memory):
|
||||
_name = "stock.return.picking.line"
|
||||
_rec_name = 'product_id'
|
||||
|
||||
_columns = {
|
||||
'product_id' : fields.many2one('product.product', string="Product", required=True),
|
||||
'quantity' : fields.float("Quantity", digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
|
||||
'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"),
|
||||
'move_id' : fields.many2one('stock.move', "Move"),
|
||||
'lot_id': fields.related('move_id', 'lot_id', type='many2one', relation='stock.production.lot', string='Serial Number', readonly=True),
|
||||
|
||||
'product_id': fields.many2one('product.product', string="Product", required=True),
|
||||
'quantity': fields.float("Quantity", digits_compute=dp.get_precision('Product Unit of Measure'), required=True),
|
||||
'wizard_id': fields.many2one('stock.return.picking', string="Wizard"),
|
||||
'move_id': fields.many2one('stock.move', "Move"),
|
||||
'lot_id': fields.related('move_id', 'quant_ids', 'lot_id', type="many2one", relation='stock.production.lot', string='Serial Number', readonly=True),
|
||||
}
|
||||
|
||||
|
||||
|
||||
class stock_return_picking(osv.osv_memory):
|
||||
_name = 'stock.return.picking'
|
||||
_description = 'Return Picking'
|
||||
_columns = {
|
||||
'product_return_moves' : fields.one2many('stock.return.picking.memory', 'wizard_id', 'Moves'),
|
||||
'invoice_state': fields.selection([('2binvoiced', 'To be refunded/invoiced'), ('none', 'No invoicing')], 'Invoicing',required=True),
|
||||
'product_return_moves': fields.one2many('stock.return.picking.line', 'wizard_id', 'Moves'),
|
||||
}
|
||||
|
||||
def default_get(self, cr, uid, fields, context=None):
|
||||
@@ -66,75 +63,25 @@ class stock_return_picking(osv.osv_memory):
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
if pick:
|
||||
if 'invoice_state' in fields:
|
||||
if pick.invoice_state=='invoiced':
|
||||
res.update({'invoice_state': '2binvoiced'})
|
||||
else:
|
||||
res.update({'invoice_state': 'none'})
|
||||
return_history = self.get_return_history(cr, uid, record_id, context)
|
||||
if pick.state != 'done':
|
||||
raise osv.except_osv(_('Warning!'), _("You may only return pickings that are Done!"))
|
||||
for line in pick.move_lines:
|
||||
qty = line.product_uom_qty - return_history.get(line.id, 0)
|
||||
qty = line.product_qty
|
||||
if line.returned_move_ids:
|
||||
for returned_move in line.returned_move_ids:
|
||||
if returned_move.product_id.id == line.product_id.id:
|
||||
qty -= returned_move.product_qty
|
||||
|
||||
if qty > 0:
|
||||
result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id, 'lot_id': line.lot_id and line.lot_id.id or False})
|
||||
result1.append({'product_id': line.product_id.id, 'quantity': qty, 'move_id': line.id})
|
||||
if len(result1) == 0:
|
||||
raise osv.except_osv(_('Warning!'), _("No products to return (only lines in Done state and not fully returned yet can be returned)!"))
|
||||
if 'product_return_moves' in fields:
|
||||
res.update({'product_return_moves': result1})
|
||||
return res
|
||||
|
||||
def view_init(self, cr, uid, fields_list, context=None):
|
||||
"""
|
||||
Creates view dynamically and adding fields at runtime.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param context: A standard dictionary
|
||||
@return: New arch of view with new columns.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
res = super(stock_return_picking, self).view_init(cr, uid, fields_list, context=context)
|
||||
record_id = context and context.get('active_id', False)
|
||||
if record_id:
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
if pick.state not in ['done','confirmed','assigned']:
|
||||
raise osv.except_osv(_('Warning!'), _("You may only return pickings that are Confirmed, Available or Done!"))
|
||||
valid_lines = 0
|
||||
return_history = self.get_return_history(cr, uid, record_id, context)
|
||||
for m in pick.move_lines:
|
||||
if m.state == 'done' and m.product_uom_qty * m.product_uom.factor > return_history.get(m.id, 0):
|
||||
valid_lines += 1
|
||||
if not valid_lines:
|
||||
raise osv.except_osv(_('Warning!'), _("No products to return (only lines in Done state and not fully returned yet can be returned)!"))
|
||||
return res
|
||||
|
||||
def get_return_history(self, cr, uid, pick_id, context=None):
|
||||
"""
|
||||
Get return_history.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@param uid: ID of the user currently logged in
|
||||
@param pick_id: Picking id
|
||||
@param context: A standard dictionary
|
||||
@return: A dictionary which of values.
|
||||
"""
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
pick = pick_obj.browse(cr, uid, pick_id, context=context)
|
||||
return_history = {}
|
||||
for m in pick.move_lines:
|
||||
if m.state == 'done':
|
||||
return_history[m.id] = 0
|
||||
for rec in m.move_history_ids2:
|
||||
# only take into account 'product return' moves, ignoring any other
|
||||
# kind of upstream moves, such as internal procurements, etc.
|
||||
# a valid return move will be the exact opposite of ours:
|
||||
# (src location, dest location) <=> (dest location, src 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_uom_qty * rec.product_uom.factor)
|
||||
return return_history
|
||||
|
||||
def create_returns(self, cr, uid, ids, context=None):
|
||||
"""
|
||||
"""
|
||||
Creates return picking.
|
||||
@param self: The object pointer.
|
||||
@param cr: A database cursor
|
||||
@@ -144,80 +91,60 @@ class stock_return_picking(osv.osv_memory):
|
||||
@return: A dictionary which of fields with values.
|
||||
"""
|
||||
if context is None:
|
||||
context = {}
|
||||
context = {}
|
||||
record_id = context and context.get('active_id', False) or False
|
||||
move_obj = self.pool.get('stock.move')
|
||||
pick_obj = self.pool.get('stock.picking')
|
||||
uom_obj = self.pool.get('product.uom')
|
||||
data_obj = self.pool.get('stock.return.picking.memory')
|
||||
act_obj = self.pool.get('ir.actions.act_window')
|
||||
model_obj = self.pool.get('ir.model.data')
|
||||
data_obj = self.pool.get('stock.return.picking.line')
|
||||
pick = pick_obj.browse(cr, uid, record_id, context=context)
|
||||
data = self.read(cr, uid, ids[0], context=context)
|
||||
date_cur = time.strftime('%Y-%m-%d %H:%M:%S')
|
||||
set_invoice_state_to_none = True
|
||||
returned_lines = 0
|
||||
|
||||
# Create new picking for returned products
|
||||
if pick.type =='out':
|
||||
new_type = 'in'
|
||||
elif pick.type =='in':
|
||||
new_type = 'out'
|
||||
else:
|
||||
new_type = 'internal'
|
||||
seq_obj_name = 'stock.picking.' + new_type
|
||||
new_pick_name = self.pool.get('ir.sequence').get(cr, uid, seq_obj_name)
|
||||
|
||||
#Create new picking for returned products
|
||||
pick_type_id = pick.picking_type_id.return_picking_type_id and pick.picking_type_id.return_picking_type_id.id or pick.picking_type_id.id
|
||||
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_lines': [],
|
||||
'picking_type_id': pick_type_id,
|
||||
'state': 'draft',
|
||||
'origin': pick.name,
|
||||
})
|
||||
|
||||
val_id = data['product_return_moves']
|
||||
for v in val_id:
|
||||
data_get = data_obj.browse(cr, uid, v, context=context)
|
||||
mov_id = data_get.move_id.id
|
||||
if not mov_id:
|
||||
|
||||
for data_get in data_obj.browse(cr, uid, data['product_return_moves'], context=context):
|
||||
move = data_get.move_id
|
||||
if not move:
|
||||
raise osv.except_osv(_('Warning !'), _("You have manually created product lines, please delete them to proceed"))
|
||||
new_qty = data_get.quantity
|
||||
move = move_obj.browse(cr, uid, mov_id, context=context)
|
||||
new_location = move.location_dest_id.id
|
||||
returned_qty = move.product_uom_qty
|
||||
for rec in move.move_history_ids2:
|
||||
returned_qty -= rec.product_uom_qty
|
||||
|
||||
if returned_qty != new_qty:
|
||||
set_invoice_state_to_none = False
|
||||
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,
|
||||
quant_ids = []
|
||||
for quant in move.quant_ids:
|
||||
quant_ids.append((4, quant.id))
|
||||
move_obj.copy(cr, uid, move.id, {
|
||||
'product_id': data_get.product_id.id,
|
||||
'product_uom_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': move.location_dest_id.id,
|
||||
'location_dest_id': move.location_id.id,
|
||||
'reserved_quant_ids': quant_ids,
|
||||
'origin_returned_move_id': move.id,
|
||||
})
|
||||
move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]}, context=context)
|
||||
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'}, context=context)
|
||||
pick_obj.signal_button_confirm(cr, uid, [new_picking])
|
||||
pick_obj.action_confirm(cr, uid, [new_picking], context=context)
|
||||
pick_obj.force_assign(cr, uid, [new_picking], context)
|
||||
ctx = {'default_picking_type_id': pick_type_id}
|
||||
return {
|
||||
'domain': "[('id', 'in', ["+str(new_picking)+"])]",
|
||||
'domain': "[('id', 'in', [" + str(new_picking) + "])]",
|
||||
'name': _('Returned Picking'),
|
||||
'view_type':'form',
|
||||
'view_mode':'tree,form',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'tree,form',
|
||||
'res_model': 'stock.picking',
|
||||
'type':'ir.actions.act_window',
|
||||
'context':context,
|
||||
'type': 'ir.actions.act_window',
|
||||
'context': ctx, # TODO: fix a bug here: the context is not the given one, but the one from the initial action (still searching on old picking type when the new picking type can be different!)
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,26 +9,10 @@
|
||||
key2="client_action_multi"
|
||||
multi="True"
|
||||
id="act_stock_return_picking"/>
|
||||
<act_window name="Return Shipment"
|
||||
res_model="stock.return.picking"
|
||||
src_model="stock.picking"
|
||||
view_mode="form"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
multi="True"
|
||||
id="act_stock_return_picking_in"/>
|
||||
<act_window name="Return Shipment"
|
||||
res_model="stock.return.picking"
|
||||
src_model="stock.picking"
|
||||
view_mode="form"
|
||||
target="new"
|
||||
key2="client_action_multi"
|
||||
multi="True"
|
||||
id="act_stock_return_picking_out"/>
|
||||
|
||||
<record id="stock_return_memory_tree_in" model="ir.ui.view">
|
||||
<field name="name">stock.return.picking.memory.tree</field>
|
||||
<field name="model">stock.return.picking.memory</field>
|
||||
<record id="stock_return_line_tree_in" model="ir.ui.view">
|
||||
<field name="name">stock.return.picking.line.tree</field>
|
||||
<field name="model">stock.return.picking.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree editable="bottom" string="Product Moves">
|
||||
<field name="product_id" />
|
||||
@@ -38,9 +22,9 @@
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="stock_return_memory_form_in" model="ir.ui.view">
|
||||
<field name="name">stock.return.picking.memory.from</field>
|
||||
<field name="model">stock.return.picking.memory</field>
|
||||
<record id="stock_return_line_form_in" model="ir.ui.view">
|
||||
<field name="name">stock.return.picking.line.from</field>
|
||||
<field name="model">stock.return.picking.line</field>
|
||||
<field name="arch" type="xml">
|
||||
<form string="Return Picking Memory" version="7.0">
|
||||
<group col="4">
|
||||
@@ -60,7 +44,6 @@
|
||||
<label string="Provide the quantities of the returned products."/>
|
||||
<group>
|
||||
<field name="product_return_moves"/>
|
||||
<field name="invoice_state" />
|
||||
</group>
|
||||
<footer>
|
||||
<button name="create_returns" string="Return" type="object" class="oe_highlight"/>
|
||||
@@ -70,6 +53,7 @@
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
|
||||
</data>
|
||||
</openerp>
|
||||
|
||||
Reference in New Issue
Block a user