diff --git a/partner_gogocarto_export_api/.gitignore b/partner_gogocarto_export_api/.gitignore new file mode 100644 index 0000000..6da5887 --- /dev/null +++ b/partner_gogocarto_export_api/.gitignore @@ -0,0 +1,2 @@ +*.*~ +*pyc diff --git a/partner_gogocarto_export_api/README.rst b/partner_gogocarto_export_api/README.rst new file mode 100644 index 0000000..8831cdc --- /dev/null +++ b/partner_gogocarto_export_api/README.rst @@ -0,0 +1,66 @@ +============================ +partner_gogocarto_export_api +============================ + +Gogocarto Export module, to export the partner data needed for a Gogocarto map. + +This module allow the users to decide: + +* the partners to be exported +* the fields exported for each partner (*name*, *partner_longitude* and *partner_lattitude* automatically exported) + + +Installation +============ + +Use Odoo normal module installation procedure to install +``partner_gogocarto_export_api``, all dependencies will be installed by default. + +Configuration +============= + +To export partners data: + +#. Set the fields you want to export in Settings / Gogocarto. +#. Check the field *"Export to 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*) + + +Known issues / Roadmap +====================== + +None yet. + +Bug Tracker +=========== + +Bugs are tracked on `our issues website `_. In case of +trouble, please check there if your issue has already been +reported. If you spotted it first, help us smashing it by providing a +detailed and welcomed feedback. + +Credits +======= + +Contributors +------------ + +* 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) + + +Maintainer +---------- + +This module is maintained by Elabore and Lokavaluto. \ No newline at end of file diff --git a/partner_gogocarto_export_api/__init__.py b/partner_gogocarto_export_api/__init__.py new file mode 100644 index 0000000..19240f4 --- /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 0000000..010cc78 --- /dev/null +++ b/partner_gogocarto_export_api/__manifest__.py @@ -0,0 +1,27 @@ +{ + 'name': 'partner_gogocarto_export_api', + 'summary': '''HTTP JSON api to send partner data for Gogocarto import''', + 'license': 'AGPL-3', + 'author': ( + 'Lokavaluto', + 'Elabore' + ), + 'website': 'https://lokavaluto.fr', + 'category': 'Localization', + 'version': "16.0.1.0.0", + 'depends': [ + 'base', + 'contacts', + 'base_geolocalize', + 'partner_geolocalize_usability', + 'jsonifier', + ], + 'data': [ + 'views/gogocarto_partner.xml', + 'views/gogocarto_config_settings_view.xml', + 'views/res_company_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 0000000..deec4a8 --- /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 0000000..310363d --- /dev/null +++ b/partner_gogocarto_export_api/controllers/main.py @@ -0,0 +1,29 @@ +import json +import logging + +from odoo import http +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, company_id): + data = self._jsonify_get_partner(company_id) + return Response(json.dumps(data)) + + def _jsonify_get_partner(self, company_id): + PartnerSudo = request.env['res.partner'].sudo() + parser = PartnerSudo._get_gogocarto_parser(company_id) + partners = PartnerSudo.with_context(force_company=company_id).search( + PartnerSudo._get_gogocarto_domain(company_id) + ) + return partners.jsonify(parser) diff --git a/partner_gogocarto_export_api/i18n/fr.po b/partner_gogocarto_export_api/i18n/fr.po new file mode 100644 index 0000000..2f7efa3 --- /dev/null +++ b/partner_gogocarto_export_api/i18n/fr.po @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_gogocarto_export_api +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-09-12 14:05+0000\n" +"PO-Revision-Date: 2023-09-12 14:05+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Check the export on /web/{COMPANY_ID}/get_http_gogocarto_elements." +msgstr "Vérifiez l'export sur /web/{COMPANY_ID}/get_http_gogocarto_elements.\"" + +#. module: partner_gogocarto_export_api +#: model:ir.model,name:partner_gogocarto_export_api.model_res_company +msgid "Companies" +msgstr "Sociétés" + +#. module: partner_gogocarto_export_api +#: model:ir.model,name:partner_gogocarto_export_api.model_res_config_settings +msgid "Config Settings" +msgstr "Paramètres de config" + +#. module: partner_gogocarto_export_api +#: model:ir.model,name:partner_gogocarto_export_api.model_res_partner +msgid "Contact" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_company__export_gogocarto_fields +msgid "Export Gogocarto Fields" +msgstr "Champs exportés dans Gogocarto" + +#. module: partner_gogocarto_export_api +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_partner__in_gogocarto +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_users__in_gogocarto +msgid "Export to Gogocarto" +msgstr "Exporter dans Gogocarto" + +#. module: partner_gogocarto_export_api +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_config_settings__export_gogocarto_fields +msgid "GogoCarto Exported fields" +msgstr "Champs exportés dans Gogocarto" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_company_gogocarto_form_view +msgid "GogoCarto Setup" +msgstr "Gogocarto" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Gogocarto" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Gogocarto export configuration" +msgstr "Configuration de l'export Gogocarto" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Partner fields to export for Gogocarto map." +msgstr "Champs de contact à exporter vers Gogocarto." + diff --git a/partner_gogocarto_export_api/i18n/partner_gogocarto_export_api.pot b/partner_gogocarto_export_api/i18n/partner_gogocarto_export_api.pot new file mode 100644 index 0000000..d1c0682 --- /dev/null +++ b/partner_gogocarto_export_api/i18n/partner_gogocarto_export_api.pot @@ -0,0 +1,73 @@ +# Translation of Odoo Server. +# This file contains the translation of the following modules: +# * partner_gogocarto_export_api +# +msgid "" +msgstr "" +"Project-Id-Version: Odoo Server 12.0\n" +"Report-Msgid-Bugs-To: \n" +"POT-Creation-Date: 2023-09-12 14:00+0000\n" +"PO-Revision-Date: 2023-09-12 14:00+0000\n" +"Last-Translator: <>\n" +"Language-Team: \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: \n" +"Plural-Forms: \n" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Check the export on /web/{COMPANY_ID}/get_http_gogocarto_elements." +msgstr "" + +#. module: partner_gogocarto_export_api +#: model:ir.model,name:partner_gogocarto_export_api.model_res_company +msgid "Companies" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model:ir.model,name:partner_gogocarto_export_api.model_res_config_settings +msgid "Config Settings" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model:ir.model,name:partner_gogocarto_export_api.model_res_partner +msgid "Contact" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_company__export_gogocarto_fields +msgid "Export Gogocarto Fields" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_partner__in_gogocarto +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_users__in_gogocarto +msgid "Export to Gogocarto" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model:ir.model.fields,field_description:partner_gogocarto_export_api.field_res_config_settings__export_gogocarto_fields +msgid "GogoCarto Exported fields" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_company_gogocarto_form_view +msgid "GogoCarto Setup" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Gogocarto" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Gogocarto export configuration" +msgstr "" + +#. module: partner_gogocarto_export_api +#: model_terms:ir.ui.view,arch_db:partner_gogocarto_export_api.res_config_settings_view_form_gogocarto +msgid "Partner fields to export for Gogocarto map." +msgstr "" + diff --git a/partner_gogocarto_export_api/models/__init__.py b/partner_gogocarto_export_api/models/__init__.py new file mode 100644 index 0000000..edf0517 --- /dev/null +++ b/partner_gogocarto_export_api/models/__init__.py @@ -0,0 +1,3 @@ +from . import res_partner +from . import res_config_settings +from . import company diff --git a/partner_gogocarto_export_api/models/company.py b/partner_gogocarto_export_api/models/company.py new file mode 100644 index 0000000..8b4d39e --- /dev/null +++ b/partner_gogocarto_export_api/models/company.py @@ -0,0 +1,13 @@ +from odoo import models, fields + + +class Company(models.Model): + _inherit = "res.company" + + export_gogocarto_fields = fields.Many2many( + 'ir.model.fields', + domain=[ + ('model_id', '=', 'res.partner'), + ('name', 'not in', ['id', 'name', 'partner_longitude', 'partner_latitude']) + ] + ) 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 0000000..3a8a794 --- /dev/null +++ b/partner_gogocarto_export_api/models/res_config_settings.py @@ -0,0 +1,23 @@ +import logging +from odoo import fields, models + + +_logger = logging.getLogger(__name__) + + +class ResConfigSettings(models.TransientModel): + _inherit = 'res.config.settings' + + export_gogocarto_fields = fields.Many2many( + related='company_id.export_gogocarto_fields', + relation='ir.model.fields', + string='GogoCarto Exported fields', + readonly=False, + domain=[ + ('model_id', '=', 'res.partner'), + ('name', 'not in', ['name', + 'partner_longitude', + 'partner_latitude', + 'id']) + ] + ) 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 0000000..b91c71a --- /dev/null +++ b/partner_gogocarto_export_api/models/res_partner.py @@ -0,0 +1,50 @@ +from odoo import models, fields + + +class ResPartner(models.Model): + """ Inherits partner, adds Gogocarto fields in the partner form, and functions""" + _inherit = 'res.partner' + + in_gogocarto = fields.Boolean('Export to Gogocarto') + + def _get_gogocarto_domain(self, company_id): + # To OVERRIDE in sub_modules to customize the partner selection + return [('in_gogocarto', '=', True)] + + def _get_generic_parser(self, fields): + parser = [] + for field in fields: + if field.ttype in [ + "boolean", + "char", + "integer", + "monetary", + "text", + "selection", + "float", + "date_time", + "date"]: + parser.append(field.name) + elif field.ttype in ["many2one", "one2many", "many2many"]: + parser.append((field.name, ['id', 'name'])) + elif field.ttype == "binary": + continue + elif field.ttype == "html": + continue # Not developped so far + else: + continue + return parser + + def _get_gogocarto_parser(self, company_id): + fields = self._get_export_fields(company_id) + parser = self._get_generic_parser(fields) + return parser + + def _get_export_fields(self, company_id): + CompanySudo = self.env['res.company'].sudo().search([('id', '=', company_id)]) + default_fields = self.env['ir.model.fields'].sudo().search([ + ('model_id', '=', 'res.partner'), + ('name', 'in', ['id', 'name', 'partner_longitude', 'partner_latitude'])]) + company_fields = CompanySudo.export_gogocarto_fields + export_fields = default_fields | company_fields + return export_fields 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 0000000..1092a37 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 0000000..933318d --- /dev/null +++ b/partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml @@ -0,0 +1,37 @@ + + + + res.config.settings.view.form.inherit.gogocarto + res.config.settings + + + + +
+

Gogocarto export configuration

+
+ Check the export on /web/{COMPANY_ID}/get_http_gogocarto_elements. +
+
+ +
+
+
+ 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 0000000..d0481f0 --- /dev/null +++ b/partner_gogocarto_export_api/views/gogocarto_partner.xml @@ -0,0 +1,14 @@ + + + + partner.gogocarto.form + res.partner + + 99 + + + + + + + \ No newline at end of file diff --git a/partner_gogocarto_export_api/views/res_company_view.xml b/partner_gogocarto_export_api/views/res_company_view.xml new file mode 100644 index 0000000..29fdc6b --- /dev/null +++ b/partner_gogocarto_export_api/views/res_company_view.xml @@ -0,0 +1,18 @@ + + + + res_company.gogocarto.form + res.company + + 99 + + + + + + + + + + +