Mayur Maheshwari(OpenERP) has proposed merging 
lp:~openerp-dev/openobject-addons/trunk-bug-923585-mma into 
lp:openobject-addons.

Requested reviews:
  Rucha (Open ERP) (rpa-openerp)
Related bugs:
  Bug #923585 in OpenERP Addons: "[trunk] average cost recalculated even if 
stock never received (direct delivery)"
  https://bugs.launchpad.net/openobject-addons/+bug/923585

For more details, see:
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-923585-mma/+merge/92754

Hello 

       purchase,stock: I have added a method get_standard_price for average 
cost calculation.

Thanks.
mma
-- 
https://code.launchpad.net/~openerp-dev/openobject-addons/trunk-bug-923585-mma/+merge/92754
Your team OpenERP R&D Team is subscribed to branch 
lp:~openerp-dev/openobject-addons/trunk-bug-923585-mma.
=== modified file 'purchase/stock.py'
--- purchase/stock.py	2012-02-01 11:37:24 +0000
+++ purchase/stock.py	2012-02-13 12:46:25 +0000
@@ -116,6 +116,12 @@
         if picking.purchase_id:
             purchase_obj.write(cursor, user, [picking.purchase_id.id], {'invoice_ids': [(4, invoice_id)]})
         return super(stock_picking, self)._invoice_hook(cursor, user, picking, invoice_id)
+    
+    def get_standard_price(self, cr, uid, product, qty, product_avail, new_price, picking, context=None):
+        if picking.purchase_id.dest_address_id:
+            return product.price_get('standard_price', context=context)[product.id]
+        else:
+            return super(stock_picking, self).get_standard_price(cr, uid, product, qty, product_avail, new_price, picking, context)
 
 class stock_partial_picking(osv.osv_memory):
     _inherit = 'stock.partial.picking'
@@ -123,9 +129,12 @@
     # Overridden to inject the purchase price as true 'cost price' when processing
     # incoming pickings.
     def _product_cost_for_average_update(self, cr, uid, move):
-        if move.picking_id.purchase_id:
-            return {'cost': move.purchase_line_id.price_unit,
-                    'currency': move.picking_id.purchase_id.pricelist_id.currency_id.id}
-        return super(stock_partial_picking, self)._product_cost_for_average_update(cr, uid, move)
+        purchase_id = move.picking_id.purchase_id
+        if purchase_id:
+            if purchase_id.dest_address_id:
+                 return {}
+            else:
+                return {'cost': move.purchase_line_id.price_unit,
+                    'currency': purchase_id.pricelist_id.currency_id.id}
 
 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:

=== modified file 'stock/stock.py'
--- stock/stock.py	2012-02-08 11:29:46 +0000
+++ stock/stock.py	2012-02-13 12:46:25 +0000
@@ -1167,6 +1167,16 @@
 
         return super(stock_picking, self).unlink(cr, uid, ids, context=context)
 
+    def get_standard_price(self, cr, uid, product, qty, product_avail, new_price, pick, context=None):
+        if product.qty_available <= 0:
+            new_std_price = new_price
+        else:
+            # Get the standard price
+            amount_unit = product.price_get('standard_price', context=context)[product.id]
+            new_std_price = ((amount_unit * product_avail)\
+            + (new_price * qty))/(product_avail + qty)
+        return new_std_price
+        
     # FIXME: needs refactoring, this code is partially duplicated in stock_move.do_partial()!
     def do_partial(self, cr, uid, ids, partial_datas, context=None):
         """ Makes partial picking and moves done.
@@ -1221,20 +1231,13 @@
                         product_avail[product.id] += qty
                     else:
                         product_avail[product.id] = product.qty_available
-
                     if qty > 0:
                         new_price = currency_obj.compute(cr, uid, product_currency,
                                 move_currency_id, product_price)
                         new_price = uom_obj._compute_price(cr, uid, product_uom, new_price,
                                 product.uom_id.id)
-                        if product.qty_available <= 0:
-                            new_std_price = new_price
-                        else:
-                            # Get the standard price
-                            amount_unit = product.price_get('standard_price', context=context)[product.id]
-                            new_std_price = ((amount_unit * product_avail[product.id])\
-                                + (new_price * qty))/(product_avail[product.id] + qty)
-                        # Write the field according to price type field
+                       
+                        new_std_price = self.get_standard_price(cr, uid, product, qty, product_avail[product.id], new_price, pick, context)
                         product_obj.write(cr, uid, [product.id], {'standard_price': new_std_price})
 
                         # Record the values that were chosen in the wizard, so they can be

_______________________________________________
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