Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: use bulk insert to ignore validations (backport #2826) #2840

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading