fix: ignore duplicates explicitly
diff --git a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py
index 72b6893..d84b8e0 100644
--- a/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py
+++ b/erpnext/accounts/doctype/bank_transaction/test_bank_transaction.py
@@ -109,7 +109,7 @@
 		frappe.get_doc({
 			"doctype": "Bank",
 			"bank_name":bank_name,
-		}).insert()
+		}).insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 
@@ -119,7 +119,7 @@
 			"account_name":"Checking Account",
 			"bank": bank_name,
 			"account": account_name
-		}).insert()
+		}).insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 
@@ -184,7 +184,7 @@
 			"supplier_group":"All Supplier Groups",
 			"supplier_type": "Company",
 			"supplier_name": "Conrad Electronic"
-		}).insert()
+		}).insert(ignore_if_duplicate=True)
 
 	except frappe.DuplicateEntryError:
 		pass
@@ -203,7 +203,7 @@
 			"supplier_group":"All Supplier Groups",
 			"supplier_type": "Company",
 			"supplier_name": "Mr G"
-		}).insert()
+		}).insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 
@@ -227,7 +227,7 @@
 			"supplier_group":"All Supplier Groups",
 			"supplier_type": "Company",
 			"supplier_name": "Poore Simon's"
-		}).insert()
+		}).insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 
@@ -237,7 +237,7 @@
 			"customer_group":"All Customer Groups",
 			"customer_type": "Company",
 			"customer_name": "Poore Simon's"
-		}).insert()
+		}).insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 
@@ -266,7 +266,7 @@
 			"customer_group":"All Customer Groups",
 			"customer_type": "Company",
 			"customer_name": "Fayva"
-		}).insert()
+		}).insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 
diff --git a/erpnext/accounts/report/tax_detail/test_tax_detail.py b/erpnext/accounts/report/tax_detail/test_tax_detail.py
index bf668ab..621de82 100644
--- a/erpnext/accounts/report/tax_detail/test_tax_detail.py
+++ b/erpnext/accounts/report/tax_detail/test_tax_detail.py
@@ -61,7 +61,7 @@
 					# Create GL Entries:
 					db_doc.submit()
 				else:
-					db_doc.insert()
+					db_doc.insert(ignore_if_duplicate=True)
 			except frappe.exceptions.DuplicateEntryError:
 				pass
 
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index 39e84e3..b17b90b 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -847,7 +847,7 @@
 			"payment_account": bank_account.name,
 			"currency": bank_account.account_currency,
 			"payment_channel": payment_channel
-		}).insert(ignore_permissions=True)
+		}).insert(ignore_permissions=True, ignore_if_duplicate=True)
 
 	except frappe.DuplicateEntryError:
 		# already exists, due to a reinstall?
diff --git a/erpnext/assets/doctype/asset/test_asset.py b/erpnext/assets/doctype/asset/test_asset.py
index ddbff89..ffd1065 100644
--- a/erpnext/assets/doctype/asset/test_asset.py
+++ b/erpnext/assets/doctype/asset/test_asset.py
@@ -1280,7 +1280,7 @@
 
 	if not args.do_not_save:
 		try:
-			asset.save()
+			asset.insert(ignore_if_duplicate=True)
 		except frappe.DuplicateEntryError:
 			pass
 
@@ -1321,7 +1321,7 @@
 			"is_grouped_asset": is_grouped_asset,
 			"asset_naming_series": naming_series
 		})
-		item.insert()
+		item.insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 	return item
diff --git a/erpnext/assets/doctype/asset_category/test_asset_category.py b/erpnext/assets/doctype/asset_category/test_asset_category.py
index 3d19fa3..2f52248 100644
--- a/erpnext/assets/doctype/asset_category/test_asset_category.py
+++ b/erpnext/assets/doctype/asset_category/test_asset_category.py
@@ -23,7 +23,7 @@
 		})
 
 		try:
-			asset_category.insert()
+			asset_category.insert(ignore_if_duplicate=True)
 		except frappe.DuplicateEntryError:
 			pass
 
