From 6e4a8ed68adef728d2bb09f4e4733ed2647279dc Mon Sep 17 00:00:00 2001 From: barredterra <14891507+barredterra@users.noreply.github.com> Date: Thu, 7 Nov 2024 17:04:45 +0100 Subject: [PATCH] fix: don't fail if record exists Resolves https://github.com/alyf-de/erpnext_germany/pull/48#issuecomment-2436286262 --- erpnext_germany/install.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/erpnext_germany/install.py b/erpnext_germany/install.py index 1ea7152..abf9d54 100644 --- a/erpnext_germany/install.py +++ b/erpnext_germany/install.py @@ -1,8 +1,11 @@ +import contextlib from csv import DictReader import frappe from frappe.custom.doctype.custom_field.custom_field import create_custom_fields from frappe.custom.doctype.property_setter.property_setter import make_property_setter +from frappe.exceptions import DuplicateEntryError + from .custom_fields import get_custom_fields @@ -32,11 +35,14 @@ def import_csv(doctype, path): reader = DictReader(csvfile) for row in reader: if frappe.db.exists(doctype, row): + # This doesn't catch all duplicates, because it expects all + # fields to match, not (only) the primary key. continue doc = frappe.new_doc(doctype) doc.update(row) - doc.insert() + with contextlib.suppress(DuplicateEntryError): + doc.insert() def make_property_setters():