Browse Source

Creation module partner_gogocarto_export_api

partner_gogocarto
Stéphan Sainléger 4 years ago
committed by default
parent
commit
15863aedb5
  1. 2
      partner_gogocarto_export_api/__init__.py
  2. 20
      partner_gogocarto_export_api/__manifest__.py
  3. 1
      partner_gogocarto_export_api/controllers/__init__.py
  4. 23
      partner_gogocarto_export_api/controllers/main.py
  5. 2
      partner_gogocarto_export_api/models/__init__.py
  6. 39
      partner_gogocarto_export_api/models/res_config_settings.py
  7. 74
      partner_gogocarto_export_api/models/res_partner.py
  8. 8
      partner_gogocarto_export_api/readme/CONFIGURE.rst
  9. 13
      partner_gogocarto_export_api/readme/CONTRIBUTORS.rst
  10. 1
      partner_gogocarto_export_api/readme/CREDITS.rst
  11. 6
      partner_gogocarto_export_api/readme/DESCRIPTION.rst
  12. BIN
      partner_gogocarto_export_api/static/description/icon.png
  13. 43
      partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml
  14. 14
      partner_gogocarto_export_api/views/gogocarto_partner.xml

2
partner_gogocarto_export_api/__init__.py

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

20
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,
}

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

39
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

74
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

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

43
partner_gogocarto_export_api/views/gogocarto_config_settings_view.xml

@ -0,0 +1,43 @@
<?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_url">
<div class="o_setting_right_pane">
<div class="text-muted">
URL of your Gogocarto map, to be displayed in Odoo main menu
</div>
<div class="content-group">
<div class="row mt16">
<label class="col-lg-3 o_light_label" string="Map URL" for="gogocarto_map_url"/>
<field name="gogocarto_map_url"/>
</div>
</div>
</div>
</div>
<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