diff --git a/erpnext/buying/doctype/supplier/test_supplier.py b/erpnext/buying/doctype/supplier/test_supplier.py
index 13fe9df..0fb81b2 100644
--- a/erpnext/buying/doctype/supplier/test_supplier.py
+++ b/erpnext/buying/doctype/supplier/test_supplier.py
@@ -14,151 +14,150 @@
 
 
 class TestSupplier(unittest.TestCase):
-    def test_get_supplier_group_details(self):
-        doc = frappe.new_doc("Supplier Group")
-        doc.supplier_group_name = "_Testing Supplier Group"
-        doc.payment_terms = "_Test Payment Term Template 3"
-        doc.accounts = []
-        test_account_details = {
-            "company": "_Test Company",
-            "account": "Creditors - _TC",
-        }
-        doc.append("accounts", test_account_details)
-        doc.save()
-        s_doc = frappe.new_doc("Supplier")
-        s_doc.supplier_name = "Testing Supplier"
-        s_doc.supplier_group = "_Testing Supplier Group"
-        s_doc.payment_terms = ""
-        s_doc.accounts = []
-        s_doc.insert()
-        s_doc.get_supplier_group_details()
-        self.assertEqual(s_doc.payment_terms, "_Test Payment Term Template 3")
-        self.assertEqual(s_doc.accounts[0].company, "_Test Company")
-        self.assertEqual(s_doc.accounts[0].account, "Creditors - _TC")
-        s_doc.delete()
-        doc.delete()
+	def test_get_supplier_group_details(self):
+		doc = frappe.new_doc("Supplier Group")
+		doc.supplier_group_name = "_Testing Supplier Group"
+		doc.payment_terms = "_Test Payment Term Template 3"
+		doc.accounts = []
+		test_account_details = {
+			"company": "_Test Company",
+			"account": "Creditors - _TC",
+		}
+		doc.append("accounts", test_account_details)
+		doc.save()
+		s_doc = frappe.new_doc("Supplier")
+		s_doc.supplier_name = "Testing Supplier"
+		s_doc.supplier_group = "_Testing Supplier Group"
+		s_doc.payment_terms = ""
+		s_doc.accounts = []
+		s_doc.insert()
+		s_doc.get_supplier_group_details()
+		self.assertEqual(s_doc.payment_terms, "_Test Payment Term Template 3")
+		self.assertEqual(s_doc.accounts[0].company, "_Test Company")
+		self.assertEqual(s_doc.accounts[0].account, "Creditors - _TC")
+		s_doc.delete()
+		doc.delete()
 
-    def test_supplier_default_payment_terms(self):
-        # Payment Term based on Days after invoice date
-        frappe.db.set_value(
-            "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 3")
+	def test_supplier_default_payment_terms(self):
+		# Payment Term based on Days after invoice date
+		frappe.db.set_value(
+			"Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 3")
 
-        due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
-        self.assertEqual(due_date, "2016-02-21")
+		due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
+		self.assertEqual(due_date, "2016-02-21")
 
-        due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
-        self.assertEqual(due_date, "2017-02-21")
+		due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
+		self.assertEqual(due_date, "2017-02-21")
 
-        # Payment Term based on last day of month
-        frappe.db.set_value(
-            "Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 1")
+		# Payment Term based on last day of month
+		frappe.db.set_value(
+			"Supplier", "_Test Supplier With Template 1", "payment_terms", "_Test Payment Term Template 1")
 
-        due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
-        self.assertEqual(due_date, "2016-02-29")
+		due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
+		self.assertEqual(due_date, "2016-02-29")
 
-        due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
-        self.assertEqual(due_date, "2017-02-28")
+		due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
+		self.assertEqual(due_date, "2017-02-28")
 
-        frappe.db.set_value("Supplier", "_Test Supplier With Template 1", "payment_terms", "")
+		frappe.db.set_value("Supplier", "_Test Supplier With Template 1", "payment_terms", "")
 
-        # Set credit limit for the supplier group instead of supplier and evaluate the due date
-        frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 3")
+		# Set credit limit for the supplier group instead of supplier and evaluate the due date
+		frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 3")
 
