Skip to content

Commit 727919a

Browse files
committed
Fixup relational import
1 parent 3173b8f commit 727919a

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/odoo_data_flow/lib/relational_import.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -281,15 +281,18 @@ def _derive_relation_info(
281281
"""
282282
# Hardcoded mappings for known self-referencing fields
283283
known_self_referencing_fields = {
284-
('product.template', 'optional_product_ids'): ('product_optional_rel', 'product_template_id'),
284+
("product.template", "optional_product_ids"): (
285+
"product_optional_rel",
286+
"product_template_id",
287+
),
285288
# Add more known self-referencing fields here as needed
286289
}
287-
290+
288291
# Check if we have a known mapping for this field
289292
key = (model, field)
290293
if key in known_self_referencing_fields:
291294
return known_self_referencing_fields[key]
292-
295+
293296
# Derive relation table name (typically follows pattern: model1_model2_rel)
294297
# with models sorted alphabetically for canonical naming
295298
models = sorted([model.replace(".", "_"), related_model_fk.replace(".", "_")])
@@ -893,21 +896,23 @@ def run_write_o2m_tuple_import(
893896

894897
# Filter for rows that actually have data in the o2m field
895898
# Handle both direct field names and /id suffixed field names
896-
actual_field = field
899+
actual_field_name = field
897900
if field not in source_df.columns:
898901
# Check if the field with /id suffix exists (common for relation fields)
899902
field_with_id = f"{field}/id"
900903
if field_with_id in source_df.columns:
901-
log.debug(f"Using field '{field_with_id}' instead of '{field}' for O2M filtering")
902-
actual_field = field_with_id
904+
log.debug(
905+
f"Using field '{field_with_id}' instead of '{field}' for O2M filtering"
906+
)
907+
actual_field_name = field_with_id
903908
else:
904909
log.error(
905910
f"Field '{field}' not found in source DataFrame. "
906911
f"Available columns: {list(source_df.columns)}"
907912
)
908913
return False
909-
910-
o2m_df = source_df.filter(pl.col(actual_field).is_not_null())
914+
915+
o2m_df = source_df.filter(pl.col(actual_field_name).is_not_null())
911916

912917
for record in o2m_df.iter_rows(named=True):
913918
parent_external_id = record["id"]

0 commit comments

Comments
 (0)