[WIP] Rereserve button with qty remaining and should return ops remaining, adjust packing.yml, revert salestock view

bzr revid: jco@openerp.com-20130822144944-2bhuyziu7dk1asio
This commit is contained in:
Josse Colpaert 2013-08-22 16:49:44 +02:00
parent 9e15fb27b6
commit 9690f9070a
4 changed files with 105 additions and 48 deletions

View File

@ -15,19 +15,6 @@
</field>
</record>
<record id="view_order_form_inherit3" model="ir.ui.view">
<field name="name">sale.order.line.form.sale.stock.location.open</field>
<field name="model">sale.order.line</field>
<field name="inherit_id" ref="sale."/>
<field name="arch" type="xml">
<data>
<xpath expr="//field[@name='price_unit']" position="before">
<field name="route_id"/>
</xpath>
</data>
</field>
</record>
<record id="view_order_line_tree_inherit" model="ir.ui.view">
<field name="name">sale.order.line.tree.sale.stock.location</field>
<field name="inherit_id" ref="sale.view_order_line_tree"/>

View File

@ -687,21 +687,21 @@ class stock_picking(osv.osv):
def rereserve(self, cr, uid, picking_ids, create=False, context=None):
"""
This will unreserve all products and reserve the quants from the operations
:return: dictionary with quantities of quant operation and product that can not be matched with moves
"""
quant_obj = self.pool.get("stock.quant")
move_obj = self.pool.get("stock.move")
op_obj = self.pool.get("stock.pack.operation")
res = {}
for picking in self.browse(cr, uid, picking_ids, context=context):
# unreserve everything
for move in picking.move_lines:
quant_obj.quants_unreserve(cr, uid, move, context=context)
# if picking.location_id.usage != 'internal' and picking.location_dest_id.usage == 'internal': #When to create the pickings?
ops_list = [(x.id, x.product_uom_qty) for x in picking.pack_operation_ids]
for ops in picking.pack_operation_ids:
#Find moves that correspond
if ops.product_id:
move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops.product_id), ('remaining_qty', '>', 0.0)], context=context)
qty_to_do = ops.product_uom_qty
move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops.product_id.id), ('remaining_qty', '>', 0.0)], context=context)
qty_to_do = ops.product_qty
while qty_to_do > 0 and move_ids:
move = move_obj.browse(cr, uid, move_ids.pop(), context=context)
if move.remaining_qty > qty_to_do:
@ -721,24 +721,35 @@ class stock_picking(osv.osv):
'history_ids': [(4, move.id)],
'in_date': datetime.now().strftime('%Y-%m-%d %H:%M:%S'),
'company_id': move.company_id.id,
'lot_id': ops[0].lot_id and ops.lot_id.id or False,
'lot_id': ops.lot_id and ops.lot_id.id or False,
'reservation_id': move.id, #Reserve at once
'package_id': ops[0].result_package_id and ops[0].result_package_id.id or False,
'package_id': ops.result_package_id and ops.result_package_id.id or False,
}
quant_id = quant_obj.create(cr, uid, vals, context=context)
else:
#Quants get
domain = [('reservation_id', '=', False)]
prefered_order = op_obj._get_preferred_order(cr, uid, ops[0].id, context=context)
prefered_order = op_obj._get_preferred_order(cr, uid, ops.id, context=context)
quants = quant_obj.quants_get(cr, uid, move.location_id, move.product_id, qty, domain=domain, prefered_order=prefered_order, context=context)
quant_obj.quants_reserve(cr, uid, quants, move, context=context)
elif ops[0].package_id:
lines = ops[0].package_id.quant_ids #_get_package_lines
to_reserve = [(x.id, x.product_uom_qty) for x in lines if not x.reservation_id]
for reserve in to_reserve:
move_ids = move_obj.search(cr, uid, [('picking_id', '=', picking.id), ('product_id', '=', reserve.product_id)])
quant_obj.quants_reserve(cr, uid, to_reserve, context=context)
res[ops.id] = {}
res[ops.id][ops.product_id.id] = qty_to_do
elif ops.package_id:
quants = ops.package_id.quant_ids #_get_package_lines
for quant in quants:
move_ids = move_obj.search(cr, uid, [('picking_id', '=', picking.id), ('product_id', '=', quant.product_id.id), ('remaining_qty', '>', 0.0)])
qty_to_do = quant.qty
while qty_to_do > 0 and move_ids:
move = move_obj.browse(cr, uid, move_ids.pop(), context=context)
if move.remaining_qty > qty_to_do:
qty = qty_to_do
qty_to_do = 0
else:
qty = move.remaining_qty
qty_to_do -= move.remaining_qty
quant_obj.quants_reserve(cr, uid, [(quant.id, qty)], move, context=context)
#quant_obj.quants_reserve(cr, uid, to_reserve, context=context)
#Need to check on which move
# for line in lines:
# if not line.reservation_id:
@ -945,21 +956,29 @@ class stock_move(osv.osv):
res[m.id] = uom_obj._compute_qty_obj(cr, uid, m.product_uom, m.product_uom_qty, m.product_id.uom_id)
return res
def _get_remaining_qty(self, cr, uid, ids, field_name, args, context=None):
#TODO: this function assumes that there aren't several stock move in the same picking with the same product. what should we do in that case?
#TODO take care of the quant on stock moves too
res = dict.fromkeys(ids, False)
for move in self.browse(cr, uid, ids, context=context):
res[move.id] = move.product_qty
if move.picking_id:
for op in move.picking_id.pack_operation_ids:
if op.product_id == move.product_id or (op.quant_id and op.quant_id.product_id == move.product_id):
res[move.id] -= op.product_qty
if op.package_id:
#find the product qty recursively
res[move.id] -= self.pool.get('stock.quant.package')._get_product_total_qty(cr, uid, op.package_id, move.product_id.id, context=context)
return res
# def _get_remaining_qty(self, cr, uid, ids, field_name, args, context=None):
# #TODO: this function assumes that there aren't several stock move in the same picking with the same product. what should we do in that case?
# #TODO take care of the quant on stock moves too
# res = dict.fromkeys(ids, False)
# for move in self.browse(cr, uid, ids, context=context):
# res[move.id] = move.product_qty
# if move.picking_id:
# for op in move.picking_id.pack_operation_ids:
# if op.product_id == move.product_id or (op.quant_id and op.quant_id.product_id == move.product_id):
# res[move.id] -= op.product_qty
# if op.package_id:
# #find the product qty recursively
# res[move.id] -= self.pool.get('stock.quant.package')._get_product_total_qty(cr, uid, op.package_id, move.product_id.id, context=context)
# return res
def _get_remaining_qty(self, cr, uid, ids, field_name, args, context=None):
res = {}
for move in self.browse(cr, uid, ids, context=context):
res[move.id] = move.product_uom_qty
for quant in move.reserved_quant_ids:
res[move.id] -= quant.qty
return res
def _get_lot_ids(self, cr, uid, ids, field_name, args, context=None):