-        due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
-        self.assertEqual(due_date, "2016-02-21")
+		due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
+		self.assertEqual(due_date, "2016-02-21")
 
-        # Payment terms for Supplier Group instead of supplier and evaluate the due date
-        frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 1")
+		# Payment terms for Supplier Group instead of supplier and evaluate the due date
+		frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "_Test Payment Term Template 1")
 
-        # Leap year
-        due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
-        self.assertEqual(due_date, "2016-02-29")
-        # # Non Leap year
-        due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
-        self.assertEqual(due_date, "2017-02-28")
+		# Leap year
+		due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier With Template 1")
+		self.assertEqual(due_date, "2016-02-29")
+		# # Non Leap year
+		due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier With Template 1")
+		self.assertEqual(due_date, "2017-02-28")
 
-        # Supplier with no default Payment Terms Template
-        frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "")
-        frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", "")
+		# Supplier with no default Payment Terms Template
+		frappe.db.set_value("Supplier Group", "_Test Supplier Group", "payment_terms", "")
+		frappe.db.set_value("Supplier", "_Test Supplier", "payment_terms", "")
 
-        due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier")
-        self.assertEqual(due_date, "2016-01-22")
-        # # Non Leap year
-        due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier")
-        self.assertEqual(due_date, "2017-01-22")
+		due_date = get_due_date("2016-01-22", "Supplier", "_Test Supplier")
+		self.assertEqual(due_date, "2016-01-22")
+		# # Non Leap year
+		due_date = get_due_date("2017-01-22", "Supplier", "_Test Supplier")
+		self.assertEqual(due_date, "2017-01-22")
 
-    def test_supplier_disabled(self):
-        make_test_records("Item")
+	def test_supplier_disabled(self):
+		make_test_records("Item")
 
-        frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 1)
+		frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 1)
 
-        from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
+		from erpnext.buying.doctype.purchase_order.test_purchase_order import create_purchase_order
 
-        po = create_purchase_order(do_not_save=True)
+		po = create_purchase_order(do_not_save=True)
 
-        self.assertRaises(PartyDisabled, po.save)
+		self.assertRaises(PartyDisabled, po.save)
 
-        frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 0)
+		frappe.db.set_value("Supplier", "_Test Supplier", "disabled", 0)
 
-        po.save()
+		po.save()
 
-    def test_supplier_country(self):
-        # Test that country field exists in Supplier DocType
-        supplier = frappe.get_doc('Supplier', '_Test Supplier with Country')
-        self.assertTrue('country' in supplier.as_dict())
+	def test_supplier_country(self):
+		# Test that country field exists in Supplier DocType
+		supplier = frappe.get_doc('Supplier', '_Test Supplier with Country')
+		self.assertTrue('country' in supplier.as_dict())
 
-        # Test if test supplier field record is 'Greece'
-        self.assertEqual(supplier.country, "Greece")
+		# Test if test supplier field record is 'Greece'
+		self.assertEqual(supplier.country, "Greece")
 
-        # Test update Supplier instance country value
-        supplier = frappe.get_doc('Supplier', '_Test Supplier')
-        supplier.country = 'Greece'
-        supplier.save()
-        self.assertEqual(supplier.country, "Greece")
+		# Test update Supplier instance country value
+		supplier = frappe.get_doc('Supplier', '_Test Supplier')
+		supplier.country = 'Greece'
+		supplier.save()
+		self.assertEqual(supplier.country, "Greece")
 
-    def test_party_details_tax_category(self):
-        from erpnext.accounts.party import get_party_details
+	def test_party_details_tax_category(self):
+		from erpnext.accounts.party import get_party_details
 
-        frappe.delete_doc_if_exists("Address", "_Test Address With Tax Category-Billing")
+		frappe.delete_doc_if_exists("Address", "_Test Address With Tax Category-Billing")
 
-        # Tax Category without Address
-        details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier")
-        self.assertEqual(details.tax_category, "_Test Tax Category 1")
+		# Tax Category without Address
+		details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier")
+		self.assertEqual(details.tax_category, "_Test Tax Category 1")
 
