← Back to team overview

openerp-community-reviewer team mailing list archive

lp:~camptocamp/margin-analysis/7.0-port-product_get_cost_field-yvr into lp:margin-analysis

 

Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/margin-analysis/7.0-port-product_get_cost_field-yvr into lp:margin-analysis.

Requested reviews:
  Margin Analysis Core Editors (margin-analysis-core-editors)

For more details, see:
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-port-product_get_cost_field-yvr/+merge/190347

Portage of product_get_cost_field
-- 
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-port-product_get_cost_field-yvr/+merge/190347
Your team Margin Analysis Core Editors is requested to review the proposed merge of lp:~camptocamp/margin-analysis/7.0-port-product_get_cost_field-yvr into lp:margin-analysis.
=== modified file 'product_get_cost_field/__openerp__.py'
--- product_get_cost_field/__openerp__.py	2013-09-11 08:08:22 +0000
+++ product_get_cost_field/__openerp__.py	2013-10-10 12:15:41 +0000
@@ -30,10 +30,10 @@
  Provides an overridable method on product which compute the cost_price field of a product. 
  By default it just return the value of standard_price field, but using the product_cost_incl_bom
  module, it will return the costing from the bom.
- 
+
  As it is a generic module, you can also setup your own way of computing the cost_price for your 
  product.
- 
+
  All our modules to compute margin are based on it, so you'll ba able to use them in your own way.
  """,
  'website': 'http://www.camptocamp.com/',
@@ -41,7 +41,7 @@
  'update_xml': ['product_view.xml'],
  'demo_xml': [],
  'tests': [],
- 'installable': False,
+ 'installable': True,
  'auto_install': False,
  'license': 'AGPL-3',
  'application': False

=== modified file 'product_get_cost_field/product_get_cost_field.py'
--- product_get_cost_field/product_get_cost_field.py	2012-07-12 13:56:17 +0000
+++ product_get_cost_field/product_get_cost_field.py	2013-10-10 12:15:41 +0000
@@ -28,14 +28,23 @@
 class Product(Model):
     _inherit = 'product.product'
 
+    def _compute_purchase_price(self, cr, uid, ids,
+                                context=None):
+        res = {}
+        products = self.browse(cr, uid, ids)
+        if isinstance(ids, (int, long)):
+            res = products.standard_price
+        elif isinstance(ids, list):
+            for product in self.browse(cr, uid, ids, context=context):
+                res[product.id] = product.standard_price
+        return res
+
     def _cost_price(self, cr, uid, ids, field_name, arg, context=None):
         if context is None:
             context = {}
         logger = logging.getLogger('product.get_cost_field')
         logger.debug("get cost field _cost_price %s, %s, %s", field_name, arg, context)
-        res = {}
-        for product in self.browse(cr, uid, ids):
-            res[product.id] = product.standard_price
+        res = self._compute_purchase_price(cr, uid, ids, context=context)
         return res
 
     def get_cost_field(self, cr, uid, ids, context=None):


Follow ups