Browse Source

[ADD] duplicate treatment

10.0
Holger Brunn 7 years ago
committed by OCA-git-bot
parent
commit
350238cdcc
  1. 3
      base_import_odoo/README.rst
  2. 30
      base_import_odoo/models/import_odoo_database.py
  3. 6
      base_import_odoo/views/import_odoo_database.xml

3
base_import_odoo/README.rst

@ -12,7 +12,7 @@ Use cases
=========
- merging databases
- one way sync (needs a bit polishing)
- one way sync
- aggregating management data from distributed systems
@ -57,6 +57,7 @@ Known issues / Roadmap
* 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
* Add duplicate handling strategy 'Overwrite older'
Bug Tracker
===========

30
base_import_odoo/models/import_odoo_database.py

@ -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

6
base_import_odoo/views/import_odoo_database.xml

@ -26,6 +26,7 @@
<field name="database" attrs="{'readonly': [('cronjob_running', '=', True)]}" />
<field name="user" attrs="{'readonly': [('cronjob_running', '=', True)]}" />
<field name="password" password="True" attrs="{'readonly': [('cronjob_running', '=', True)], 'required': [('cronjob_running', '=', False)]}" />
<field name="duplicates" />
<field name="cronjob_id" attrs="{'invisible': [('cronjob_id', '=', False)]}" />
</group>
<field name="import_line_ids" attrs="{'readonly': [('cronjob_running', '=', True)]}">
@ -64,8 +65,9 @@
});
}
</script>
<h2>Import progress</h2>
<div style="display: flex;">
<h2 t-if="object.cronjob_running">Import progress</h2>
<h2 t-if="not object.cronjob_running">Import results</h2>
<div style="display: flex; flex-flow: row wrap">
<div style="margin-right: .5em" t-foreach="object.import_line_ids" t-as="import_line">
<t t-set="model_name" t-value="import_line.model_id.model" />
<t t-set="model_display_name" t-value="import_line.model_id.name" />

Loading…
Cancel
Save