fix(migration): sanitize attribute values and set clean human-readable repair variant names
This commit is contained in:
parent
0a46f77412
commit
2dfd0fc856
1 changed files with 19 additions and 11 deletions
|
|
@ -484,14 +484,19 @@ class UpsertExecutor:
|
||||||
if val:
|
if val:
|
||||||
all_attributes[key] = val
|
all_attributes[key] = val
|
||||||
|
|
||||||
|
# Filter meaningful attributes for variant display & mapping (ignore placeholders & boolean flags)
|
||||||
|
PLACEHOLDER_VALUES = {"n/a", "na", "none", "null", "-", "true", "false", "undefined"}
|
||||||
|
clean_attributes = {
|
||||||
|
k: str(v).strip() for k, v in all_attributes.items()
|
||||||
|
if v is not None and str(v).strip() and str(v).strip().lower() not in PLACEHOLDER_VALUES
|
||||||
|
and k not in ("media_key", "parent_media_key", "is_active", "is_service_booking")
|
||||||
|
}
|
||||||
|
|
||||||
if all_attributes:
|
if all_attributes:
|
||||||
# Clear previous variant_attributes links for this variant
|
# Clear previous variant_attributes links for this variant
|
||||||
db_session.query(VariantAttribute).filter(VariantAttribute.variant_id == variant.variant_id).delete()
|
db_session.query(VariantAttribute).filter(VariantAttribute.variant_id == variant.variant_id).delete()
|
||||||
|
|
||||||
for attr_name, attr_val in all_attributes.items():
|
for attr_name, attr_val in clean_attributes.items():
|
||||||
if not attr_val:
|
|
||||||
continue
|
|
||||||
|
|
||||||
attr_code = attr_name.lower().strip().replace(" ", "_").replace("-", "_")
|
attr_code = attr_name.lower().strip().replace(" ", "_").replace("-", "_")
|
||||||
|
|
||||||
# Find or Create AttributeType in Master Attributes (attribute_types)
|
# Find or Create AttributeType in Master Attributes (attribute_types)
|
||||||
|
|
@ -636,13 +641,16 @@ class UpsertExecutor:
|
||||||
db_session.add(repair_service)
|
db_session.add(repair_service)
|
||||||
db_session.flush()
|
db_session.flush()
|
||||||
|
|
||||||
rv_name = variant.sku
|
# Prefer material/quality attribute, or meaningful attribute summary, or variant/product name
|
||||||
if all_attributes:
|
material_val = clean_attributes.get("material") or clean_attributes.get("quality")
|
||||||
attr_summary = " | ".join([str(v) for k, v in all_attributes.items() if k not in ("media_key", "parent_media_key")])
|
if material_val:
|
||||||
if attr_summary:
|
rv_name = material_val
|
||||||
rv_name = attr_summary
|
elif clean_attributes:
|
||||||
if not rv_name:
|
rv_name = " | ".join(clean_attributes.values())
|
||||||
rv_name = raw_name
|
elif raw_name and raw_name.strip():
|
||||||
|
rv_name = raw_name.strip()
|
||||||
|
else:
|
||||||
|
rv_name = variant.sku or "Standard Quality"
|
||||||
|
|
||||||
rv = db_session.query(RepairVariant).filter(
|
rv = db_session.query(RepairVariant).filter(
|
||||||
RepairVariant.repair_service_id == repair_service.repair_service_id,
|
RepairVariant.repair_service_id == repair_service.repair_service_id,
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue