Compare commits

...

7 Commits

  1. 1
      partner_gogocarto_export_api/README.rst
  2. 2
      partner_gogocarto_export_api/__init__.py
  3. 23
      partner_gogocarto_export_api/__manifest__.py
  4. 1
      partner_gogocarto_export_api/controllers/__init__.py
  5. 23
      partner_gogocarto_export_api/controllers/main.py
  6. 2
      partner_gogocarto_export_api/models/__init__.py
  7. 34
      partner_gogocarto_export_api/models/res_config_settings.py
  8. 122
      partner_gogocarto_export_api/models/res_partner.py
  9. 8
      partner_gogocarto_export_api/readme/CONFIGURE.rst
  10. 13
      partner_gogocarto_export_api/readme/CONTRIBUTORS.rst
  11. 1
      partner_gogocarto_export_api/readme/CREDITS.rst
  12. 6
      partner_gogocarto_export_api/readme/DESCRIPTION.rst
  13. BIN
      partner_gogocarto_export_api/static/description/icon.png
  14. 30
      partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml
  15. 14
      partner_gogocarto_export_api/views/gogocarto_partner.xml

1
partner_gogocarto_export_api/README.rst

@ -0,0 +1 @@
This file is going to be generated by oca-gen-addon-readme.

2
partner_gogocarto_export_api/__init__.py

@ -0,0 +1,2 @@
from . import controllers
from . import models

23
partner_gogocarto_export_api/__manifest__.py

@ -0,0 +1,23 @@
{
'name': 'partner_gogocarto_export_api',
'summary': '''HTTP JSON api to send partner data for Gogocarto import''',
'license': 'AGPL-3',
'author': (
'Lokavaluto,'
'Odoo Community Association (OCA)'
),
'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,
}

1
partner_gogocarto_export_api/controllers/__init__.py

@ -0,0 +1 @@
from . import main

23
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

2
partner_gogocarto_export_api/models/__init__.py

@ -0,0 +1,2 @@
from . import res_partner
from . import res_config_settings

34
partner_gogocarto_export_api/models/res_config_settings.py

@ -0,0 +1,34 @@
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'
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','message_follower_ids','message_ids'))""]",
readonly=False)
@api.model
def get_values(self):
res = super(ResConfigSettings, self).get_values()
ICPSudo = self.env['ir.config_parameter'].sudo()
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(
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.export_gogocarto_fields',self.export_gogocarto_fields.ids)
return res

122
partner_gogocarto_export_api/models/res_partner.py

@ -0,0 +1,122 @@
from odoo import models, fields, api
from ast import literal_eval
from datetime import date, datetime
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)]
############################################
#region Public method for JSON Serialization
############################################
def gogocarto_serialization(self):
element = {}
# mandatory fields in the export
self._add_simple_node(element, "name")
self._add_simple_node(element, "partner_longitude")
self._add_simple_node(element, "partner_latitude")
# To detect the changes in the exported data compared to the previous ones, so that Gogocarto does not compute all the data for each synchronization:
self._add_computed_node(element, "write_date", self.write_date.strftime("%d-%m-%Y, %H:%M:%S"))
export_fields = self._get_export_fields()
for field in export_fields:
if field.name in ["name", "partner_longitude", "partner_latitude", "write_date"]:
continue # fields already added above
#######################################################################################
# # ADD HERE new conditions in override method to customized the fields' value exported
# elif condition1:
# self._add_simple_node(element, field.name)
# elif condition2:
# self._add_computed_node(element, field.name, self._newmethod(field)
#######################################################################################
elif field.ttype in ["boolean", "char", "integer", "monetary", "text", "selection", "float"]:
self._add_simple_node(element, field.name)
elif field.ttype == "many2one":
self._add_computed_node(element, field.name, self._get_field_value_name(field))
elif field.ttype in ["one2many", "many2many"]:
self._add_computed_node(element, field.name, self._get_field_many_values(field))
elif field.ttype == "datetime":
self._add_computed_node(element, field.name, self._get_field_datetime_value(field))
elif field.ttype == "date":
self._add_computed_node(element, field.name, self._get_field_date_value(field))
elif field.ttype == "binary":
continue # Not developped so far
# IMPROVMENT PROPOSED: export a public URL toward the bynary
elif field.ttype == "html":
continue # Not developped so far
else:
continue
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, fieldStrValue):
element[fieldLabel] = fieldStrValue
# Method to get the name of the value registered in a Many2one field
def _get_field_value_name(self, field):
if getattr(self, field.name):
return self[field.name].name
else:
return ''
# Method to get the name of the values registered in a One2many or Many2many field
def _get_field_many_values(self, field):
values_list = ''
for item in self[field.name] :
if values_list != '':
values_list = values_list + ', '
values_list = values_list + item.name
return values_list
# Method to get a datetime value in a string
def _get_field_datetime_value(self, field):
if getattr(self, field.name):
return fields.Datetime.to_datetime(self[field.name]).strftime("%d-%m-%Y, %H:%M:%S")
else:
return ""
# Method to get a date value in a string
def _get_field_date_value(self, field):
if getattr(self, field.name):
return fields.Date.to_date(self[field.name]).strftime("%d-%m-%Y")
else:
return ""
#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

