test: item-wh deduplication in reposting
diff --git a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
index c0cb2c5..ff490f8 100644
--- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
+++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
@@ -59,7 +59,7 @@
 
 	def on_submit(self):
 		self.deduplicate_similar_repost()
-		if not frappe.flags.in_test:
+		if not frappe.flags.in_test or self.flags.dont_run_in_test:
 			return
 
 		frappe.enqueue(repost, timeout=1800, queue='long',
diff --git a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py
index 7abda61..ea79572 100644
--- a/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py
+++ b/erpnext/stock/doctype/repost_item_valuation/test_repost_item_valuation.py
@@ -74,8 +74,11 @@
 			)
 
 	def test_create_item_wise_repost_item_valuation_entries(self):
-		pr = make_purchase_receipt(company="_Test Company with perpetual inventory",
-			warehouse = "Stores - TCP1", get_multiple_items = True)
+		pr = make_purchase_receipt(
+			company="_Test Company with perpetual inventory",
+			warehouse="Stores - TCP1",
+			get_multiple_items=True,
+		)
 
 		rivs = create_item_wise_repost_entries(pr.doctype, pr.name)
 		self.assertGreaterEqual(len(rivs), 2)
@@ -84,3 +87,51 @@
 		for riv in rivs:
 			self.assertEqual(riv.company, "_Test Company with perpetual inventory")
 			self.assertEqual(riv.warehouse, "Stores - TCP1")
+
+	def test_deduplication(self):
+		def _assert_status(doc, status):
+			doc.load_from_db()
+			self.assertEqual(doc.status, status)
+
+		riv_args = frappe._dict(
+			doctype="Repost Item Valuation",
+			item_code="_Test Item",
+			warehouse="_Test Warehouse - _TC",
+			based_on="Item and Warehouse",
+			voucher_type="Sales Invoice",
+			voucher_no="SI-1",
+			posting_date="2021-01-02",
+			posting_time="00:01:00",
+		)
+
+		# new repost without any duplicates
+		riv1 = frappe.get_doc(riv_args)
+		riv1.flags.dont_run_in_test = True
+		riv1.submit()
+		_assert_status(riv1, "Queued")
+		self.assertEqual(riv1.voucher_type, "Sales Invoice")  # traceability
+		self.assertEqual(riv1.voucher_no, "SI-1")
+
+		# newer than existing duplicate - riv1
+		riv2 = frappe.get_doc(riv_args.update({"posting_date": "2021-01-03"}))
+		riv2.flags.dont_run_in_test = True
+		riv2.submit()
+		_assert_status(riv2, "Skipped")
+
+		# older than exisitng duplicate - riv1
+		riv3 = frappe.get_doc(riv_args.update({"posting_date": "2021-01-01"}))
+		riv3.flags.dont_run_in_test = True
+		riv3.submit()
+		_assert_status(riv3, "Queued")
+		_assert_status(riv1, "Skipped")
+
+		# unrelated reposts, shouldn't do anything to others.
+		riv4 = frappe.get_doc(riv_args.update({"warehouse": "Stores - _TC"}))
+		riv4.flags.dont_run_in_test = True
+		riv4.submit()
+		_assert_status(riv4, "Queued")
+		_assert_status(riv3, "Queued")
+
+		# to avoid breaking other tests accidentaly
+		riv4.set_status("Skipped")
+		riv3.set_status("Skipped")