← Back to team overview

credativ team mailing list archive

[Merge] lp:~credativ/openobject-addons/6.0-internal-stock-average-cost into lp:~credativ/openobject-addons/6.0

 

Jacob Hicks (credativ) has proposed merging lp:~credativ/openobject-addons/6.0-internal-stock-average-cost into lp:~credativ/openobject-addons/6.0.

Requested reviews:
  Jacob Hicks (credativ) (jah256)

For more details, see:
https://code.launchpad.net/~credativ/openobject-addons/6.0-internal-stock-average-cost/+merge/203725

Merge request to fix average price to take all internal locations in to account
-- 
https://code.launchpad.net/~credativ/openobject-addons/6.0-internal-stock-average-cost/+merge/203725
Your team credativ is subscribed to branch lp:~credativ/openobject-addons/6.0.
=== modified file 'product/product.py'
--- product/product.py	2012-03-30 08:53:02 +0000
+++ product/product.py	2014-01-29 12:28:47 +0000
@@ -579,7 +579,7 @@
     #
     # Could be overrided for variants matrices prices
     #
-    def price_get(self, cr, uid, ids, ptype='list_price', context=None):
+    def price_get(self, cr, uid, ids, ptype='list_price', context=None,round=True):
         if context is None:
             context = {}
 
@@ -604,7 +604,7 @@
                 # Take the price_type currency from the product field
                 # This is right cause a field cannot be in more than one currency
                 res[product.id] = self.pool.get('res.currency').compute(cr, uid, price_type_currency_id,
-                    context['currency_id'], res[product.id],context=context)
+                    context['currency_id'], res[product.id],round=round,context=context)
 
         return res
 

=== modified file 'stock/stock.py'
--- stock/stock.py	2013-04-24 21:59:10 +0000
+++ stock/stock.py	2014-01-29 12:28:47 +0000
@@ -302,7 +302,7 @@
 
                     # Compute based on pricetype
                     # Choose the right filed standard_price to read
-                    amount_unit = product.price_get('standard_price', context)[product.id]
+                    amount_unit = product.price_get('standard_price', context,round=False)[product.id]
                     price = qty[product_id] * amount_unit
 
                     total_price += price
@@ -904,7 +904,7 @@
         if type in ('in_invoice', 'in_refund'):
             # Take the user company and pricetype
             context['currency_id'] = move_line.company_id.currency_id.id
-            amount_unit = move_line.product_id.price_get('standard_price', context)[move_line.product_id.id]
+            amount_unit = move_line.product_id.price_get('standard_price', context,round=False)[move_line.product_id.id]
             return amount_unit
         else:
             return move_line.product_id.list_price
@@ -1214,18 +1214,22 @@
                     if product.id in product_avail:
                         product_avail[product.id] += qty
                     else:
+                        ctx = context.copy()
+                        location_ids = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
+                        ctx.update({'location': location_ids})
+                        product = product.browse(context=ctx)[0]
                         product_avail[product.id] = product.qty_available
 
                     if qty > 0:
                         new_price = currency_obj.compute(cr, uid, product_currency,
-                                move_currency_id, product_price)
+                                move_currency_id, product_price,round=False)
                         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)[product.id]
+                            amount_unit = product.price_get('standard_price', context,round=False)[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
@@ -2069,7 +2073,7 @@
             if context is None:
                 context = {}
             currency_ctx = dict(context, currency_id = move.company_id.currency_id.id)
-            amount_unit = move.product_id.price_get('standard_price', currency_ctx)[move.product_id.id]
+            amount_unit = move.product_id.price_get('standard_price', currency_ctx,round=False)[move.product_id.id]
             reference_amount = amount_unit * qty
 
         return reference_amount, reference_currency_id
@@ -2458,14 +2462,18 @@
                 qty = uom_obj._compute_qty(cr, uid, product_uom, product_qty, product.uom_id.id)
                 if qty > 0:
                     new_price = currency_obj.compute(cr, uid, product_currency,
-                            move_currency_id, product_price)
+                            move_currency_id, product_price,round=False)
                     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:
+                        ctx = context.copy()
+                        location_ids = self.pool.get('stock.location').search(cr, uid, [('usage', '=', 'internal')], context=context)
+                        ctx.update({'location': location_ids})
+                        product = product.browse(context=ctx)[0]
                         # Get the standard price
-                        amount_unit = product.price_get('standard_price', context)[product.id]
+                        amount_unit = product.price_get('standard_price', context,round=False)[product.id]
                         new_std_price = ((amount_unit * product.qty_available)\
                             + (new_price * qty))/(product.qty_available + qty)
 


References