[IMP] Make sure invoice_state of picking is used when creating extra moves and take price of related move if there is one

When we would copy, it gives problems as it won't be invoiced the correct way on sale, so we provide for a simpler solution.
This commit is contained in:
Josse Colpaert 2014-10-02 12:00:46 +02:00
parent ab7b5d7732
commit 383f2b2c43
2 changed files with 28 additions and 10 deletions

View File

@ -1255,6 +1255,23 @@ class stock_picking(osv.osv):
if picking.pack_operation_ids:
self.recompute_remaining_qty(cr, uid, picking, context=context)
def _prepare_values_extra_move(self, cr, uid, op, product, remaining_qty, context=None):
"""
Creates an extra move when there is no corresponding original move to be copied
"""
picking = op.picking_id
res = {
'picking_id': picking.id,
'location_id': picking.location_id.id,
'location_dest_id': picking.location_dest_id.id,
'product_id': product.id,
'product_uom': product.uom_id.id,
'product_uom_qty': remaining_qty,
'name': _('Extra Move: ') + op.product_id.name,
'state': 'draft',
}
return res
def _create_extra_moves(self, cr, uid, picking, context=None):
'''This function creates move lines on a picking, at the time of do_transfer, based on
unexpected product transfers (or exceeding quantities) found in the pack operations.
@ -1266,16 +1283,7 @@ class stock_picking(osv.osv):
for product_id, remaining_qty in operation_obj._get_remaining_prod_quantities(cr, uid, op, context=context).items():
if remaining_qty > 0:
product = self.pool.get('product.product').browse(cr, uid, product_id, context=context)
vals = {
'picking_id': picking.id,
'location_id': picking.location_id.id,
'location_dest_id': picking.location_dest_id.id,
'product_id': product_id,
'product_uom': product.uom_id.id,
'product_uom_qty': remaining_qty,
'name': _('Extra Move: ') + product.name,
'state': 'draft',
}
vals = self._prepare_values_extra_move(cr, uid, op, product, remaining_qty, context=context)
moves.append(move_obj.create(cr, uid, vals, context=context))
if moves:
move_obj.action_confirm(cr, uid, moves, context=context)

View File

@ -300,3 +300,13 @@ class stock_picking(osv.osv):
invoice_obj.button_compute(cr, uid, invoices.values(), context=context, set_total=(inv_type in ('in_invoice', 'in_refund')))
return invoices.values()
def _prepare_values_extra_move(self, cr, uid, op, product, remaining_qty, context=None):
"""
Need to pass invoice_state of picking when an extra move is created which is not a copy of a previous
"""
res = super(stock_picking, self)._prepare_values_extra_move(cr, uid, op, product, remaining_qty, context=context)
res.update({'invoice_state': op.picking_id.invoice_state})
if op.linked_move_operation_ids:
res.update({'price_unit': op.linked_move_operation_ids[-1].move_id.price_unit})
return res