refactor: use consistent report column names

(cherry picked from commit 6dca96b423)
This commit is contained in:
Smit Vora
2026-04-21 17:28:56 +05:30
committed by Mergify
parent dd2763aabc
commit 9276cd7343
3 changed files with 27 additions and 19 deletions

View File

@@ -46,8 +46,8 @@ def get_tax_withholding_data(filters):
party_info = party_details.get((entry.party_type, entry.party), {}) party_info = party_details.get((entry.party_type, entry.party), {})
row = { row = {
"section_code": entry.tax_withholding_category, "tax_withholding_category": entry.tax_withholding_category,
"entity_type": party_info.get("entity_type"), "party_entity_type": party_info.get("party_entity_type"),
"rate": entry.tax_rate, "rate": entry.tax_rate,
"total_amount": entry.taxable_amount, "total_amount": entry.taxable_amount,
"grand_total": doc_details.get("grand_total", 0), "grand_total": doc_details.get("grand_total", 0),
@@ -70,7 +70,11 @@ def get_tax_withholding_data(filters):
# Sort by section code, transaction date, then withholding_name for deterministic ordering # Sort by section code, transaction date, then withholding_name for deterministic ordering
data.sort( data.sort(
key=lambda x: (x["section_code"] or "", x["transaction_date"] or "", x["withholding_name"] or "") key=lambda x: (
x["tax_withholding_category"] or "",
x["transaction_date"] or "",
x["withholding_name"] or "",
)
) )
return data return data
@@ -94,9 +98,13 @@ def get_party_details(entries):
fields = [doctype.name] fields = [doctype.name]
if party_type == "Supplier": if party_type == "Supplier":
fields.extend([doctype.supplier_type.as_("entity_type"), doctype.supplier_name.as_("party_name")]) fields.extend(
[doctype.supplier_type.as_("party_entity_type"), doctype.supplier_name.as_("party_name")]
)
elif party_type == "Customer": elif party_type == "Customer":
fields.extend([doctype.customer_type.as_("entity_type"), doctype.customer_name.as_("party_name")]) fields.extend(
[doctype.customer_type.as_("party_entity_type"), doctype.customer_name.as_("party_name")]
)
query = frappe.qb.from_(doctype).select(*fields).where(doctype.name.isin(party_set)) query = frappe.qb.from_(doctype).select(*fields).where(doctype.name.isin(party_set))
party_details = query.run(as_dict=True) party_details = query.run(as_dict=True)
@@ -113,7 +121,7 @@ def get_columns(filters):
{ {
"label": _("Section Code"), "label": _("Section Code"),
"options": "Tax Withholding Category", "options": "Tax Withholding Category",
"fieldname": "section_code", "fieldname": "tax_withholding_category",
"fieldtype": "Link", "fieldtype": "Link",
"width": 90, "width": 90,
}, },
@@ -133,7 +141,7 @@ def get_columns(filters):
}, },
{ {
"label": _("Entity Type"), "label": _("Entity Type"),
"fieldname": "entity_type", "fieldname": "party_entity_type",
"fieldtype": "Data", "fieldtype": "Data",
"width": 100, "width": 100,
}, },

View File

@@ -124,7 +124,7 @@ class TestTaxWithholdingDetails(ERPNextTestSuite, AccountsTestMixin):
voucher_expected_values = expected_values[i] voucher_expected_values = expected_values[i]
voucher_actual_values = ( voucher_actual_values = (
voucher.ref_no, voucher.ref_no,
voucher.section_code, voucher.tax_withholding_category,
voucher.rate, voucher.rate,
voucher.base_total, voucher.base_total,
voucher.tax_amount, voucher.tax_amount,

View File

@@ -36,26 +36,26 @@ def group_by_party_and_category(data, filters):
for row in data: for row in data:
party_category_wise_map.setdefault( party_category_wise_map.setdefault(
(row.get("party"), row.get("section_code")), (row.get("party"), row.get("tax_withholding_category")),
{ {
"tax_id": row.get("tax_id"), "tax_id": row.get("tax_id"),
"party": row.get("party"), "party": row.get("party"),
"party_name": row.get("party_name"), "party_name": row.get("party_name"),
"section_code": row.get("section_code"), "tax_withholding_category": row.get("tax_withholding_category"),
"entity_type": row.get("entity_type"), "party_entity_type": row.get("party_entity_type"),
"rate": row.get("rate"), "rate": row.get("rate"),
"total_amount": 0.0, "total_amount": 0.0,
"tax_amount": 0.0, "tax_amount": 0.0,
}, },
) )
party_category_wise_map.get((row.get("party"), row.get("section_code")))["total_amount"] += row.get( party_category_wise_map.get((row.get("party"), row.get("tax_withholding_category")))[
"total_amount", 0.0 "total_amount"
) ] += row.get("total_amount", 0.0)
party_category_wise_map.get((row.get("party"), row.get("section_code")))["tax_amount"] += row.get( party_category_wise_map.get((row.get("party"), row.get("tax_withholding_category")))[
"tax_amount", 0.0 "tax_amount"
) ] += row.get("tax_amount", 0.0)
final_result = get_final_result(party_category_wise_map) final_result = get_final_result(party_category_wise_map)
@@ -89,13 +89,13 @@ def get_columns(filters):
{ {
"label": _("Section Code"), "label": _("Section Code"),
"options": "Tax Withholding Category", "options": "Tax Withholding Category",
"fieldname": "section_code", "fieldname": "tax_withholding_category",
"fieldtype": "Link", "fieldtype": "Link",
"width": 180, "width": 180,
}, },
{ {
"label": _("Entity Type"), "label": _("Entity Type"),
"fieldname": "entity_type", "fieldname": "party_entity_type",
"fieldtype": "Data", "fieldtype": "Data",
"width": 180, "width": 180,
}, },