Skip to content

Commit 0914ff5

Browse files
committed
Revert "Add field type conversion to handle Odoo version differences (float to int)"
This reverts commit cee856c.
1 parent 9212291 commit 0914ff5

File tree

1 file changed

+0
-121
lines changed

1 file changed

+0
-121
lines changed

src/odoo_data_flow/import_threaded.py

Lines changed: 0 additions & 121 deletions
Original file line numberDiff line numberDiff line change
@@ -523,25 +523,6 @@ def _process_external_id_fields(
523523
return converted_vals, external_id_fields
524524

525525

526-
def _convert_field_types(
527-
model: Any,
528-
clean_vals: dict[str, Any],
529-
) -> dict[str, Any]:
530-
"""Skip field type conversion - let Odoo handle it internally.
531-
532-
Args:
533-
model: The Odoo model object
534-
clean_vals: Dictionary of clean field values
535-
536-
Returns:
537-
Dictionary with original values (no type conversion applied)
538-
"""
539-
# Skip type conversion entirely - let Odoo handle it internally
540-
# This prevents the "tuple index out of range" error that can occur
541-
# when pre-converted types confuse Odoo's internal processing
542-
return clean_vals
543-
544-
545526
def _handle_create_error(
546527
i: int,
547528
create_error: Exception,
@@ -880,108 +861,6 @@ def _execute_load_batch( # noqa: C901
880861
lines_to_process = lines_to_process[chunk_size:]
881862
continue
882863

883-
# Skip type conversion for the load method - let Odoo handle it internally
884-
# The load method expects raw values and handles type conversion on its own
885-
# Converting types here can cause bulk import failures when there are type inconsistencies
886-
log.debug(
887-
f"Skipping type conversion for batch {batch_number}, using raw values for load method"
888-
)
889-
890-
# PRE-PROCESSING: Clean up field values to prevent type errors
891-
# Convert float string values like "1.0" to integers for integer fields
892-
# This prevents "tuple index out of range" errors in Odoo server processing
893-
try:
894-
# Get field metadata - _fields might be a property that needs to be called
895-
model_fields = None
896-
if hasattr(model, "_fields"):
897-
model_fields_attr = model._fields
898-
# Check if it's callable first, but be careful about the result
899-
if callable(model_fields_attr):
900-
try:
901-
# It's a method, call it to get the fields
902-
model_fields = model_fields_attr()
903-
except Exception:
904-
# If calling fails, treat it as a dictionary anyway
905-
model_fields = (
906-
model_fields_attr
907-
if (
908-
hasattr(model_fields_attr, "__iter__")
909-
and not callable(model_fields_attr)
910-
)
911-
else None
912-
)
913-
else:
914-
# It's a property/dictionary, use it directly
915-
model_fields = (
916-
model_fields_attr
917-
if (
918-
hasattr(model_fields_attr, "__iter__")
919-
and not callable(model_fields_attr)
920-
)
921-
else None
922-
)
923-
924-
if model_fields:
925-
cleaned_load_lines = []
926-
for row in load_lines:
927-
cleaned_row = []
928-
for i, value in enumerate(row):
929-
if i < len(load_header):
930-
field_name = load_header[i]
931-
clean_field_name = field_name.split("/")[
932-
0
933-
] # Handle external ID fields like 'parent_id/id'
934-
# Only attempt cleanup if we have field metadata and this field exists
935-
if clean_field_name in model_fields:
936-
field_info = model_fields[clean_field_name]
937-
field_type = (
938-
field_info.get("type")
939-
if hasattr(field_info, "get")
940-
else None
941-
)
942-
# Only clean up for integer fields
943-
if field_type in ("integer", "positive", "negative"):
944-
str_value = str(value) if value is not None else ""
945-
# Convert float string values like "1.0", "2.0" to integers
946-
if "." in str_value:
947-
try:
948-
float_val = float(str_value)
949-
if float_val.is_integer():
950-
# It's a whole number like 1.0, 2.0 - convert to int
951-
cleaned_row.append(int(float_val))
952-
else:
953-
# It's a non-integer float like 1.5 - keep original to let Odoo handle
954-
cleaned_row.append(value)
955-
except ValueError:
956-
# Not a valid float - keep original to let Odoo handle
957-
cleaned_row.append(value)
958-
elif str_value.lstrip("-").isdigit():
959-
# It's an integer string like "1", "-5" - convert to int
960-
try:
961-
cleaned_row.append(int(str_value))
962-
except ValueError:
963-
# Not a valid integer - keep original to let Odoo handle
964-
cleaned_row.append(value)
965-
else:
966-
# Not a numeric string - keep original to let Odoo handle
967-
cleaned_row.append(value)
968-
else:
969-
# For all other field types, keep original value
970-
cleaned_row.append(value)
971-
else:
972-
# If field doesn't exist in model, pass original value
973-
cleaned_row.append(value)
974-
else:
975-
# Safety check: if index doesn't match, keep original value
976-
cleaned_row.append(value)
977-
cleaned_load_lines.append(cleaned_row)
978-
load_lines = cleaned_load_lines
979-
except Exception as e:
980-
log.warning(
981-
f"Pre-processing for type conversion failed, proceeding without conversion: {e}"
982-
)
983-
# Continue with original values if pre-processing fails
984-
985864
# DEBUG: Log what we're sending to Odoo
986865
log.debug(
987866
f"Sending to Odoo - load_header (first 10): {load_header[:10]}"

0 commit comments

Comments
 (0)