Merge pull request #32478 from rtdany10/patch-23

feat(JE): trigger account field when fetched from template
diff --git a/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py b/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py
index 062d24b..fd2a2a3 100644
--- a/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py
+++ b/erpnext/patches/v14_0/migrate_remarks_from_gl_to_payment_ledger.py
@@ -3,6 +3,29 @@
 from frappe.utils import create_batch
 
 
+def remove_duplicate_entries(pl_entries):
+	unique_vouchers = set()
+	for x in pl_entries:
+		unique_vouchers.add(
+			(x.company, x.account, x.party_type, x.party, x.voucher_type, x.voucher_no, x.gle_remarks)
+		)
+
+	entries = []
+	for x in unique_vouchers:
+		entries.append(
+			frappe._dict(
+				company=x[0],
+				account=x[1],
+				party_type=x[2],
+				party=x[3],
+				voucher_type=x[4],
+				voucher_no=x[5],
+				gle_remarks=x[6],
+			)
+		)
+	return entries
+
+
 def execute():
 	if frappe.reload_doc("accounts", "doctype", "payment_ledger_entry"):
 
@@ -34,6 +57,8 @@
 			.run(as_dict=True)
 		)
 
+		pl_entries = remove_duplicate_entries(pl_entries)
+
 		if pl_entries:
 			# split into multiple batches, update and commit for each batch
 			batch_size = 1000
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 c470524..d6f9bae 100644
--- a/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
+++ b/erpnext/stock/doctype/repost_item_valuation/repost_item_valuation.py
@@ -128,6 +128,9 @@
 		if not frappe.db.exists("Repost Item Valuation", doc.name):
 			return
 
+		# This is to avoid TooManyWritesError in case of large reposts
+		frappe.db.MAX_WRITES_PER_TRANSACTION *= 4
+
 		doc.set_status("In Progress")
 		if not frappe.flags.in_test:
 			frappe.db.commit()