Skip to content

Commit

Permalink
fix: use bulk insert to ignore validations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ninad1306 authored and vorasmit committed Dec 12, 2024
1 parent 6265581 commit 4448e1a
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions india_compliance/patches/v15/migrate_boe_taxes_to_ic_taxes.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import frappe
from frappe.model.document import bulk_insert
from frappe.model.naming import _generate_random_string


def execute():
Expand All @@ -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

0 comments on commit 4448e1a

Please sign in to comment.