Skip to content

Commit

Permalink
fix: Use bill_no instead of name as PI default Reference field
Browse files Browse the repository at this point in the history
  • Loading branch information
marination committed Jan 6, 2025
1 parent 93bc317 commit 4ea542e
Showing 1 changed file with 15 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,9 @@ def subtract_allocations(gl_account, vouchers):
This does not affect "unpaid" vouchers (e.g. unpaid invoices) since they
are never directly allocated to a Bank Transaction.
"""
rows = get_total_allocated_amount([
(voucher.get("doctype"), voucher.get("name"))
for voucher in vouchers
])
rows = get_total_allocated_amount(
[(voucher.get("doctype"), voucher.get("name")) for voucher in vouchers]
)

if not rows:
return
Expand Down Expand Up @@ -1141,6 +1140,11 @@ def get_pi_matching_query(
"""
Get matching purchase invoice query when they are also used as payment entries (is_paid)
"""
# Default to bill_no instead of name.
# "name" is passed when it is unset. Handle specific default here.
if reference_field == "name" or not reference_field:
reference_field = "bill_no"

purchase_invoice = frappe.qb.DocType("Purchase Invoice")
description = common_filters.description

Expand Down Expand Up @@ -1192,7 +1196,7 @@ def get_pi_matching_query(
ConstantColumn("Purchase Invoice").as_("doctype"),
purchase_invoice.name,
purchase_invoice.paid_amount,
purchase_invoice[reference_field or "bill_no"].as_("reference_no"),
purchase_invoice[reference_field].as_("reference_no"),
purchase_invoice.bill_date.as_("reference_date"),
purchase_invoice.supplier.as_("party"),
ConstantColumn("Supplier").as_("party_type"),
Expand Down Expand Up @@ -1230,6 +1234,11 @@ def get_unpaid_pi_matching_query(
include_only_returns: bool = False,
reference_field: str = "name",
):
# Default to bill_no instead of name.
# "name" is passed when it is unset. Handle specific default here.
if reference_field == "name" or not reference_field:
reference_field = "bill_no"

purchase_invoice = frappe.qb.DocType("Purchase Invoice")
description = common_filters.description

Expand Down Expand Up @@ -1269,7 +1278,7 @@ def get_unpaid_pi_matching_query(
ConstantColumn("Purchase Invoice").as_("doctype"),
purchase_invoice.name.as_("name"),
purchase_invoice.outstanding_amount.as_("paid_amount"),
purchase_invoice[reference_field or "name"].as_("reference_no"),
purchase_invoice[reference_field].as_("reference_no"),
purchase_invoice.bill_date.as_("reference_date"),
purchase_invoice.supplier.as_("party"),
ConstantColumn("Supplier").as_("party_type"),
Expand Down

0 comments on commit 4ea542e

Please sign in to comment.