From 98940d7147649520e7c5fd7876ba584f8c8c9c7d Mon Sep 17 00:00:00 2001 From: Holger Brunn Date: Wed, 11 Oct 2017 19:38:17 +0200 Subject: [PATCH] [IMP] community review --- base_import_odoo/README.rst | 1 + .../models/import_odoo_database.py | 21 +++++++++++-------- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/base_import_odoo/README.rst b/base_import_odoo/README.rst index 73c0fee64..fc58abb1c 100644 --- a/base_import_odoo/README.rst +++ b/base_import_odoo/README.rst @@ -53,6 +53,7 @@ Known issues / Roadmap * Yes of course this duplicates a lot of connector functionality. Rewrite this with the connector framework, probably collaborate with https://github.com/OCA/connector-odoo2odoo * Do something with workflows +* Support reference fields, while being at it refactor _run_import_map_values to call a function per field type * Probably it's safer and faster to disable recomputation during import, and recompute all fields afterwards Bug Tracker diff --git a/base_import_odoo/models/import_odoo_database.py b/base_import_odoo/models/import_odoo_database.py index 8d462bd24..50b87b982 100644 --- a/base_import_odoo/models/import_odoo_database.py +++ b/base_import_odoo/models/import_odoo_database.py @@ -1,10 +1,11 @@ # -*- coding: utf-8 -*- # © 2017 Therp BV # License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). +import logging try: from erppeek import Client except: - pass + logging.debug('Unable to import erppeek') import psycopg2 import traceback from openerp import _, api, exceptions, fields, models, tools @@ -123,12 +124,15 @@ class ImportOdooDatabase(models.Model): for model_line in self.import_line_ids: model = self.env[model_line.model_id.model] done[model._name] = 0 + chunk_len = commit and (commit_threshold or 1) or len( + remote_ids[model._name] + ) for start_index in range( - len(remote_ids[model._name]) / commit_threshold + 1 + len(remote_ids[model._name]) / chunk_len + 1 ): - index = start_index * commit_threshold - ids = remote_ids[model._name][index:index + commit_threshold] + index = start_index * chunk_len + ids = remote_ids[model._name][index:index + chunk_len] context = ImportContext( remote, model_line, ids, idmap, dummies, dummy_instances, to_delete, field_context(None, None, None), @@ -289,7 +293,7 @@ class ImportOdooDatabase(models.Model): 'id', 'not in', [ v for (model_name, remote_id), v - in context.dummies.iteritems() + in context.dummies.items() if model_name == model._name ] + [ @@ -308,12 +312,12 @@ class ImportOdooDatabase(models.Model): return dummy.id required = [ name - for name, field in model._fields.iteritems() + for name, field in model._fields.items() if field.required ] defaults = model.default_get(required) values = {'id': record['id']} - for name, field in model._fields.iteritems(): + for name, field in model._fields.items(): if name not in required or name in defaults: continue value = None @@ -338,7 +342,6 @@ class ImportOdooDatabase(models.Model): value = field.selection[0][0] elif field.type in ['selection'] and callable(field.selection): value = field.selection(model)[0][0] - # TODO: support more types, refactor to one function per type values[name] = value dummy = self._create_record(context, model, values) context.dummies[mapping_key(model._name, record['id'])] = dummy.id @@ -407,7 +410,7 @@ class ImportOdooDatabase(models.Model): return { name: field for name, field - in self.env[context.model_line.model_id.model]._fields.iteritems() + in self.env[context.model_line.model_id.model]._fields.items() if not field.compute or field.related }