From 4448e1a36020955d0942c19a7ed08800d17a0202 Mon Sep 17 00:00:00 2001 From: Ninad1306 Date: Mon, 9 Dec 2024 14:09:23 +0530 Subject: [PATCH] fix: use bulk insert to ignore validations --- .../v15/migrate_boe_taxes_to_ic_taxes.py | 23 +++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/india_compliance/patches/v15/migrate_boe_taxes_to_ic_taxes.py b/india_compliance/patches/v15/migrate_boe_taxes_to_ic_taxes.py index ad0cbe2ea5..36f36f9161 100644 --- a/india_compliance/patches/v15/migrate_boe_taxes_to_ic_taxes.py +++ b/india_compliance/patches/v15/migrate_boe_taxes_to_ic_taxes.py @@ -1,4 +1,6 @@ import frappe +from frappe.model.document import bulk_insert +from frappe.model.naming import _generate_random_string def execute(): @@ -8,16 +10,33 @@ def execute(): boe_taxes = frappe.qb.DocType("Bill of Entry Taxes") boe_taxes_docs = frappe.qb.from_(boe_taxes).select("*").run(as_dict=True) + ic_taxes_names = set( + frappe.get_all("India Compliance Taxes and Charges", pluck="name") + ) + ic_taxes = [] + for doc in boe_taxes_docs: ic_taxes_doc = frappe.get_doc( { **doc, "doctype": "India Compliance Taxes and Charges", - "name": None, + "name": set_name(doc.name, ic_taxes_names), "base_total": doc.total, } ) - ic_taxes_doc.insert(ignore_if_duplicate=True) + + ic_taxes.append(ic_taxes_doc) + + bulk_insert("India Compliance Taxes and Charges", ic_taxes) # Drop the old table frappe.db.delete("Bill of Entry Taxes") + + +def set_name(name, names): + new_name = name + while new_name in names: + new_name = _generate_random_string(10) + + names.add(new_name) + return new_name