[FIX] product_margin: graph view only use one non-stored field as measure fixes #16565

Because read_group can not handle non-stored fields well,
we fall back to the similar implementation as for the stock
valuation report.  This allows only one non-stored field as a measure in
the graph.  Then it is more logical to show the total margin as that is
what the module is meant for.
This commit is contained in:
Josse Colpaert
2017-05-30 15:53:34 +02:00
parent 82fbe03ff8
commit 40c5366861
2 changed files with 4 additions and 6 deletions
+2 -3
View File
@@ -103,9 +103,8 @@ class product_product(osv.osv):
res[val.id]['total_cost'] = result[2] and result[2] or 0.0
res[val.id]['normal_cost'] = prod.standard_price * res[val.id]['purchase_num_invoiced']
res[val.id]['purchase_gap'] = res[val.id]['normal_cost'] - res[val.id]['total_cost']
if 'total_margin' in field_names:
res[val.id]['total_margin'] = res[val.id]['turnover'] - res[val.id]['total_cost']
res[val.id]['total_margin'] = res[val.id]['turnover'] - res[val.id]['total_cost']
if 'expected_margin' in field_names:
res[val.id]['expected_margin'] = res[val.id]['sale_expected'] - res[val.id]['normal_cost']
if 'total_margin_rate' in field_names:
@@ -8,8 +8,7 @@
<field name="arch" type="xml">
<graph string="Product Margins" type="bar">
<field name="product_tmpl_id"/>
<field name="turnover" operator="+"/>
<field name="total_cost" operator="+"/>
<field name="total_margin" type="measure" operator="+"/>
</graph>
</field>
</record>
@@ -74,7 +73,7 @@
<field name="sales_gap" sum="Sales Gap"/>
<field name="total_cost" sum="Total Cost"/>
<field name="purchase_num_invoiced" string="#Purchased"/>
<field name="total_margin"/>
<field name="total_margin" sum="Total Margin"/>
<field name="expected_margin"/>
<field name="total_margin_rate" widget="progressbar"/>
<field name="expected_margin_rate" widget="progressbar"/>