[MIG] partner_gogocarto_export_api: migrate to 18.0
Migrated from 16.0.1.0.1 following the OCA migration guidelines:
- ``with_context(force_company=...)`` replaced by ``.with_company(...)``
in the controller: the ``force_company`` context key is no longer
supported and logs a warning in 18.0.
- Settings view rewritten for the 17.0+ settings structure: the legacy
``<div class="app_settings_block">`` / ``hasclass('settings')`` anchor
is gone. The block now follows the ``<block>``/``<setting>`` idiom and
inherits ``base_setup.res_config_settings_view_form``; the
``base_setup`` dependency was added accordingly. Translatable strings
are kept verbatim so the ``fr.po`` catalog stays valid.
- Fixed the ``posiion`` -> ``position`` typo in the company form
inheritance (silently defaulted to ``inside`` since 16.0).
- Version bumped to ``18.0.1.0.0``; author normalized to a
comma-separated string (pylint manifest-author-string).
Dependencies verified on 18.0: ``jsonifier`` (OCA server-tools) still
provides ``jsonify(parser)``, ``server_action_mass_edit`` (OCA
server-ux) still provides ``ir.actions.server.mass.edit.line`` and the
core ``ir.actions.server.create_action`` used by the mass-edit record.
Verified on a local 18.0 instance: clean install, and
``GET /web/<company_id>/get_http_gogocarto_elements`` returns the
expected JSON payload (flagged partners only, unknown company yields
``[]``, no ``force_company`` warnings in logs).
This commit is contained in:
3
partner_gogocarto_export_api/models/__init__.py
Normal file
3
partner_gogocarto_export_api/models/__init__.py
Normal file
@@ -0,0 +1,3 @@
|
||||
from . import res_partner
|
||||
from . import res_config_settings
|
||||
from . import company
|
||||
13
partner_gogocarto_export_api/models/company.py
Normal file
13
partner_gogocarto_export_api/models/company.py
Normal file
@@ -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'])
|
||||
]
|
||||
)
|
||||
23
partner_gogocarto_export_api/models/res_config_settings.py
Normal file
23
partner_gogocarto_export_api/models/res_config_settings.py
Normal file
@@ -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'])
|
||||
]
|
||||
)
|
||||
49
partner_gogocarto_export_api/models/res_partner.py
Normal file
49
partner_gogocarto_export_api/models/res_partner.py
Normal file
@@ -0,0 +1,49 @@
|
||||
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",
|
||||
"html"]:
|
||||
parser.append(field.name)
|
||||
elif field.ttype in ["many2one", "one2many", "many2many"]:
|
||||
parser.append((field.name, ['id', 'name']))
|
||||
elif field.ttype == "binary":
|
||||
continue
|
||||
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
|
||||
Reference in New Issue
Block a user