diff options
| author | Goffin Simon <sig@odoo.com> | 2017-02-28 14:56:23 +0100 |
|---|---|---|
| committer | Goffin Simon <sig@odoo.com> | 2017-03-01 15:50:56 +0100 |
| commit | 8c55e57c7ff2bd25df6e76608f77bab1dedd26cf (patch) | |
| tree | 672f6daf3859d67369c7c987f2862dda5ccb10ad /addons/product_margin/models | |
| parent | 5d27b3d6c0d7a92796ffda5dc18c2eea2e343df5 (diff) | |
[FIX] product_margin: _compute_product_margin_fields_values
All the fields defined in model "product.product" from module product_margin
are computed and not stored with the same function which is _compute_product_margin_fields_values.
This function has a deprecated argument which is field_names and this agrument is only used in
function read_group overwritten in this module in model "product.product. This overwrite of
read_group uses a variable "fields_list" with almost all the fields defined in "product.product"
in this module (excepted: date_from, date_to and invoice_state which are read from the context).
Each time, the fields total_margin, expected_margin, total_margin_rate, expected_margin_rate,
date_from, date_to, invoice_state were needed, nothing was returned due to the empty argument
field_names passed to this method. For example, when opening product.margin.form.inherit form
view.
In old API, it works because the compute was called with the list of the fields and in new API, it is not the case.
Closes #15604
opw:709962
Diffstat (limited to 'addons/product_margin/models')
| -rw-r--r-- | addons/product_margin/models/product_product.py | 21 |
1 files changed, 7 insertions, 14 deletions
diff --git a/addons/product_margin/models/product_product.py b/addons/product_margin/models/product_product.py index ef79a2d1714..fa65e79b38e 100644 --- a/addons/product_margin/models/product_product.py +++ b/addons/product_margin/models/product_product.py @@ -85,12 +85,9 @@ class ProductProduct(models.Model): date_from = self.env.context.get('date_from', time.strftime('%Y-01-01')) date_to = self.env.context.get('date_to', time.strftime('%Y-12-31')) invoice_state = self.env.context.get('invoice_state', 'open_paid') - if 'date_from' in field_names: - res[val.id]['date_from'] = date_from - if 'date_to' in field_names: - res[val.id]['date_to'] = date_to - if 'invoice_state' in field_names: - res[val.id]['invoice_state'] = invoice_state + res[val.id]['date_from'] = date_from + res[val.id]['date_to'] = date_to + res[val.id]['invoice_state'] = invoice_state invoice_types = () states = () if invoice_state == 'paid': @@ -136,14 +133,10 @@ class ProductProduct(models.Model): res[val.id]['normal_cost'] = val.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'] - 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: - res[val.id]['total_margin_rate'] = res[val.id]['turnover'] and res[val.id]['total_margin'] * 100 / res[val.id]['turnover'] or 0.0 - if 'expected_margin_rate' in field_names: - res[val.id]['expected_margin_rate'] = res[val.id]['sale_expected'] and res[val.id]['expected_margin'] * 100 / res[val.id]['sale_expected'] or 0.0 + res[val.id]['total_margin'] = res[val.id]['turnover'] - res[val.id]['total_cost'] + res[val.id]['expected_margin'] = res[val.id]['sale_expected'] - res[val.id]['normal_cost'] + res[val.id]['total_margin_rate'] = res[val.id]['turnover'] and res[val.id]['total_margin'] * 100 / res[val.id]['turnover'] or 0.0 + res[val.id]['expected_margin_rate'] = res[val.id]['sale_expected'] and res[val.id]['expected_margin'] * 100 / res[val.id]['sale_expected'] or 0.0 for k, v in res[val.id].items(): setattr(val, k, v) return res |
