|
|
from odoo import models, fields, api from ast import literal_eval import logging _logger = logging.getLogger(__name__)
class ResPartner(models.Model): """ Inherits partner, adds Gogocarto fields in the partner form, and functions""" _inherit = 'res.partner'
in_gogocarto = fields.Boolean('In gogocarto') def _get_gogocarto_domain(self): # To OVERRIDE in sub_modules to customize the partner selection return [('in_gogocarto','=',True) ,('partner_longitude', '!=', float()) ,('partner_latitude', '!=', float()) ] def _get_industry_label(self): if self.industry_id: return self.industry_id.name 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 ############################################ def gogocarto_serialization(self): element = {}
self._add_simple_node(element, "name") self._add_simple_node(element, "partner_longitude") self._add_simple_node(element, "partner_latitude")
return self.add_fields(element, self._get_export_fields())
def add_fields(self, element, export_fields): # To OVERRIDE in sub_modules to customize the fields content 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
############################################ #region Private method to JSON Serialization ############################################ def _get_export_fields(self): ICPSudo = self.env['ir.config_parameter'].sudo() export_field_ids = literal_eval(ICPSudo.get_param('gogocarto_export_api.export_gogocarto_fields')) 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
################################################# #region Public method to debug JSON Serialization ################################################# def debug_field_exported(self): _logger.debug("List of field exported for gogoCarto:") for field in self._get_export_fields(): _logger.debug(field.name) #endregion
|