Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[14.0][FIX] connector_importer: skip_fields_unchanged #136

Open
wants to merge 1 commit into
base: 14.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should probably use field's convert_to_read w/ use_name_get=False

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):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks for adding a test! 🤝

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)})
Loading