refactor: pass dimension values to Gain/Loss journal

This commit is contained in:
ruthra kumar 2024-01-18 14:35:06 +05:30
parent ba5a7c8cd8
commit c44eb432a5
3 changed files with 30 additions and 9 deletions

View File

@ -508,7 +508,7 @@ class PaymentReconciliation(Document):
reconciled_entry.append(payment_details) reconciled_entry.append(payment_details)
if entry_list: if entry_list:
reconcile_against_document(entry_list, skip_ref_details_update_for_pe) reconcile_against_document(entry_list, skip_ref_details_update_for_pe, self.dimensions)
if dr_or_cr_notes: if dr_or_cr_notes:
reconcile_dr_cr_note(dr_or_cr_notes, self.company, self.dimensions) reconcile_dr_cr_note(dr_or_cr_notes, self.company, self.dimensions)

View File

@ -453,7 +453,19 @@ def add_cc(args=None):
return cc.name return cc.name
def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # nosemgrep def _build_dimensions_dict_for_exc_gain_loss(
entry: dict | object = None, active_dimensions: list = None
):
dimensions_dict = frappe._dict()
if entry and active_dimensions:
for dim in active_dimensions:
dimensions_dict[dim.fieldname] = entry.get(dim.fieldname)
return dimensions_dict
def reconcile_against_document(
args, skip_ref_details_update_for_pe=False, active_dimensions=None
): # nosemgrep
""" """
Cancel PE or JV, Update against document, split if required and resubmit Cancel PE or JV, Update against document, split if required and resubmit
""" """
@ -482,6 +494,8 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
check_if_advance_entry_modified(entry) check_if_advance_entry_modified(entry)
validate_allocated_amount(entry) validate_allocated_amount(entry)
dimensions_dict = _build_dimensions_dict_for_exc_gain_loss(entry, active_dimensions)
# update ref in advance entry # update ref in advance entry
if voucher_type == "Journal Entry": if voucher_type == "Journal Entry":
referenced_row = update_reference_in_journal_entry(entry, doc, do_not_save=False) referenced_row = update_reference_in_journal_entry(entry, doc, do_not_save=False)
@ -489,10 +503,14 @@ def reconcile_against_document(args, skip_ref_details_update_for_pe=False): # n
# amount and account in args # amount and account in args
# referenced_row is used to deduplicate gain/loss journal # referenced_row is used to deduplicate gain/loss journal
entry.update({"referenced_row": referenced_row}) entry.update({"referenced_row": referenced_row})
doc.make_exchange_gain_loss_journal([entry]) doc.make_exchange_gain_loss_journal([entry], dimensions_dict)
else: else:
referenced_row = update_reference_in_payment_entry( referenced_row = update_reference_in_payment_entry(
entry, doc, do_not_save=True, skip_ref_details_update_for_pe=skip_ref_details_update_for_pe entry,
doc,
do_not_save=True,
skip_ref_details_update_for_pe=skip_ref_details_update_for_pe,
dimensions_dict=dimensions_dict,
) )
doc.save(ignore_permissions=True) doc.save(ignore_permissions=True)
@ -655,7 +673,7 @@ def update_reference_in_journal_entry(d, journal_entry, do_not_save=False):
def update_reference_in_payment_entry( def update_reference_in_payment_entry(
d, payment_entry, do_not_save=False, skip_ref_details_update_for_pe=False d, payment_entry, do_not_save=False, skip_ref_details_update_for_pe=False, dimensions_dict=None
): ):
reference_details = { reference_details = {
"reference_doctype": d.against_voucher_type, "reference_doctype": d.against_voucher_type,
@ -701,8 +719,9 @@ def update_reference_in_payment_entry(
if not skip_ref_details_update_for_pe: if not skip_ref_details_update_for_pe:
payment_entry.set_missing_ref_details() payment_entry.set_missing_ref_details()
payment_entry.set_amounts() payment_entry.set_amounts()
payment_entry.make_exchange_gain_loss_journal( payment_entry.make_exchange_gain_loss_journal(
frappe._dict({"difference_posting_date": d.difference_posting_date}) frappe._dict({"difference_posting_date": d.difference_posting_date}), dimensions_dict
) )
if not do_not_save: if not do_not_save:

View File

@ -1220,7 +1220,9 @@ class AccountsController(TransactionBase):
return True return True
return False return False
def make_exchange_gain_loss_journal(self, args: dict = None) -> None: def make_exchange_gain_loss_journal(
self, args: dict = None, dimensions_dict: dict = None
) -> None:
""" """
Make Exchange Gain/Loss journal for Invoices and Payments Make Exchange Gain/Loss journal for Invoices and Payments
""" """
@ -1275,7 +1277,7 @@ class AccountsController(TransactionBase):
self.name, self.name,
arg.get("referenced_row"), arg.get("referenced_row"),
arg.get("cost_center"), arg.get("cost_center"),
{}, dimensions_dict,
) )
frappe.msgprint( frappe.msgprint(
_("Exchange Gain/Loss amount has been booked through {0}").format( _("Exchange Gain/Loss amount has been booked through {0}").format(
@ -1356,7 +1358,7 @@ class AccountsController(TransactionBase):
self.name, self.name,
d.idx, d.idx,
self.cost_center, self.cost_center,
{}, dimensions_dict,
) )
frappe.msgprint( frappe.msgprint(
_("Exchange Gain/Loss amount has been booked through {0}").format( _("Exchange Gain/Loss amount has been booked through {0}").format(