refactor: split ple creation function into two

refactor create_payment_ledger_entry function into 2.
one for generating ple map and one for DB entry creation
This commit is contained in:
ruthra kumar 2022-10-13 14:13:48 +05:30
parent d794b834fd
commit 9b50221bf0

View File

@ -1368,9 +1368,8 @@ def check_and_delete_linked_reports(report):
frappe.delete_doc("Desktop Icon", icon) frappe.delete_doc("Desktop Icon", icon)
def create_payment_ledger_entry( def get_payment_ledger_entries(gl_entries, cancel=0):
gl_entries, cancel=0, adv_adj=0, update_outstanding="Yes", from_repost=0 ple_map = []
):
if gl_entries: if gl_entries:
ple = None ple = None
@ -1410,39 +1409,52 @@ def create_payment_ledger_entry(
dr_or_cr *= -1 dr_or_cr *= -1
dr_or_cr_account_currency *= -1 dr_or_cr_account_currency *= -1
ple = frappe.get_doc( ple = frappe._dict(
{ doctype="Payment Ledger Entry",
"doctype": "Payment Ledger Entry", posting_date=gle.posting_date,
"posting_date": gle.posting_date, company=gle.company,
"company": gle.company, account_type=account_type,
"account_type": account_type, account=gle.account,
"account": gle.account, party_type=gle.party_type,
"party_type": gle.party_type, party=gle.party,
"party": gle.party, cost_center=gle.cost_center,
"cost_center": gle.cost_center, finance_book=gle.finance_book,
"finance_book": gle.finance_book, due_date=gle.due_date,
"due_date": gle.due_date, voucher_type=gle.voucher_type,
"voucher_type": gle.voucher_type, voucher_no=gle.voucher_no,
"voucher_no": gle.voucher_no, against_voucher_type=gle.against_voucher_type
"against_voucher_type": gle.against_voucher_type
if gle.against_voucher_type if gle.against_voucher_type
else gle.voucher_type, else gle.voucher_type,
"against_voucher_no": gle.against_voucher if gle.against_voucher else gle.voucher_no, against_voucher_no=gle.against_voucher if gle.against_voucher else gle.voucher_no,
"account_currency": gle.account_currency, account_currency=gle.account_currency,
"amount": dr_or_cr, amount=dr_or_cr,
"amount_in_account_currency": dr_or_cr_account_currency, amount_in_account_currency=dr_or_cr_account_currency,
"delinked": True if cancel else False, delinked=True if cancel else False,
"remarks": gle.remarks, remarks=gle.remarks,
}
) )
dimensions_and_defaults = get_dimensions() dimensions_and_defaults = get_dimensions()
if dimensions_and_defaults: if dimensions_and_defaults:
for dimension in dimensions_and_defaults[0]: for dimension in dimensions_and_defaults[0]:
ple.set(dimension.fieldname, gle.get(dimension.fieldname)) ple[dimension.fieldname] = gle.get(dimension.fieldname)
ple_map.append(ple)
return ple_map
def create_payment_ledger_entry(
gl_entries, cancel=0, adv_adj=0, update_outstanding="Yes", from_repost=0
):
if gl_entries:
ple_map = get_payment_ledger_entries(gl_entries, cancel=cancel)
for entry in ple_map:
ple = frappe.get_doc(entry)
if cancel: if cancel:
delink_original_entry(ple) delink_original_entry(ple)
ple.flags.ignore_permissions = 1 ple.flags.ignore_permissions = 1
ple.flags.adv_adj = adv_adj ple.flags.adv_adj = adv_adj
ple.flags.from_repost = from_repost ple.flags.from_repost = from_repost