|
|
@ -62,6 +62,13 @@ class ImportOdooDatabase(models.Model): |
|
|
|
status_html = fields.Html( |
|
|
|
compute='_compute_status_html', readonly=True, sanitize=False, |
|
|
|
) |
|
|
|
duplicates = fields.Selection( |
|
|
|
[ |
|
|
|
('skip', 'Skip existing'), ('overwrite', 'Overwrite existing'), |
|
|
|
('overwrite_empty', 'Overwrite empty fields'), |
|
|
|
], |
|
|
|
'Duplicate handling', default='skip', required=True, |
|
|
|
) |
|
|
|
|
|
|
|
@api.multi |
|
|
|
def action_import(self): |
|
|
@ -177,6 +184,7 @@ class ImportOdooDatabase(models.Model): |
|
|
|
context, model, data, create_dummy=False, |
|
|
|
) |
|
|
|
if (model._name, data['id']) in context.idmap: |
|
|
|
if self.duplicates == 'skip': |
|
|
|
# there's a mapping for this record, nothing to do |
|
|
|
continue |
|
|
|
data = self._run_import_map_values(context, data) |
|
|
@ -193,8 +201,14 @@ class ImportOdooDatabase(models.Model): |
|
|
|
xmlid = '%d-%s-%d' % ( |
|
|
|
self.id, model._name.replace('.', '_'), _id or 0, |
|
|
|
) |
|
|
|
if self.env.ref('base_import_odoo.%s' % xmlid, False): |
|
|
|
new = self.env.ref('base_import_odoo.%s' % xmlid) |
|
|
|
new = self.env.ref('base_import_odoo.%s' % xmlid, False) |
|
|
|
if new and new.exists(): |
|
|
|
if self.duplicates == 'overwrite_empty': |
|
|
|
record = { |
|
|
|
key: value |
|
|
|
for key, value in record.items() |
|
|
|
if not new[key] |
|
|
|
} |
|
|
|
new.with_context( |
|
|
|
**self._create_record_context(model, record) |
|
|
|
).write(record) |
|
|
@ -321,10 +335,18 @@ class ImportOdooDatabase(models.Model): |
|
|
|
continue |
|
|
|
if isinstance(record, list): |
|
|
|
record = record[0] |
|
|
|
records = model.search([ |
|
|
|
domain = [ |
|
|
|
(field.name, '=', record.get(field.name)) |
|
|
|
for field in mapping.field_ids |
|
|
|
], limit=1) |
|
|
|
if record.get(field.name) |
|
|
|
] |
|
|
|
if len(domain) < len(mapping.field_ids): |
|
|
|
# play it save, only use mapping if we really select |
|
|
|
# something specific |
|
|
|
continue |
|
|
|
records = model.with_context(active_test=False).search( |
|
|
|
domain, limit=1, |
|
|
|
) |
|
|
|
if records: |
|
|
|
_id = records.id |
|
|
|
context.idmap[(model._name, record['id'])] = _id |
|
|
|