e-taxes settings is single doctype now
This commit is contained in:
parent
49d974f366
commit
408e55d709
|
|
@ -169,15 +169,28 @@ def restore_etaxes_from_file():
|
||||||
)
|
)
|
||||||
restored_scalars += 1
|
restored_scalars += 1
|
||||||
|
|
||||||
# Child tables → DELETE existing + INSERT from backup
|
# Child tables → update parent for existing rows + insert missing ones
|
||||||
restored_children = 0
|
restored_children = 0
|
||||||
|
old_name = backup.get("old_name", "")
|
||||||
for fieldname, rows in backup.get("children", {}).items():
|
for fieldname, rows in backup.get("children", {}).items():
|
||||||
table = CHILD_TABLES.get(fieldname)
|
table = CHILD_TABLES.get(fieldname)
|
||||||
if not table or not _sql_table_exists(table) or not rows:
|
if not table or not _sql_table_exists(table) or not rows:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
frappe.db.sql(f"DELETE FROM `{table}` WHERE parent = 'E-Taxes Settings'")
|
# First: update parent/parenttype/parentfield for ALL rows that came from old name
|
||||||
|
if old_name and old_name != "E-Taxes Settings":
|
||||||
|
frappe.db.sql(
|
||||||
|
f"UPDATE `{table}` SET parent = 'E-Taxes Settings', "
|
||||||
|
f"parenttype = 'E-Taxes Settings', parentfield = %s "
|
||||||
|
f"WHERE parent = %s",
|
||||||
|
(fieldname, old_name),
|
||||||
|
)
|
||||||
|
updated = frappe.db.sql("SELECT ROW_COUNT() as cnt")[0][0]
|
||||||
|
if updated:
|
||||||
|
print(f" {table}: updated parent for {updated} existing rows")
|
||||||
|
restored_children += updated
|
||||||
|
|
||||||
|
# Then: insert any rows that don't exist yet
|
||||||
for row in rows:
|
for row in rows:
|
||||||
row["parent"] = "E-Taxes Settings"
|
row["parent"] = "E-Taxes Settings"
|
||||||
row["parenttype"] = "E-Taxes Settings"
|
row["parenttype"] = "E-Taxes Settings"
|
||||||
|
|
@ -186,9 +199,10 @@ def restore_etaxes_from_file():
|
||||||
placeholders = ", ".join(["%s"] * len(row))
|
placeholders = ", ".join(["%s"] * len(row))
|
||||||
try:
|
try:
|
||||||
frappe.db.sql(
|
frappe.db.sql(
|
||||||
f"INSERT INTO `{table}` ({columns}) VALUES ({placeholders})",
|
f"INSERT IGNORE INTO `{table}` ({columns}) VALUES ({placeholders})",
|
||||||
list(row.values()),
|
list(row.values()),
|
||||||
)
|
)
|
||||||
|
if frappe.db.sql("SELECT ROW_COUNT() as cnt")[0][0]:
|
||||||
restored_children += 1
|
restored_children += 1
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f" Warning: failed to insert row in {table}: {e}")
|
print(f" Warning: failed to insert row in {table}: {e}")
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue