refactor: Credit Note and its Exc gain/loss JE inherits dimensions

This commit is contained in:
ruthra kumar 2024-01-15 16:13:26 +05:30
parent 0ec17590ae
commit ab939cc6e8
2 changed files with 26 additions and 11 deletions

View File

@ -458,8 +458,15 @@ class PaymentReconciliation(Document):
row = self.append("allocation", {}) row = self.append("allocation", {})
row.update(entry) 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): def get_allocated_entry(self, pay, inv, allocated_amount):
return frappe._dict( res = frappe._dict(
{ {
"reference_type": pay.get("reference_type"), "reference_type": pay.get("reference_type"),
"reference_name": pay.get("reference_name"), "reference_name": pay.get("reference_name"),
@ -475,6 +482,9 @@ class PaymentReconciliation(Document):
} }
) )
res = self.update_dimension_values_in_allocated_entries(res)
return res
def reconcile_allocations(self, skip_ref_details_update_for_pe=False): def reconcile_allocations(self, skip_ref_details_update_for_pe=False):
adjust_allocations_for_taxes(self) adjust_allocations_for_taxes(self)
dr_or_cr = ( dr_or_cr = (
@ -500,7 +510,7 @@ class PaymentReconciliation(Document):
reconcile_against_document(entry_list, skip_ref_details_update_for_pe) reconcile_against_document(entry_list, skip_ref_details_update_for_pe)
if dr_or_cr_notes: 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() @frappe.whitelist()
def reconcile(self): def reconcile(self):
@ -552,12 +562,10 @@ class PaymentReconciliation(Document):
} }
) )
dimensions_dict = {}
for x in self.dimensions: for x in self.dimensions:
if row.get(x.fieldname): 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 return payment_details
def check_mandatory_to_fetch(self): def check_mandatory_to_fetch(self):
@ -720,7 +728,7 @@ class PaymentReconciliation(Document):
return conditions 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: for inv in dr_cr_notes:
voucher_type = "Credit Note" if inv.voucher_type == "Sales Invoice" else "Debit Note" voucher_type = "Credit Note" if inv.voucher_type == "Sales Invoice" else "Debit Note"
@ -770,6 +778,15 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
} }
) )
# 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_mandatory = True
jv.flags.ignore_exchange_rate = True jv.flags.ignore_exchange_rate = True
jv.remark = None jv.remark = None
@ -803,7 +820,7 @@ def reconcile_dr_cr_note(dr_cr_notes, company):
inv.against_voucher, inv.against_voucher,
None, None,
inv.cost_center, inv.cost_center,
frappe._dict(), dimensions_dict,
) )

View File

@ -2046,8 +2046,6 @@ def create_gain_loss_journal(
cost_center, cost_center,
dimensions, dimensions,
) -> str: ) -> str:
# TODO: pass dimensions to Journal
journal_entry = frappe.new_doc("Journal Entry") journal_entry = frappe.new_doc("Journal Entry")
journal_entry.voucher_type = "Exchange Gain Or Loss" journal_entry.voucher_type = "Exchange Gain Or Loss"
journal_entry.company = company journal_entry.company = company
@ -2080,7 +2078,7 @@ def create_gain_loss_journal(
dr_or_cr + "_in_account_currency": 0, dr_or_cr + "_in_account_currency": 0,
} }
) )
journal_account.update(dimensions)
journal_entry.append("accounts", journal_account) journal_entry.append("accounts", journal_account)
journal_account = frappe._dict( journal_account = frappe._dict(
@ -2096,7 +2094,7 @@ def create_gain_loss_journal(
reverse_dr_or_cr: abs(exc_gain_loss), reverse_dr_or_cr: abs(exc_gain_loss),
} }
) )
journal_account.update(dimensions)
journal_entry.append("accounts", journal_account) journal_entry.append("accounts", journal_account)
journal_entry.save() journal_entry.save()