fix: payment entry voucher_type error (#35779)

* fix: payment entry `voucher_type` error

* chore: linters
This commit is contained in:
Dany Robert 2023-07-10 19:32:59 +05:30 committed by GitHub
parent 49c61e7ebb
commit 361a357088
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1432,6 +1432,9 @@ def get_outstanding_reference_documents(args, validate=False):
if args.get("party_type") == "Member": if args.get("party_type") == "Member":
return return
if not args.get("get_outstanding_invoices") and not args.get("get_orders_to_be_billed"):
args["get_outstanding_invoices"] = True
ple = qb.DocType("Payment Ledger Entry") ple = qb.DocType("Payment Ledger Entry")
common_filter = [] common_filter = []
accounting_dimensions_filter = [] accounting_dimensions_filter = []
@ -1626,60 +1629,59 @@ def get_orders_to_be_billed(
cost_center=None, cost_center=None,
filters=None, filters=None,
): ):
voucher_type = None
if party_type == "Customer": if party_type == "Customer":
voucher_type = "Sales Order" voucher_type = "Sales Order"
elif party_type == "Supplier": elif party_type == "Supplier":
voucher_type = "Purchase Order" voucher_type = "Purchase Order"
elif party_type == "Employee":
voucher_type = None if not voucher_type:
return []
# Add cost center condition # Add cost center condition
if voucher_type: doc = frappe.get_doc({"doctype": voucher_type})
doc = frappe.get_doc({"doctype": voucher_type}) condition = ""
condition = "" if doc and hasattr(doc, "cost_center") and doc.cost_center:
if doc and hasattr(doc, "cost_center") and doc.cost_center: condition = " and cost_center='%s'" % cost_center
condition = " and cost_center='%s'" % cost_center
orders = [] if party_account_currency == company_currency:
if voucher_type: grand_total_field = "base_grand_total"
if party_account_currency == company_currency: rounded_total_field = "base_rounded_total"
grand_total_field = "base_grand_total" else:
rounded_total_field = "base_rounded_total" grand_total_field = "grand_total"
else: rounded_total_field = "rounded_total"
grand_total_field = "grand_total"
rounded_total_field = "rounded_total"
orders = frappe.db.sql( orders = frappe.db.sql(
""" """
select select
name as voucher_no, name as voucher_no,
if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) as invoice_amount, if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) as invoice_amount,
(if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) - advance_paid) as outstanding_amount, (if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) - advance_paid) as outstanding_amount,
transaction_date as posting_date transaction_date as posting_date
from from
`tab{voucher_type}` `tab{voucher_type}`
where where
{party_type} = %s {party_type} = %s
and docstatus = 1 and docstatus = 1
and company = %s and company = %s
and ifnull(status, "") != "Closed" and ifnull(status, "") != "Closed"
and if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) > advance_paid and if({rounded_total_field}, {rounded_total_field}, {grand_total_field}) > advance_paid
and abs(100 - per_billed) > 0.01 and abs(100 - per_billed) > 0.01
{condition} {condition}
order by order by
transaction_date, name transaction_date, name
""".format( """.format(
**{ **{
"rounded_total_field": rounded_total_field, "rounded_total_field": rounded_total_field,
"grand_total_field": grand_total_field, "grand_total_field": grand_total_field,
"voucher_type": voucher_type, "voucher_type": voucher_type,
"party_type": scrub(party_type), "party_type": scrub(party_type),
"condition": condition, "condition": condition,
} }
), ),
(party, company), (party, company),
as_dict=True, as_dict=True,
) )
order_list = [] order_list = []
for d in orders: for d in orders:
@ -1712,6 +1714,8 @@ def get_negative_outstanding_invoices(
cost_center=None, cost_center=None,
condition=None, condition=None,
): ):
if party_type not in ["Customer", "Supplier"]:
return []
voucher_type = "Sales Invoice" if party_type == "Customer" else "Purchase Invoice" voucher_type = "Sales Invoice" if party_type == "Customer" else "Purchase Invoice"
account = "debit_to" if voucher_type == "Sales Invoice" else "credit_to" account = "debit_to" if voucher_type == "Sales Invoice" else "credit_to"
supplier_condition = "" supplier_condition = ""