-        address = frappe.get_doc(dict(
-            doctype='Address',
-            address_title='_Test Address With Tax Category',
-            tax_category='_Test Tax Category 2',
-            address_type='Billing',
-            address_line1='Station Road',
-            city='_Test City',
-            country='India',
-            links=[dict(
-                link_doctype='Supplier',
-                link_name='_Test Supplier With Tax Category'
-            )]
-        )).insert()
+		address = frappe.get_doc(dict(
+			doctype='Address',
+			address_title='_Test Address With Tax Category',
+			tax_category='_Test Tax Category 2',
+			address_type='Billing',
+			address_line1='Station Road',
+			city='_Test City',
+			country='India',
+			links=[dict(
+				link_doctype='Supplier',
+				link_name='_Test Supplier With Tax Category'
+			)]
+		)).insert()
 
-        # Tax Category with Address
-        details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier")
-        self.assertEqual(details.tax_category, "_Test Tax Category 2")
+		# Tax Category with Address
+		details = get_party_details("_Test Supplier With Tax Category", party_type="Supplier")
+		self.assertEqual(details.tax_category, "_Test Tax Category 2")
 
-        # Rollback
-        address.delete()
+		# Rollback
+		address.delete()
 
 def create_supplier(**args):
-    args = frappe._dict(args)
+	args = frappe._dict(args)
 
-    try:
-        doc = frappe.get_doc({
-            "doctype": "Supplier",
-            "supplier_name": args.supplier_name,
-            "supplier_group": args.supplier_group or "Services",
-            "supplier_type": args.supplier_type or "Company",
-            "tax_withholding_category": args.tax_withholding_category
-        }).insert()
+	if frappe.db.exists("Supplier", args.supplier_name):
+		return frappe.get_doc("Supplier", args.supplier_name)
 
-        return doc
+	doc = frappe.get_doc({
+		"doctype": "Supplier",
+		"supplier_name": args.supplier_name,
+		"supplier_group": args.supplier_group or "Services",
+		"supplier_type": args.supplier_type or "Company",
+		"tax_withholding_category": args.tax_withholding_category
+	}).insert()
 
-    except frappe.DuplicateEntryError:
-        return frappe.get_doc("Supplier", args.supplier_name)
+	return doc
diff --git a/erpnext/e_commerce/shopping_cart/test_shopping_cart.py b/erpnext/e_commerce/shopping_cart/test_shopping_cart.py
index 8519e68..6be8c94 100644
--- a/erpnext/e_commerce/shopping_cart/test_shopping_cart.py
+++ b/erpnext/e_commerce/shopping_cart/test_shopping_cart.py
@@ -175,7 +175,7 @@
 	def create_tax_rule(self):
 		tax_rule = frappe.get_test_records("Tax Rule")[0]
 		try:
-			frappe.get_doc(tax_rule).insert()
+			frappe.get_doc(tax_rule).insert(ignore_if_duplicate=True)
 		except (frappe.DuplicateEntryError, ConflictingTaxRule):
 			pass
 
diff --git a/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py b/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py
index 54ed6f7..26bd19f 100644
--- a/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py
+++ b/erpnext/erpnext_integrations/doctype/tally_migration/tally_migration.py
@@ -82,7 +82,7 @@
 				"is_private": True
 			})
 			try:
-				f.insert()
+				f.insert(ignore_if_duplicate=True)
 			except frappe.DuplicateEntryError:
 				pass
 			setattr(self, key, f.file_url)
diff --git a/erpnext/hr/doctype/employee/employee.py b/erpnext/hr/doctype/employee/employee.py
index a2df26c..6e52eb9 100755
--- a/erpnext/hr/doctype/employee/employee.py
+++ b/erpnext/hr/doctype/employee/employee.py
@@ -142,7 +142,7 @@
 						"file_url": self.image,
 						"attached_to_doctype": "User",
 						"attached_to_name": self.user_id
-					}).insert()
+					}).insert(ignore_if_duplicate=True)
 				except frappe.DuplicateEntryError:
 					# already exists
 					pass
