Browse Source

[ADD] duplicate treatment

pull/988/head
Holger Brunn 7 years ago
parent
commit
8a739e4e81
No known key found for this signature in database GPG Key ID: 1C9760FECA3AE18
  1. 3
      base_import_odoo/README.rst
  2. 16
      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
===========

16
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):
if self.env.ref('base_import_odoo.%s' % xmlid, False).exists():
new = self.env.ref('base_import_odoo.%s' % xmlid)
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)

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