Skip to content

Commit

Permalink
[FIX] connector_importer: skip_fields_unchanged
Browse files Browse the repository at this point in the history
  • Loading branch information
raumschmiede-joshuaL committed Jun 21, 2024
1 parent 363a0b1 commit 952d043
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
6 changes: 4 additions & 2 deletions connector_importer/components/odoorecord.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
28 changes: 28 additions & 0 deletions connector_importer/tests/test_record_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)})

0 comments on commit 952d043

Please sign in to comment.