From 74cdfdc3acd173a3f206460843586451920fd9a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phan=20Sainl=C3=A9ger?= Date: Tue, 1 Dec 2020 15:08:44 +0100 Subject: [PATCH] Addition of _get_category_id method --- .../models/res_partner.py | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/partner_gogocarto_export_api/models/res_partner.py b/partner_gogocarto_export_api/models/res_partner.py index 433d8c51b..d930da306 100644 --- a/partner_gogocarto_export_api/models/res_partner.py +++ b/partner_gogocarto_export_api/models/res_partner.py @@ -22,6 +22,15 @@ class ResPartner(models.Model): else: return '' + def _get_category_id(self): + categories_list = '' + for category in self.category_id : + if categories_list != '': + categories_list = categories_list + ', ' + categories_list = categories_list + category.name + return categories_list + + ############################################ #region Public method for JSON Serialization @@ -40,8 +49,12 @@ class ResPartner(models.Model): for field in export_fields: if field.name == "industry_id": self._add_computed_node(element, "industry_id", self._get_industry_id_label) + elif field.name == "category_id": + _logger.warning("STEPHAN - Ajout des catégories") + self._add_computed_node(element, "category_id", self._get_category_id) else: self._add_simple_node(element, field.name) + _logger.warning("STEPHAN - Retours des éléments") return element #endregion @@ -55,10 +68,12 @@ class ResPartner(models.Model): export_fields = self.env['ir.model.fields'].search([('model_id', '=', 'res.partner'),('id','in', export_field_ids)]) return export_fields + # Method to add simple fields, for which there is no process needed def _add_simple_node(self, element, fieldName): if getattr(self, fieldName): element[fieldName] = self[fieldName] + # Method to add complex fileds, for which we need a dedicated method to get the value def _add_computed_node(self, element, fieldLabel, specificMethod): element[fieldLabel] = specificMethod() #endregion