From 4381749239df5db89163021a17d4ffc15662faac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thibault=20Delavall=C3=A9e?= Date: Fri, 21 Sep 2018 16:10:59 +0200 Subject: [PATCH] [IMP] digest: correctly support studio fields in digest Studio fields are prefixed by x_studio, not only x_ which are simple custom fields. This commit update the field name check to correctly include fields created through studio. As studio automatically add x_studio as prefix help is updated to tell users to only use kpi_ as prefix for their digest fields. Result will be x_studio_kpi_foo and x_studio_kpi_foo_value which are the value digest needs to run. This commit is linked to task ID 1887619. --- addons/digest/models/digest.py | 4 ++-- addons/digest/views/digest_views.xml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/addons/digest/models/digest.py b/addons/digest/models/digest.py index c7be29b15d9..d89016bd78b 100644 --- a/addons/digest/models/digest.py +++ b/addons/digest/models/digest.py @@ -51,7 +51,7 @@ class Digest(models.Model): for digest in self: kpis_values_fields = [] for field_name, field in digest._fields.items(): - if field.type == 'boolean' and (field_name.startswith('kpi_') or field_name.startswith('x_kpi_')) and digest[field_name]: + if field.type == 'boolean' and field_name.startswith(('kpi_', 'x_kpi_', 'x_studio_kpi_')) and digest[field_name]: kpis_values_fields += [field_name + '_value'] digest.available_fields = ', '.join(kpis_values_fields) @@ -112,7 +112,7 @@ class Digest(models.Model): previous_digest = self.with_context(start_date=tf[1][0], end_date=tf[1][1], company=company).sudo(user.id) kpis = {} for field_name, field in self._fields.items(): - if field.type == 'boolean' and (field_name.startswith('kpi_') or field_name.startswith('x_kpi_')) and self[field_name]: + if field.type == 'boolean' and field_name.startswith(('kpi_', 'x_kpi_', 'x_studio_kpi_')) and self[field_name]: try: compute_value = digest[field_name + '_value'] diff --git a/addons/digest/views/digest_views.xml b/addons/digest/views/digest_views.xml index 6020af0aca7..dc348837227 100644 --- a/addons/digest/views/digest_views.xml +++ b/addons/digest/views/digest_views.xml @@ -76,12 +76,12 @@
  • first create a boolean field called - x_kpi_myfield + kpi_myfield and display it in the KPI's tab;
  • then create a computed field called - x_kpi_myfield_value + kpi_myfield_value that will compute your customized KPI.