Skip to content

Commit

Permalink
Merge pull request #43074 from frappe/mergify/bp/version-15-hotfix/pr…
Browse files Browse the repository at this point in the history
…-43070

fix: AP filter to simulate employee advance as a ledger impacting voucher (backport #43070)
  • Loading branch information
ruthra-kumar authored Sep 6, 2024
2 parents d2b2002 + cb64f90 commit c31b4e6
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 18 deletions.
5 changes: 5 additions & 0 deletions erpnext/accounts/report/accounts_payable/accounts_payable.js
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,11 @@ frappe.query_reports["Accounts Payable"] = {
label: __("In Party Currency"),
fieldtype: "Check",
},
{
fieldname: "handle_employee_advances",
label: __("Handle Employee Advances"),
fieldtype: "Check",
},
],

formatter: function (value, row, column, data, default_formatter) {
Expand Down
52 changes: 34 additions & 18 deletions erpnext/accounts/report/accounts_receivable/accounts_receivable.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,26 @@ def get_data(self):

self.build_data()

def build_voucher_dict(self, ple):
return frappe._dict(
voucher_type=ple.voucher_type,
voucher_no=ple.voucher_no,
party=ple.party,
party_account=ple.account,
posting_date=ple.posting_date,
account_currency=ple.account_currency,
remarks=ple.remarks,
invoiced=0.0,
paid=0.0,
credit_note=0.0,
outstanding=0.0,
invoiced_in_account_currency=0.0,
paid_in_account_currency=0.0,
credit_note_in_account_currency=0.0,
outstanding_in_account_currency=0.0,
cost_center=ple.cost_center,
)

def init_voucher_balance(self):
# build all keys, since we want to exclude vouchers beyond the report date
for ple in self.ple_entries:
Expand All @@ -123,24 +143,8 @@ def init_voucher_balance(self):
key = (ple.account, ple.voucher_type, ple.voucher_no, ple.party)

if key not in self.voucher_balance:
self.voucher_balance[key] = frappe._dict(
voucher_type=ple.voucher_type,
voucher_no=ple.voucher_no,
party=ple.party,
party_account=ple.account,
posting_date=ple.posting_date,
account_currency=ple.account_currency,
remarks=ple.remarks,
invoiced=0.0,
paid=0.0,
credit_note=0.0,
outstanding=0.0,
invoiced_in_account_currency=0.0,
paid_in_account_currency=0.0,
credit_note_in_account_currency=0.0,
outstanding_in_account_currency=0.0,
cost_center=ple.cost_center,
)
self.voucher_balance[key] = self.build_voucher_dict(ple)

self.get_invoices(ple)

if self.filters.get("group_by_party"):
Expand Down Expand Up @@ -208,6 +212,18 @@ def get_voucher_balance(self, ple):

row = self.voucher_balance.get(key)

# Build and use a separate row for Employee Advances.
# This allows Payments or Journals made against Emp Advance to be processed.
if (
not row
and ple.against_voucher_type == "Employee Advance"
and self.filters.handle_employee_advances
):
_d = self.build_voucher_dict(ple)
_d.voucher_type = ple.against_voucher_type
_d.voucher_no = ple.against_voucher_no
row = self.voucher_balance[key] = _d

if not row:
# no invoice, this is an invoice / stand-alone payment / credit note
if self.filters.get("ignore_accounts"):
Expand Down

0 comments on commit c31b4e6

Please sign in to comment.