← Back to team overview

openerp-community-reviewer team mailing list archive

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

 

Yannick Vaucher @ Camptocamp has proposed merging lp:~camptocamp/margin-analysis/7.0-port-product_cost_incl_bom-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_cost_incl_bom-yvr/+merge/190348

Portage of product_cost_incl_bom
-- 
https://code.launchpad.net/~camptocamp/margin-analysis/7.0-port-product_cost_incl_bom-yvr/+merge/190348
Your team Margin Analysis Core Editors is requested to review the proposed merge of lp:~camptocamp/margin-analysis/7.0-port-product_cost_incl_bom-yvr into lp:margin-analysis.
=== modified file 'product_cost_incl_bom/__openerp__.py'
--- product_cost_incl_bom/__openerp__.py	2013-09-11 08:08:22 +0000
+++ product_cost_incl_bom/__openerp__.py	2013-10-10 12:16:22 +0000
@@ -24,7 +24,7 @@
  'maintainer': 'Camptocamp',
  'category': 'Products',
  'complexity': "normal",  # easy, normal, expert
- 'depends' : ['product_get_cost_field', 
+ 'depends' : ['product_get_cost_field',
               'mrp'],
  'description': """
   Compute product cost price by recursively summing parts cost prices according to product BOM. It takes into
@@ -36,7 +36,7 @@
  'update_xml': [],
  'demo_xml': [],
  'tests': [],
- 'installable': False,
+ 'installable': True,
  'auto_install': False,
  'license': 'AGPL-3',
  'application': False}

=== modified file 'product_cost_incl_bom/product_cost_incl_bom.py'
--- product_cost_incl_bom/product_cost_incl_bom.py	2012-07-12 13:56:17 +0000
+++ product_cost_incl_bom/product_cost_incl_bom.py	2013-10-10 12:16:22 +0000
@@ -27,16 +27,15 @@
     _inherit = 'product.product'
 
     def _compute_purchase_price(self, cursor, user, ids,
-                                product_uom=None,
-                                bom_properties=None,
                                 context=None):
         '''
         Compute the purchase price, taking into account sub products and routing
         '''
         if context is None:
             context = {}
-        if bom_properties is None:
-            bom_properties =  []
+        product_uom = context.get('product_uom')
+        bom_properties = context.get('properties', [])
+
         bom_obj = self.pool.get('mrp.bom')
         uom_obj = self.pool.get('product.uom')
 
@@ -45,11 +44,9 @@
 
         for pr in self.browse(cursor, user, ids):
 
-            # Workaround for first loading in V5 as some columns are not created
-            #if not hasattr(pr, 'standard_price'): return False
-            bom_id = bom_obj._bom_find(cursor, user, pr.id, product_uom=None, properties=bom_properties)
+            bom_id = bom_obj._bom_find(cursor, user, pr.id, product_uom=product_uom, properties=bom_properties)
             if not bom_id: # no BoM: use standard_price
-                res[pr.id] = pr.standard_price
+                res[pr.id] = super(Product, self)._compute_purchase_price(cursor, user, pr.id, context=context)
                 continue
             bom = bom_obj.browse(cursor, user, bom_id)
             sub_products, routes = bom_obj._bom_explode(cursor, user, bom,
@@ -76,22 +73,19 @@
             res[pr.id] = price
         return res
 
-    def get_cost_field(self, cr, uid, ids, context=None):
-        return self._cost_price(cr, uid, ids, '', [], context)
 
     def _cost_price(self, cr, uid, ids, field_name, arg, context=None):
         if context is None:
             context = {}
-        product_uom = context.get('product_uom')
-        bom_properties = context.get('properties')
-        res = self._compute_purchase_price(cr, uid, ids, product_uom, bom_properties)
+
+        res = self._compute_purchase_price(cr, uid, ids, context=context)
         return res
 
     _columns = {
         'cost_price': fields.function(_cost_price,
                                       method=True,
                                       string='Cost Price (incl. BoM)',
-                                      digits_compute = dp.get_precision('Sale Price'),
+                                      digits_compute=dp.get_precision('Sale Price'),
                                       help="The cost price is the standard price or, if the product has a bom, "
                                       "the sum of all standard price of its components. it take also care of the "
                                       "bom costing like cost per cylce.")


Follow ups