refactor: Credit Note and its Exc gain/loss JE inherits dimensions
diff --git a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
index 81601a2..be7201b 100644
--- a/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
+++ b/erpnext/accounts/doctype/payment_reconciliation/payment_reconciliation.py
@@ -458,8 +458,15 @@
row = self.append("allocation", {})
row.update(entry)
+ def update_dimension_values_in_allocated_entries(self, res):
+ for x in self.dimensions:
+ dimension = x.fieldname
+ if self.get(dimension):
+ res[dimension] = self.get(dimension)
+ return res
+
def get_allocated_entry(self, pay, inv, allocated_amount):
- return frappe._dict(
+ res = frappe._dict(
{
"reference_type": pay.get("reference_type"),
"reference_name": pay.get("reference_name"),
@@ -475,6 +482,9 @@
}
)
+ res = self.update_dimension_values_in_allocated_entries(res)
+ return res
+
def reconcile_allocations(self, skip_ref_details_update_for_pe=False):
adjust_allocations_for_taxes(self)
dr_or_cr = (
@@ -500,7 +510,7 @@
reconcile_against_document(entry_list, skip_ref_details_update_for_pe)
if dr_or_cr_notes:
- reconcile_dr_cr_note(dr_or_cr_notes, self.company)
+ reconcile_dr_cr_note(dr_or_cr_notes, self.company, self.dimensions)
@frappe.whitelist()
def reconcile(self):
@@ -552,12 +562,10 @@
}
)
- dimensions_dict = {}
for x in self.dimensions:
if row.get(x.fieldname):
- dimensions_dict.update({x.fieldname: row.get(x.fieldname)})
+ payment_details[x.fieldname] = row.get(x.fieldname)
- payment_details.update({"dimensions": dimensions_dict})
return payment_details
def check_mandatory_to_fetch(self):
@@ -720,7 +728,7 @@
return conditions
-def reconcile_dr_cr_note(dr_cr_notes, company):
+def reconcile_dr_cr_note(dr_cr_notes, company, active_dimensions=None):
for inv in dr_cr_notes:
voucher_type = "Credit Note" if inv.voucher_type == "Sales Invoice" else "Debit Note"
@@ -770,6 +778,15 @@
}
)
+ # Credit Note(JE) will inherit the same dimension values as payment
+ dimensions_dict = frappe._dict()
+ if active_dimensions:
+ for dim in active_dimensions:
+ dimensions_dict[dim.fieldname] = inv.get(dim.fieldname)
+
+ jv.accounts[0].update(dimensions_dict)
+ jv.accounts[1].update(dimensions_dict)
+
jv.flags.ignore_mandatory = True
jv.flags.ignore_exchange_rate = True
jv.remark = None
@@ -803,7 +820,7 @@
inv.against_voucher,
None,
inv.cost_center,
- frappe._dict(),
+ dimensions_dict,
)
diff --git a/erpnext/accounts/utils.py b/erpnext/accounts/utils.py
index a80cf6f..9f7e89a 100644
--- a/erpnext/accounts/utils.py
+++ b/erpnext/accounts/utils.py
@@ -2046,8 +2046,6 @@
cost_center,
dimensions,
) -> str:
- # TODO: pass dimensions to Journal
-
journal_entry = frappe.new_doc("Journal Entry")
journal_entry.voucher_type = "Exchange Gain Or Loss"
journal_entry.company = company
@@ -2080,7 +2078,7 @@
dr_or_cr + "_in_account_currency": 0,
}
)
-
+ journal_account.update(dimensions)
journal_entry.append("accounts", journal_account)
journal_account = frappe._dict(
@@ -2096,7 +2094,7 @@
reverse_dr_or_cr: abs(exc_gain_loss),
}
)
-
+ journal_account.update(dimensions)
journal_entry.append("accounts", journal_account)
journal_entry.save()