[WIP] rereserve + store on remaining qty in move + remove route_id

bzr revid: jco@openerp.com-20130822122103-a4qgvukgho8vuwv9
This commit is contained in:
Josse Colpaert 2013-08-22 14:21:03 +02:00
parent ee59841b3d
commit 9e15fb27b6
4 changed files with 41 additions and 15 deletions

View File

@ -397,7 +397,6 @@
<field name="product_uom_qty" readonly="1" class="oe_inline"/>
<field name="product_uom" groups="product.group_uom" class="oe_inline"/>
</div>
<field name="route_id"/>
</group>
<group>
<field name="price_unit"/>

View File

@ -14,6 +14,20 @@
</data>
</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

@ -697,19 +697,19 @@ class stock_picking(osv.osv):
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]
while ops_list:
ops = ops_list.pop()
for ops in picking.pack_operation_ids:
#Find moves that correspond
if ops[0].product_id:
move_ids = move_obj.search(cr, uid, [('picking_id','=',picking.id), ('product_id', '=', ops[0].product_id), ('remaining_qty', '>', 0.0)], context=context)
for move in move_obj.browse(cr, uid, move_ids, context=context):
if move.remaining_qty > ops[1]:
qty = ops[1]
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
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
# Add remaining quantity to the list
if ops[1] - qty > 0:
ops_list.append((ops[0] , ops[1] - qty),)
qty_to_do -= move.remaining_qty
if create and move.location_id != 'internal':
# Create quants
@ -733,9 +733,12 @@ class stock_picking(osv.osv):
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.package_id.quant_ids #_get_package_lines
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]
quant_obj.quants_reserve(cr,uid, to_reserve, context=context)
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)
#Need to check on which move
# for line in lines:
# if not line.reservation_id:
@ -983,6 +986,14 @@ class stock_move(osv.osv):
res[move.id] = min(move.product_qty, availability)
return res
def _get_move(self, cr, uid, ids, context=None):
res = set()
for quant in self.browse(cr, uid, ids, context=context):
if quant.reservation_id:
res.add(quant.reservation_id.id)
return list(res)
_columns = {
'name': fields.char('Description', required=True, select=True),
'priority': fields.selection([('0', 'Not urgent'), ('1', 'Urgent')], 'Priority'),
@ -1048,7 +1059,9 @@ class stock_move(osv.osv):
'quant_ids': fields.many2many('stock.quant', 'stock_quant_move_rel', 'move_id', 'quant_id', 'Quants'),
'reserved_quant_ids': fields.one2many('stock.quant', 'reservation_id', 'Reserved quants'),
'remaining_qty': fields.function(_get_remaining_qty, type='float', string='Remaining Quantity', digits_compute=dp.get_precision('Product Unit of Measure'), states={'done': [('readonly', True)]}),
'remaining_qty': fields.function(_get_remaining_qty, type='float', string='Remaining Quantity',
digits_compute=dp.get_precision('Product Unit of Measure'), states={'done': [('readonly', True)]},
store = {'stock.quant': (_get_move, ['reservation_id'], 10)}),
'procurement_id': fields.many2one('procurement.order', 'Procurement'),
'group_id': fields.related('procurement_id', 'group_id', type='many2one', relation="procurement.group", string='Procurement Group'),
'rule_id': fields.many2one('procurement.rule', 'Procurement Rule'),

View File

@ -15,7 +15,7 @@
product_uom: product.product_uom_unit
location_dest_id: stock.stock_location_customers
move_type: direct
type: out
picking_type_id: stock.picking_type_out
-
I need to check the availability of the product so I make my picking order for processing later.
-