|
|
@ -0,0 +1,74 @@ |
|
|
|
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 '' |
|
|
|
|
|
|
|
|
|
|
|
############################################ |
|
|
|
#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) |
|
|
|
else: |
|
|
|
self._add_simple_node(element, field.name) |
|
|
|
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 |
|
|
|
|
|
|
|
def _add_simple_node(self, element, fieldName): |
|
|
|
if getattr(self, fieldName): |
|
|
|
element[fieldName] = self[fieldName] |
|
|
|
|
|
|
|
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 |