[IMP] picking.do_partial() can be postponed + some fixes

bzr revid: qdp-launchpad@openerp.com-20130803232848-73ihxv87d1biwovs
This commit is contained in:
Quentin (OpenERP) 2013-08-04 01:28:48 +02:00
parent 9eb29913fa
commit 5baed5bc99
3 changed files with 43 additions and 29 deletions

View File

@ -586,11 +586,14 @@ class stock_picking(osv.osv):
# Methods for partial pickings
def _create_backorder(self, cr, uid, picking, context=None):
def _create_backorder(self, cr, uid, picking, backorder_moves=[], context=None):
"""
Move all non-done lines into a new backorder picking
"""
if not backorder_moves:
backorder_moves = picking.move_lines
backorder_move_ids = [x.id for x in backorder_moves if x.state not in ('done','cancel')]
backorder_id = self.copy(cr, uid, picking.id, {
'name': '/',
'move_lines': [],
@ -599,8 +602,7 @@ class stock_picking(osv.osv):
})
back_order_name = self.browse(cr, uid, backorder_id, context=context).name
self.message_post(cr, uid, picking.id, body=_("Back order <em>%s</em> <b>created</b>.") % (back_order_name), context=context)
notdone_move_ids = [x.id for x in picking.move_lines if x.state not in ('done','cancel')]
self.pool.get('stock.move').write(cr, uid, notdone_move_ids, {'picking_id': backorder_id}, context=context)
self.pool.get('stock.move').write(cr, uid, backorder_move_ids, {'picking_id': backorder_id}, context=context)
return backorder_id
def do_prepare_partial(self, cr, uid, picking_ids, context=None):
@ -608,7 +610,7 @@ class stock_picking(osv.osv):
pack_operation_obj = self.pool.get('stock.pack.operation')
for picking in self.browse(cr, uid, picking_ids, context=context):
for move in picking.move_lines:
if move.state <> 'assigned': continue
if move.state != 'assigned': continue
remaining_qty = move.product_qty
for quant in move.reserved_quant_ids:
qty = min(quant.qty, move.product_qty)
@ -637,21 +639,17 @@ class stock_picking(osv.osv):
if move.state in ('cancel','done'): continue
if move.product_id.id == product.id:
todo = min(move.product_qty, qty)
partial_datas = {
'product_qty': todo,
'product_uom_id': product.uom_id.id,
'reserved_quant_ids': quant and [(4, quant.id)] or [],
}
newmove_id = stock_move_obj.split(cr, uid, move, todo, context=context)
stock_move_obj.action_done(cr, uid, [newmove_id], context=context)
if not context.get('do_only_split'):
stock_move_obj.action_done(cr, uid, [newmove_id], context=context)
# TODO: To be removed after new API implementation
move.refresh()
moves.append(move)
qty -= todo
if qty<=0: break
if qty>0:
if qty <= 0: break
if qty > 0:
move_id = stock_move_obj.create(cr, uid, {
'name': product.name,
'product_id': product.id,
@ -660,10 +658,11 @@ class stock_picking(osv.osv):
'location_id': picking.location_id.id,
'location_dest_id': picking.location_dest_id.id,
'picking_id': picking.id,
'reserved_quant_ids': quant and [(4,quant.id)] or [],
'reserved_quant_ids': quant and [(4, quant.id)] or [],
'picking_type_id': picking.picking_type_id.id
}, context=context)
stock_move_obj.action_done(cr, uid, [move_id], context=context)
if not context.get('do_only_split'):
stock_move_obj.action_done(cr, uid, [move_id], context=context)
move = stock_move_obj.browse(cr, uid, move_id, context=context)
moves.append(move)
return moves
@ -675,6 +674,7 @@ class stock_picking(osv.osv):
"""
#TODO: this variable should be in argument
quant_obj = self.pool.get('stock.quant')
quant_package_obj = self.pool.get('stock.quant.package')
for picking in self.browse(cr, uid, picking_ids, context=context):
if not picking.pack_operation_ids:
self.action_done(cr, uid, [picking.id], context=context)
@ -699,6 +699,30 @@ class stock_picking(osv.osv):
self._create_backorder(cr, uid, picking, context=context)
return True
def do_split(self, cr, uid, picking_ids, context=None):
"""
If no pack operation, we close the whole move
Otherwise, do the pack operations
"""
if context is None:
context = {}
ctx = context.copy()
ctx['do_only_split'] = True
quant_package_obj = self.pool.get('stock.quant.package')
backorder_moves = []
for picking in self.browse(cr, uid, picking_ids, context=context):
if not picking.pack_operation_ids:
continue
for op in picking.pack_operation_ids:
if op.package_id:
for quant in quant_package_obj.quants_get(cr, uid, op.package_id, context=context):
backorder_moves += self._do_partial_product_move(cr, uid, picking, quant.product_id, quant.qty, quant, context=ctx)
elif op.product_id:
backorder_moves += self._do_partial_product_move(cr, uid, picking, op.product_id, op.product_qty, op.quant_id, context=ctx)
self._create_backorder(cr, uid, picking, backorder_moves, context=context)
return True
# Methods for the barcode UI
def _get_picking_for_packing_ui(self, cr, uid, context=None):

View File

@ -587,6 +587,7 @@
<button name="action_assign" states="confirmed" string="Check Availability" type="object" class="oe_highlight" groups="base.group_user"/>
<button name="force_assign" states="confirmed" string="Force Availability" type="object" class="oe_highlight" groups="base.group_user"/>
<button name="do_partial" states="assigned" string="Transfer Done" groups="stock.group_stock_user" type="object" class="oe_highlight"/>
<button name="do_split" string="Postpone Partial Transfer" groups="stock.group_stock_user" type="object" attrs="{'invisible': ['|',('pack_operation_exist', '=', False),('state','!=','assigned')]}"/>
<button name="do_prepare_partial" string="Partial Transfer" groups="stock.group_stock_user" type="object" class="oe_highlight" attrs="{'invisible': ['|',('pack_operation_exist', '=', True),('state','!=','assigned')]}"/>
<button name="%(act_stock_return_picking)d" string="Reverse Transfer" states="done" type="action" groups="base.group_user"/>
<button name="action_cancel" states="assigned,confirmed,draft" string="Cancel Transfer" groups="base.group_user" type="object"/>
@ -667,7 +668,7 @@
<filter string="Order Date" icon="terp-go-month" domain="[]" context="{'group_by':'date'}"/>
<filter string="Expected Date" icon="terp-go-month" domain="[]" context="{'group_by':'min_date'}"/>
<filter string="Origin" domain="[]" context="{'group_by':'origin'}"/>
<filter string="Picking Type" name="picking_type_id" domain="[]" context="{'group_by':'picking_type_id'}"/>
<filter string="Picking Type" domain="[]" context="{'group_by':'picking_type_id'}"/>
</group>
</search>
</field>
@ -854,7 +855,7 @@
<group name="origin_grp" string="Origin">
<field name="origin"/>
<field name="picking_id" domain="[('picking_type_id','=',picking_type_id)]"/>
<field name="picking_type_id"/>
<field name="picking_type_id"/>
<field name="location_id" groups="stock.group_locations"/>
<field name="create_date" groups="base.group_no_one"/>
</group>

View File

@ -136,7 +136,7 @@
<field name="model">stock.picking</field>
<field name="inherit_id" ref="stock.view_picking_internal_search"/>
<field name="arch" type="xml">
<xpath expr="//filter[@name='picking_type_id']" position="after">
<xpath expr="//filter[@string='Picking Type']" position="after">
<filter string="Wave" domain="[]" context="{'group_by':'wave_id'}"/>
</xpath>
<xpath expr="//field[@name='picking_type_id']" position="after">
@ -156,16 +156,5 @@
</field>
</record>
<record model="ir.ui.view" id="partner_wave_type">
<field name="name">partner.wave.type.view</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form" />
<field name="arch" type="xml">
<xpath expr="//field[@name='active']" position="after">
<field name="wave_type" widget="many2many_tags"/>
</xpath>
</field>
</record>
</data>
</openerp>