diff --git a/partner_gogocarto_export_api/__init__.py b/partner_gogocarto_export_api/__init__.py new file mode 100644 index 000000000..19240f4ea --- /dev/null +++ b/partner_gogocarto_export_api/__init__.py @@ -0,0 +1,2 @@ +from . import controllers +from . import models \ No newline at end of file diff --git a/partner_gogocarto_export_api/__manifest__.py b/partner_gogocarto_export_api/__manifest__.py new file mode 100644 index 000000000..814eb2207 --- /dev/null +++ b/partner_gogocarto_export_api/__manifest__.py @@ -0,0 +1,20 @@ +{ + 'name': 'partner_gogocarto_export_api', + 'summary': '''HTTP JSON api to send partner data for Gogocarto import''', + 'license': 'AGPL-3', + 'author': 'Lokavaluto', + 'website': 'https://lokavaluto.fr', + 'category': 'Localization', + 'version': '12.0.1.0.0', + 'depends': [ + 'base', + 'base_geolocalize' + ], + 'data': [ + 'views/gogocarto_partner.xml', + 'views/gogocarto_config_settings_view.xml', + ], + 'demo': [], + 'installable': True, + 'auto_install': False, +} diff --git a/partner_gogocarto_export_api/controllers/__init__.py b/partner_gogocarto_export_api/controllers/__init__.py new file mode 100644 index 000000000..deec4a8b8 --- /dev/null +++ b/partner_gogocarto_export_api/controllers/__init__.py @@ -0,0 +1 @@ +from . import main \ No newline at end of file diff --git a/partner_gogocarto_export_api/controllers/main.py b/partner_gogocarto_export_api/controllers/main.py new file mode 100644 index 000000000..b689bd3e1 --- /dev/null +++ b/partner_gogocarto_export_api/controllers/main.py @@ -0,0 +1,23 @@ +import json, logging + +from odoo import http, models, fields, api +from odoo.http import Response, request + +_logger = logging.getLogger(__name__) + +class PartnerGogocartojs(http.Controller): + + @http.route('/web/get_http_gogocarto_elements',methods=['GET'], type='http', csrf=False, auth="public", website=True) + def get_gogocarto_elements_http(self): + data = self._get_partner() + return Response(json.dumps(data)) + + def _get_partner(self): + data = [] + all_partner = request.env['res.partner'].sudo() + partners = all_partner.search(all_partner._get_gogocarto_domain()) + all_partner.debug_field_exported() + for partner in partners: + data.append(partner.gogocarto_serialization()) + return data + diff --git a/partner_gogocarto_export_api/models/__init__.py b/partner_gogocarto_export_api/models/__init__.py new file mode 100644 index 000000000..cf2bdc202 --- /dev/null +++ b/partner_gogocarto_export_api/models/__init__.py @@ -0,0 +1,2 @@ +from . import res_partner +from . import res_config_settings \ No newline at end of file diff --git a/partner_gogocarto_export_api/models/res_config_settings.py b/partner_gogocarto_export_api/models/res_config_settings.py new file mode 100644 index 000000000..7a070e36e --- /dev/null +++ b/partner_gogocarto_export_api/models/res_config_settings.py @@ -0,0 +1,39 @@ +# -*- coding: utf-8 -*- +import logging +from ast import literal_eval +from odoo import api, fields, models + +_logger = logging.getLogger(__name__) + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + gogocarto_map_url = fields.Char(readonly=False) + export_gogocarto_fields = fields.Many2many('ir.model.fields', 'export_field_rel', 'export_id', 'fields_id', + domain="[""('model_id', '=', 'res.partner')\ + ,('name', 'not in', ('name','partner_longitude','partner_latitude'))""]", + readonly=False) + + @api.model + def get_values(self): + res = super(ResConfigSettings, self).get_values() + ICPSudo = self.env['ir.config_parameter'].sudo() + gogocarto_map_url = ICPSudo.get_param('gogocarto_export_api.gogocarto_map_url') + export_gogocarto_fields = ICPSudo.get_param('gogocarto_export_api.export_gogocarto_fields') if ICPSudo.get_param('gogocarto_export_api.export_gogocarto_fields') else "[]" + res.update( + gogocarto_map_url=gogocarto_map_url, + export_gogocarto_fields= [(6, 0, literal_eval(export_gogocarto_fields))] + ) + return res + + @api.multi + def set_values(self): + res = super(ResConfigSettings, self).set_values() + ICPSudo = self.env['ir.config_parameter'] + ICPSudo.set_param('gogocarto_export_api.gogocarto_map_url',self.gogocarto_map_url) + ICPSudo.set_param('gogocarto_export_api.export_gogocarto_fields',self.export_gogocarto_fields.ids) + return res + + + + diff --git a/partner_gogocarto_export_api/models/res_partner.py b/partner_gogocarto_export_api/models/res_partner.py new file mode 100644 index 000000000..433d8c51b --- /dev/null +++ b/partner_gogocarto_export_api/models/res_partner.py @@ -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 \ No newline at end of file diff --git a/partner_gogocarto_export_api/readme/CONFIGURE.rst b/partner_gogocarto_export_api/readme/CONFIGURE.rst new file mode 100644 index 000000000..963dbf462 --- /dev/null +++ b/partner_gogocarto_export_api/readme/CONFIGURE.rst @@ -0,0 +1,8 @@ +Just install partner_gogocarto_export_api, all dependencies will be installed by default. + +To export partners data: + +#. Set the fields you want to export in Settings / Gogocarto. +#. Check the field *"In Gogocarto"* in the partner form view. + +And use the link *https://yourodoo.com/web/get_http_gogocarto_elements* in Gogocarto server import configuration (*https://video.colibris-outilslibres.org/videos/watch/c74fc469-c822-4ab8-82a7-a2555e49e576*) \ No newline at end of file diff --git a/partner_gogocarto_export_api/readme/CONTRIBUTORS.rst b/partner_gogocarto_export_api/readme/CONTRIBUTORS.rst new file mode 100644 index 000000000..73fcf60b1 --- /dev/null +++ b/partner_gogocarto_export_api/readme/CONTRIBUTORS.rst @@ -0,0 +1,13 @@ +* Stéphan SAINLEGER +* Chloé Migayrou +* Nicolas Jeudy +* Lokavaluto Teams + +Funders +------- + +The development of this module has been financially supported by: + +* Lokavaluto (https://lokavaluto.fr) +* Mycéliandre (https://myceliandre.fr) +* Elabore (https://elabore.coop) \ No newline at end of file diff --git a/partner_gogocarto_export_api/readme/CREDITS.rst b/partner_gogocarto_export_api/readme/CREDITS.rst new file mode 100644 index 000000000..63e6554be --- /dev/null +++ b/partner_gogocarto_export_api/readme/CREDITS.rst @@ -0,0 +1 @@ +* Lokavaluto: `Icon ` \ No newline at end of file diff --git a/partner_gogocarto_export_api/readme/DESCRIPTION.rst b/partner_gogocarto_export_api/readme/DESCRIPTION.rst new file mode 100644 index 000000000..0c284caf3 --- /dev/null +++ b/partner_gogocarto_export_api/readme/DESCRIPTION.rst @@ -0,0 +1,6 @@ +Gogocarto Export module, to export the partner data needed for a Gogocarto map. + +This module allow the users to decide: + +* the partner to be exported +* the fields exported for each partner (*name*, *partner_longitude* and *partner_lattitude* automatically exported) diff --git a/partner_gogocarto_export_api/static/description/icon.png b/partner_gogocarto_export_api/static/description/icon.png new file mode 100644 index 000000000..1092a370f Binary files /dev/null and b/partner_gogocarto_export_api/static/description/icon.png differ diff --git a/partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml b/partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml new file mode 100644 index 000000000..7591f2848 --- /dev/null +++ b/partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml @@ -0,0 +1,43 @@ + + + + res.config.settings.view.form.inherit.gogocarto + res.config.settings + + + + +
+

Gogocarto export configuration

+
+
+
+
+ URL of your Gogocarto map, to be displayed in Odoo main menu +
+
+
+
+
+
+
+
+
+
+ Partner fields to export for Gogocarto map +
+
+
+ +
+
+
+
+
+
+
+
+
+
\ No newline at end of file diff --git a/partner_gogocarto_export_api/views/gogocarto_partner.xml b/partner_gogocarto_export_api/views/gogocarto_partner.xml new file mode 100644 index 000000000..b42f95f54 --- /dev/null +++ b/partner_gogocarto_export_api/views/gogocarto_partner.xml @@ -0,0 +1,14 @@ + + + + partner.gogocarto.form + res.partner + + 300 + + + + + + + \ No newline at end of file