[REF] purchase: more work for modular picking generation
bzr revid: rvalyi@gmail.com-20111016013125-0blsz0g2gl5z1plv
This commit is contained in:
parent
389c81177a
commit
e08e6d973a
|
@ -441,11 +441,9 @@ class purchase_order(osv.osv):
|
|||
'move_lines' : [],
|
||||
}
|
||||
|
||||
def _prepare_order_line_move(self, cr, uid, order_line, picking_id, *args):
|
||||
loc_id = order_line.order_id.partner_id.property_stock_supplier.id
|
||||
dest = order_line.order_id.location_id.id
|
||||
def _prepare_order_line_move(self, cr, uid, order, order_line, picking_id, *args):
|
||||
return {
|
||||
'name': order_line.order_id.name + ': ' +(order_line.name or ''),
|
||||
'name': order.name + ': ' +(order_line.name or ''),
|
||||
'product_id': order_line.product_id.id,
|
||||
'product_qty': order_line.product_qty,
|
||||
'product_uos_qty': order_line.product_qty,
|
||||
|
@ -453,27 +451,33 @@ class purchase_order(osv.osv):
|
|||
'product_uos': order_line.product_uom.id,
|
||||
'date': order_line.date_planned,
|
||||
'date_expected': order_line.date_planned,
|
||||
'location_id': loc_id,
|
||||
'location_dest_id': dest,
|
||||
'location_id': order.partner_id.property_stock_supplier.id,
|
||||
'location_dest_id': order.location_id.id,
|
||||
'picking_id': picking_id,
|
||||
'address_id': order_line.order_id.dest_address_id.id or order_line.order_id.partner_address_id.id,
|
||||
'address_id': order.dest_address_id.id or order.partner_address_id.id,
|
||||
'move_dest_id': order_line.move_dest_id.id,
|
||||
'state': 'draft',
|
||||
'purchase_line_id': order_line.id,
|
||||
'company_id': order_line.order_id.company_id.id,
|
||||
'company_id': order.company_id.id,
|
||||
'price_unit': order_line.price_unit
|
||||
}
|
||||
|
||||
def _create_pickings(self, cr, uid, order_lines, picking_id=False, *args):
|
||||
def _create_pickings(self, cr, uid, order, order_lines, picking_id=False, *args):
|
||||
"""
|
||||
Create pickings for given order lines. Filtering the order lines allows to partition the delivery
|
||||
over several pickings.
|
||||
Creates pickings and appropriate stock moves for given order lines.
|
||||
|
||||
:param cr: database cursor
|
||||
:param uid: current user id
|
||||
:param order: sale order object
|
||||
:param order_lines: sale order line objects
|
||||
:param picking_id: id of picking to use evenually
|
||||
If ``picking_id`` is provided, the stock moves will be added to it, otherwise
|
||||
a standard outgoing picking will be created to wrap the stock moves, as returned
|
||||
by :meth:`~._prepare_order_picking`.
|
||||
|
||||
Modules that wish to customize the procurements or partition the stock moves over
|
||||
multiple stock pickings may override this method and call ``super()`` with
|
||||
different subsets of ``order_lines`` and/or preset ``picking_id`` values.
|
||||
|
||||
:param browse_record order: purchase order to which the order lines belong
|
||||
:param list(browse_record) order_lines: sale order line records to procure
|
||||
:param int picking_id: optional ID of a stock picking to which the created stock moves
|
||||
will be added. A new picking will be created if ommitted.
|
||||
:return: True
|
||||
"""
|
||||
picking_id = self.pool.get('stock.picking').create(cr, uid, self._prepare_order_picking(cr, uid, order, args))
|
||||
|
@ -482,9 +486,9 @@ class purchase_order(osv.osv):
|
|||
if not order_line.product_id:
|
||||
continue
|
||||
if order_line.product_id.product_tmpl_id.type in ('product', 'consu'):
|
||||
move = self.pool.get('stock.move').create(cr, uid, self._prepare_order_line_move(cr, uid, order_line, picking_id, args))
|
||||
move = self.pool.get('stock.move').create(cr, uid, self._prepare_order_line_move(cr, uid, order, order_line, picking_id, args))
|
||||
if order_line.move_dest_id:
|
||||
self.pool.get('stock.move').write(cr, uid, [order_line.move_dest_id.id], {'location_id': order_line.order_id.location_id.id})
|
||||
self.pool.get('stock.move').write(cr, uid, [order_line.move_dest_id.id], {'location_id': order.location_id.id})
|
||||
todo_moves.append(move)
|
||||
self.pool.get('stock.move').action_confirm(cr, uid, todo_moves)
|
||||
self.pool.get('stock.move').force_assign(cr, uid, todo_moves)
|
||||
|
@ -494,10 +498,9 @@ class purchase_order(osv.osv):
|
|||
return picking_id
|
||||
|
||||
def action_picking_create(self,cr, uid, ids, *args):
|
||||
picking_id = False
|
||||
for order in self.browse(cr, uid, ids):
|
||||
self._create_pickings(cr, uid, [order_line for order_line in order.order_line], False, args)
|
||||
return picking_id
|
||||
picking_id = self._create_pickings(cr, uid, order, [order_line for order_line in order.order_line], False, args)
|
||||
return picking_id #FIXME this is brittle to assume there is only 1 picking_id, but has been kept for API compatibility
|
||||
|
||||
def copy(self, cr, uid, id, default=None, context=None):
|
||||
if not default:
|
||||
|
|
Loading…
Reference in New Issue