View File

@ -583,6 +583,7 @@
<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="rereserve" string="ReReserve from Operations" 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"/>

View File

@ -1,5 +1,5 @@
-
Create a new stockable product
Create a new stockable product
-
!record {model: product.product, id: packingtest}:
name: nice product
@ -8,11 +8,61 @@
-
!record{model: stock.picking}: |
-
Create move linked to picking
Confirm and assign picking and prepare partial
-
!record{model:stock.move, id:}
-
Confirm picking
-
!python {model: stock.picking}: |
!python {model: stock.picking, id:}: |
self.action_confirm(cr, uid, ref())
-
Put 120 pieces on Pallet 1 (package), 120 pieces on Pallet 2 with lot A and 60 pieces on Pallet 3
-
!python {model: stock.picking, id:} |
#Change quantity of first to 120 and create 2 others quant operations
#Create package for each line and assign it as result_package_id
-
Use button rereserve and check the qtyremaining on the moves are correct (=0)
-
-
Transfer the reception
-
-
Check the system created 3 quants one with 120 pieces on pallet 1, one with 120 pieces on pallet 2 with lot A and 60 pieces on pallet 3
-
-
Check there is no backorder or extra moves created
-
-
Make a delivery order of 300 pieces to the customer
-
-
Assign and confirm
-
-
Instead of doing the 300 pieces, you decide to take pallet 1 (do not mention product in operation here) and 20 pieces from lot A and 10 pieces from pallet 3
-
-
Process this picking
-
-
Check the quants that you have 120 pieces pallet 1 in customers, 100 pieces pallet 2 in stock and 20 with customers and 50 in stock, 10 in customers from pallet 3
-
-
Check a backorder was created and on that backorder, prepare partial and add an op with 20 pieces (20 that cannot be assigned) with lot B
-
-
Process this backorder
-
-
Check you have a negative quant because there were 20 too many that were transferred with lot B
-