Rohan Nayani(Open ERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-779145-ron into 
lp:openobject-addons.

Requested reviews:
  Rucha (Open ERP) (rpa-openerp)
Related bugs:
  Bug #779145 in OpenERP Addons: "[stock] store price_unit for all stock moves, 
and use it for suggesting return picking values"
  https://bugs.launchpad.net/openobject-addons/+bug/779145

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-779145-ron/+merge/65324

[FIX]stock,sale,purchase:Fixed=>
1)use price_unit field as current cost price,
2)this field used at return picking as historical price unit'
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-779145-ron/+merge/65324
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-779145-ron.
=== modified file 'sale/sale.py'
--- sale/sale.py	2011-05-18 16:45:45 +0000
+++ sale/sale.py	2011-06-21 09:35:52 +0000
@@ -709,6 +709,7 @@
                         #'state': 'waiting',
                         'note': line.notes,
                         'company_id': order.company_id.id,
+                        'price_unit': line.product_id.standard_price or 0.0
                     })
                     
                 if line.product_id:

=== modified file 'stock/stock.py'
--- stock/stock.py	2011-05-30 16:21:43 +0000
+++ stock/stock.py	2011-06-21 09:35:52 +0000
@@ -1140,6 +1140,19 @@
                 move_obj.unlink(cr, uid, ids2, ctx)
 
         return super(stock_picking, self).unlink(cr, uid, ids, context=context)
+    
+    def get_current_cost_price(self, cr, uid, ids, pick, move, product_price, context=None):
+        """@return: Return Current cost price"""
+        if context is None:
+            context = {}
+        price_unit = 0.0
+        if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
+            price_unit = product_price
+        elif move.price_unit == 0:
+            price_unit = move.product_id.standard_price
+        else:
+            price_unit = move.price_unit
+        return price_unit
 
     # FIXME: needs refactoring, this code is partially duplicated in stock_move.do_partial()!
     def do_partial(self, cr, uid, ids, partial_datas, context=None):
@@ -1217,7 +1230,6 @@
                                 {'price_unit': product_price,
                                  'price_currency_id': product_currency})
 
-
             for move in too_few:
                 product_qty = move_product_qty[move.id]
 
@@ -1229,35 +1241,45 @@
                                 'state':'draft',
                             })
                 if product_qty != 0:
+                    price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context)
                     defaults = {
                             'product_qty' : product_qty,
                             'product_uos_qty': product_qty, #TODO: put correct uos_qty
                             'picking_id' : new_picking,
                             'state': 'assigned',
                             'move_dest_id': False,
-                            'price_unit': move.price_unit,
+                            'price_unit': price_unit or 0.0
                     }
                     prodlot_id = prodlot_ids[move.id]
                     if prodlot_id:
                         defaults.update(prodlot_id=prodlot_id)
                     move_obj.copy(cr, uid, move.id, defaults)
-
+                if (pick.type == 'in') and (move.product_id.cost_method == 'average'):
+                    new_price_unit = move.product_id.standard_price
+                else:
+                    new_price_unit = price_unit
                 move_obj.write(cr, uid, [move.id],
                         {
                             'product_qty' : move.product_qty - product_qty,
                             'product_uos_qty':move.product_qty - product_qty, #TODO: put correct uos_qty
+                            'price_unit': new_price_unit or 0.0
                         })
 
             if new_picking:
                 move_obj.write(cr, uid, [c.id for c in complete], {'picking_id': new_picking})
             for move in complete:
+                price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context)
+                defaults = {'price_unit': price_unit or 0.0}
                 if prodlot_ids.get(move.id):
-                    move_obj.write(cr, uid, [move.id], {'prodlot_id': prodlot_ids[move.id]})
+                    defaults.update({'prodlot_id': prodlot_ids[move.id]})
+                move_obj.write(cr, uid, [move.id], defaults)
             for move in too_many:
+                price_unit = self.get_current_cost_price(cr, uid, ids, pick, move, product_price, context=context)
                 product_qty = move_product_qty[move.id]
                 defaults = {
                     'product_qty' : product_qty,
                     'product_uos_qty': product_qty, #TODO: put correct uos_qty
+                    'price_unit': price_unit or 0.0
                 }
                 prodlot_id = prodlot_ids.get(move.id)
                 if prodlot_ids.get(move.id):
@@ -2489,7 +2511,7 @@
 
         for move in complete:
             if prodlot_ids.get(move.id):
-                self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id)})
+                self.write(cr, uid, [move.id],{'prodlot_id': prodlot_ids.get(move.id), 'price_unit': move.product_id.standard_price})
             self.action_done(cr, uid, [move.id], context=context)
             if  move.picking_id.id :
                 # TOCHECK : Done picking if all moves are done

=== modified file 'stock/wizard/stock_return_picking.py'
--- stock/wizard/stock_return_picking.py	2011-03-18 09:16:07 +0000
+++ stock/wizard/stock_return_picking.py	2011-06-21 09:35:52 +0000
@@ -33,6 +33,7 @@
         'quantity' : fields.float("Quantity", required=True),
         'wizard_id' : fields.many2one('stock.return.picking', string="Wizard"),
         'move_id' : fields.many2one('stock.move', "Move"),
+        'price_unit' : fields.float('Cost Price', digits=(16,2), help="Historical cost price of product")
     }
 
 stock_return_picking_memory()
@@ -73,7 +74,7 @@
             for line in pick.move_lines:
                 qty = line.product_qty - return_history[line.id]
                 if qty > 0:
-                    result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id})
+                    result1.append({'product_id': line.product_id.id, 'quantity': qty,'move_id':line.id, 'price_unit': line.price_unit})
             if 'product_return_moves' in fields:
                 res.update({'product_return_moves': result1})
         return res
@@ -180,9 +181,10 @@
                     'product_qty': new_qty,
                     'product_uos_qty': uom_obj._compute_qty(cr, uid, move.product_uom.id,
                         new_qty, move.product_uos.id),
-                    'picking_id':new_picking, 'state':'draft',
-                    'location_id':new_location, 'location_dest_id':move.location_id.id,
-                    'date':date_cur,})
+                    'picking_id': new_picking, 'state': 'draft',
+                    'location_id': new_location, 'location_dest_id': move.location_id.id,
+                    'date': date_cur,
+                    'price_unit': move.price_unit})
                 move_obj.write(cr, uid, [move.id], {'move_history_ids2':[(4,new_move)]})
         if not returned_lines:
             raise osv.except_osv(_('Warning !'), _("Please specify at least one non-zero quantity!"))

=== modified file 'stock/wizard/stock_return_picking_view.xml'
--- stock/wizard/stock_return_picking_view.xml	2011-03-04 13:47:28 +0000
+++ stock/wizard/stock_return_picking_view.xml	2011-06-21 09:35:52 +0000
@@ -18,7 +18,7 @@
                 <tree editable="bottom" string="Product Moves">
                     <field name="product_id" />
                     <field name="quantity" />
-                    
+                    <field name="price_unit" />
                 </tree>
             </field>
         </record>
@@ -31,6 +31,7 @@
                 <form>
                     <field name="product_id" />
                     <field name="quantity" />
+                    <field name="price_unit" />
                  </form>
             </field>
         </record>   

_______________________________________________
Mailing list: https://launchpad.net/~openerp-dev-gtk
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~openerp-dev-gtk
More help   : https://help.launchpad.net/ListHelp

Reply via email to