diff --git a/erpnext/hr/doctype/exit_interview/exit_interview.py b/erpnext/hr/doctype/exit_interview/exit_interview.py
index 30e19f1..59fb2fd 100644
--- a/erpnext/hr/doctype/exit_interview/exit_interview.py
+++ b/erpnext/hr/doctype/exit_interview/exit_interview.py
@@ -128,4 +128,4 @@
 		message += _('{0} due to missing email information for employee(s): {1}').format(
 			frappe.bold('Sending Failed'), ', '.join(email_failure))
 
-	frappe.msgprint(message, title=_('Exit Questionnaire'), indicator='blue', is_minimizable=True, wide=True)
\ No newline at end of file
+	frappe.msgprint(message, title=_('Exit Questionnaire'), indicator='blue', is_minimizable=True, wide=True)
diff --git a/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py b/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
index acd50f2..abb2887 100644
--- a/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
+++ b/erpnext/hr/doctype/vehicle_log/test_vehicle_log.py
@@ -82,7 +82,7 @@
 			"vehicle_value": flt(500000)
 		})
 	try:
-		vehicle.insert()
+		vehicle.insert(ignore_if_duplicate=True)
 	except frappe.DuplicateEntryError:
 		pass
 	return license_plate
diff --git a/erpnext/portal/doctype/homepage_section/test_homepage_section.py b/erpnext/portal/doctype/homepage_section/test_homepage_section.py
index b30d983..c3be146 100644
--- a/erpnext/portal/doctype/homepage_section/test_homepage_section.py
+++ b/erpnext/portal/doctype/homepage_section/test_homepage_section.py
@@ -21,7 +21,7 @@
 					{'title': 'Card 2', 'subtitle': 'Subtitle 2', 'content': 'This is test card 2', 'image': 'test.jpg'},
 				],
 				'no_of_columns': 3
-			}).insert()
+			}).insert(ignore_if_duplicate=True)
 		except frappe.DuplicateEntryError:
 			pass
 
diff --git a/erpnext/regional/india/setup.py b/erpnext/regional/india/setup.py
index 074bd52..e835690 100644
--- a/erpnext/regional/india/setup.py
+++ b/erpnext/regional/india/setup.py
@@ -53,10 +53,7 @@
 		hsn_code.description = d["description"]
 		hsn_code.hsn_code = d[code_field]
 		hsn_code.name = d[code_field]
-		try:
-			hsn_code.db_insert()
-		except frappe.DuplicateEntryError:
-			pass
+		hsn_code.db_insert(ignore_if_duplicate=True)
 
 def add_custom_roles_for_reports():
 	for report_name in ('GST Sales Register', 'GST Purchase Register',
diff --git a/erpnext/setup/utils.py b/erpnext/setup/utils.py
index 4441bb9..a4f2207 100644
--- a/erpnext/setup/utils.py
+++ b/erpnext/setup/utils.py
@@ -155,7 +155,7 @@
 		doc = frappe.new_doc(r.get("doctype"))
 		doc.update(r)
 		try:
-			doc.insert(ignore_permissions=True)
+			doc.insert(ignore_permissions=True, ignore_if_duplicate=True)
 		except frappe.DuplicateEntryError as e:
 			# pass DuplicateEntryError and continue
 			if e.args and e.args[0]==doc.doctype and e.args[1]==doc.name:
diff --git a/erpnext/stock/doctype/batch/test_batch.py b/erpnext/stock/doctype/batch/test_batch.py
index baa0302..613dd3f 100644
--- a/erpnext/stock/doctype/batch/test_batch.py
+++ b/erpnext/stock/doctype/batch/test_batch.py
@@ -433,14 +433,13 @@
 def make_new_batch(**args):
 	args = frappe._dict(args)
 
-	try:
+	if frappe.db.exists("Batch", args.batch_id):
+		batch = frappe.get_doc("Batch", args.batch_id)
+	else:
 		batch = frappe.get_doc({
 			"doctype": "Batch",
 			"batch_id": args.batch_id,
 			"item": args.item_code,
 		}).insert()
 
-	except frappe.DuplicateEntryError:
-		batch = frappe.get_doc("Batch", args.batch_id)
-
 	return batch