8
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*)

13
partner_gogocarto_export_api/readme/CONTRIBUTORS.rst

@ -0,0 +1,13 @@
* Stéphan SAINLEGER <https://github.com/stephansainleger>
* Chloé Migayrou <https://github.com/MigayrouChloe>
* Nicolas Jeudy <https://github.com/njeudy>
* Lokavaluto Teams <https://lokavaluto.fr>
Funders
-------
The development of this module has been financially supported by:
* Lokavaluto (https://lokavaluto.fr)
* Mycéliandre (https://myceliandre.fr)
* Elabore (https://elabore.coop)

1
partner_gogocarto_export_api/readme/CREDITS.rst

@ -0,0 +1 @@
* Lokavaluto: `Icon <https://lokavaluto.fr/web/image/res.company/1/logo?unique=f3db262>`

6
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)

BIN
partner_gogocarto_export_api/static/description/icon.png

After

Width: 500  |  Height: 500  |  Size: 52 KiB

30
partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="res_config_settings_view_form_gogocarto" model="ir.ui.view">
<field name="name">res.config.settings.view.form.inherit.gogocarto</field>
<field name="model">res.config.settings</field>
<field name="priority" eval="100"/>
<field name="inherit_id" ref="base.res_config_settings_view_form"/>
<field name="arch" type="xml">
<xpath expr="//div[hasclass('settings')]" position="inside">
<div class="app_settings_block" data-string="Gogocarto" string="Gogocarto" data-key="gogocarto">
<h2>Gogocarto export configuration</h2>
<div class="row mt16 o_settings_container" id="gogocarto_selection_settings">
<div class="col-12 col-lg-6 o_setting_box" id="gogocarto_fields">
<div class="o_setting_right_pane">
<div class="text-muted">
Partner fields to export for Gogocarto map
</div>
<div class="content-group">
<div class="mt16">
<field name="export_gogocarto_fields" widget="many2many_tags" options="{'no_create': True, 'no_open': True}"/>
</div>
</div>
</div>
</div>
</div>
</div>
</xpath>
</field>
</record>
</odoo>

14
partner_gogocarto_export_api/views/gogocarto_partner.xml

@ -0,0 +1,14 @@
<?xml version="1.0" encoding="UTF-8"?>
<odoo>
<record model="ir.ui.view" id="partner_gogocarto_form_view">
<field name="name">partner.gogocarto.form</field>
<field name="model">res.partner</field>
<field name="inherit_id" ref="base.view_partner_form"/>
<field name='priority'>300</field>
<field name="arch" type="xml">
<xpath expr="//field[@name='function']" position="after">
<field name="in_gogocarto"/>
</xpath>
</field>
</record>
</odoo>
Loading…
Cancel
Save