diff --git a/addons/sale_stock_location/sale_stock_location_view.xml b/addons/sale_stock_location/sale_stock_location_view.xml
index 2273831dce2..0a8ad68f060 100644
--- a/addons/sale_stock_location/sale_stock_location_view.xml
+++ b/addons/sale_stock_location/sale_stock_location_view.xml
@@ -15,19 +15,6 @@
-
- sale.order.line.form.sale.stock.location.open
- sale.order.line
-
-
-
-
-
-
-
-
-
-
sale.order.line.tree.sale.stock.location
diff --git a/addons/stock/stock.py b/addons/stock/stock.py
index 5a8e2641eff..73a0f2ab4c0 100644
--- a/addons/stock/stock.py
+++ b/addons/stock/stock.py
@@ -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):
diff --git a/addons/stock/stock_view.xml b/addons/stock/stock_view.xml
index f6a8c12976c..c0c6ba97976 100644
--- a/addons/stock/stock_view.xml
+++ b/addons/stock/stock_view.xml
@@ -583,6 +583,7 @@
+
diff --git a/addons/stock/test/packing.yml b/addons/stock/test/packing.yml
index a2b13fefe01..64f772268f4 100644
--- a/addons/stock/test/packing.yml
+++ b/addons/stock/test/packing.yml
@@ -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
+-
+
\ No newline at end of file