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: Quality Inspection Parameter migration - DuplicateEntryError due to case sensitivity #37499

Merged
merged 2 commits into from
Oct 23, 2023
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
31 changes: 16 additions & 15 deletions erpnext/patches/v13_0/convert_qi_parameter_to_link_field.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@

def execute():
frappe.reload_doc("stock", "doctype", "quality_inspection_parameter")
params = set()

# get all distinct parameters from QI readigs table
reading_params = frappe.db.get_all(
"Quality Inspection Reading", fields=["distinct specification"]
)
reading_params = [d.specification for d in reading_params]
# get all parameters from QI readings table
for (p,) in frappe.db.get_all(
"Quality Inspection Reading", fields=["specification"], as_list=True
):
params.add(p.strip())

# get all distinct parameters from QI Template as some may be unused in QI
template_params = frappe.db.get_all(
"Item Quality Inspection Parameter", fields=["distinct specification"]
)
template_params = [d.specification for d in template_params]
# get all parameters from QI Template as some may be unused in QI
for (p,) in frappe.db.get_all(
"Item Quality Inspection Parameter", fields=["specification"], as_list=True
):
params.add(p.strip())

params = list(set(reading_params + template_params))
# because db primary keys are case insensitive, so duplicates will cause an exception
params = set({x.casefold(): x for x in params}.values())

for parameter in params:
if not frappe.db.exists("Quality Inspection Parameter", parameter):
frappe.get_doc(
{"doctype": "Quality Inspection Parameter", "parameter": parameter, "description": parameter}
).insert(ignore_permissions=True)
frappe.get_doc(
{"doctype": "Quality Inspection Parameter", "parameter": parameter, "description": parameter}
).insert(ignore_permissions=True)
Loading