|
|
@ -0,0 +1,37 @@ |
|
|
|
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, company_id): # To OVERRIDE in sub_modules to customize the partner selection |
|
|
|
return [('in_gogocarto','=',True)] |
|
|
|
|
|
|
|
def _get_gogocarto_parser(self, company_id): |
|
|
|
parser = [] |
|
|
|
for field in self._get_export_fields(company_id): |
|
|
|
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 |
|
|
|
# use /web/image?model=res.partner&id=<id>&field=image_medium in gogocarto template |
|
|
|
elif field.ttype == "html": |
|
|
|
continue # Not developped so far |
|
|
|
else: |
|
|
|
continue |
|
|
|
return parser |
|
|
|
|
|
|
|
def _get_export_fields(self, company_id): |
|
|
|
CompanySudo = self.env['res.company'].sudo() |
|
|
|
default_fields = self.env['ir.model.fields'].sudo().search([('model_id', '=', 'res.partner'),('name', 'in', ['id', 'name','partner_longitude','partner_latitude'])]) |
|
|
|
export_fields = default_fields | CompanySudo.search([('id', '=', company_id)]).export_gogocarto_fields |
|
|
|
return export_fields |