diff --git a/connector_importer/components/odoorecord.py b/connector_importer/components/odoorecord.py index 5cf255e5..c6ada00e 100644 --- a/connector_importer/components/odoorecord.py +++ b/connector_importer/components/odoorecord.py @@ -229,7 +229,9 @@ def _odoo_write_purge_values(self, odoo_record, values): # remove fields having the same value field_names = tuple(values.keys()) if self.work.options.record_handler.skip_fields_unchanged: - current_values = odoo_record.read(field_names, load="_classic_write") + current_values = odoo_record.read(field_names, load="_classic_write")[0] + current_values.pop("id") for k, v in current_values.items(): - if values[k] != v: + # FIXME: New value can be "1" and existing 1. Needs field conversion + if values[k] == v: values.pop(k) diff --git a/connector_importer/tests/test_record_handler.py b/connector_importer/tests/test_record_handler.py index e35f7824..ac787bcc 100644 --- a/connector_importer/tests/test_record_handler.py +++ b/connector_importer/tests/test_record_handler.py @@ -71,3 +71,31 @@ def test_find_domain(self): self.assertEqual( domain, [("name", "=", values["name"]), ("age", "=", values["age"])] ) + + def test_odoo_write_purge_values(self): + handler = self._get_handler() + + rec = self.env.ref("base.partner_admin") + + new_credit = rec.credit_limit + 1 + vals = {"name": rec.name, "credit_limit": new_credit, "bad_key": 1} + + vals_copy = vals.copy() + handler._odoo_write_purge_values(rec, vals_copy) + # Only key bad_key must have been removed + self.assertEqual(vals_copy, {"name": rec.name, "credit_limit": new_credit}) + + handler.work.options["record_handler"] = { + "skip_fields_unchanged": True, + } + vals_copy = vals.copy() + handler._odoo_write_purge_values(rec, vals_copy) + # name is the same as the existing value, must have been removed + self.assertEqual(vals_copy, {"credit_limit": new_credit}) + + vals["credit_limit"] = str(rec.credit_limit) + vals_copy = vals.copy() + handler._odoo_write_purge_values(rec, vals_copy) + # Values are not converted to the field type when used for comparing, they + # must not be removed + self.assertEqual(vals_copy, {"credit_limit": str(rec.credit_limit)})