[IMP] Make sure invoice_state of picking is used when creating extra moves and take...
authorJosse Colpaert <jco@odoo.com>
Thu, 2 Oct 2014 10:00:46 +0000 (12:00 +0200)
committerJosse Colpaert <jco@odoo.com>
Mon, 6 Oct 2014 07:10:09 +0000 (09:10 +0200)
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.

addons/stock/stock.py
addons/stock_account/stock.py

index 9f5a4bb..badd9cc 100644 (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)
index aecf8d3..295c17f 100644 (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
\ No newline at end of file