Skip to content

Commit

Permalink
feat: add voucher totals in tds payable report (#36568)
Browse files Browse the repository at this point in the history
* feat: voucher totals in tds payable monthly

* fix: naming series column in tds payable report

* fix: tds computation summary columns
  • Loading branch information
GursheenK authored Aug 14, 2023
1 parent b131f70 commit 90b390c
Show file tree
Hide file tree
Showing 4 changed files with 159 additions and 73 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,35 @@ frappe.query_reports["TDS Computation Summary"] = {
"default": frappe.defaults.get_default('company')
},
{
"fieldname":"supplier",
"label": __("Supplier"),
"fieldtype": "Link",
"options": "Supplier",
"fieldname":"party_type",
"label": __("Party Type"),
"fieldtype": "Select",
"options": ["Supplier", "Customer"],
"reqd": 1,
"default": "Supplier",
"on_change": function(){
frappe.query_report.set_filter_value("party", "");
}
},
{
"fieldname":"party",
"label": __("Party"),
"fieldtype": "Dynamic Link",
"get_options": function() {
var party_type = frappe.query_report.get_filter_value('party_type');
var party = frappe.query_report.get_filter_value('party');
if(party && !party_type) {
frappe.throw(__("Please select Party Type first"));
}
return party_type;
},
"get_query": function() {
return {
"filters": {
"tax_withholding_category": ["!=",""],
}
}
}
},
},
{
"fieldname":"from_date",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@


def execute(filters=None):
validate_filters(filters)
if filters.get("party_type") == "Customer":
party_naming_by = frappe.db.get_single_value("Selling Settings", "cust_master_name")
else:
party_naming_by = frappe.db.get_single_value("Buying Settings", "supp_master_name")

filters.update({"naming_series": party_naming_by})

filters.naming_series = frappe.db.get_single_value("Buying Settings", "supp_master_name")
validate_filters(filters)

columns = get_columns(filters)
(
Expand All @@ -25,7 +30,7 @@ def execute(filters=None):
res = get_result(
filters, tds_docs, tds_accounts, tax_category_map, journal_entry_party_map, invoice_total_map
)
final_result = group_by_supplier_and_category(res)
final_result = group_by_party_and_category(res, filters)

return columns, final_result

Expand All @@ -43,60 +48,67 @@ def validate_filters(filters):
filters["fiscal_year"] = from_year


def group_by_supplier_and_category(data):
supplier_category_wise_map = {}
def group_by_party_and_category(data, filters):
party_category_wise_map = {}

for row in data:
supplier_category_wise_map.setdefault(
(row.get("supplier"), row.get("section_code")),
party_category_wise_map.setdefault(
(row.get("party"), row.get("section_code")),
{
"pan": row.get("pan"),
"supplier": row.get("supplier"),
"supplier_name": row.get("supplier_name"),
"tax_id": row.get("tax_id"),
"party": row.get("party"),
"party_name": row.get("party_name"),
"section_code": row.get("section_code"),
"entity_type": row.get("entity_type"),
"tds_rate": row.get("tds_rate"),
"total_amount_credited": 0.0,
"tds_deducted": 0.0,
"rate": row.get("rate"),
"total_amount": 0.0,
"tax_amount": 0.0,
},
)

supplier_category_wise_map.get((row.get("supplier"), row.get("section_code")))[
"total_amount_credited"
] += row.get("total_amount_credited", 0.0)
party_category_wise_map.get((row.get("party"), row.get("section_code")))[
"total_amount"
] += row.get("total_amount", 0.0)

supplier_category_wise_map.get((row.get("supplier"), row.get("section_code")))[
"tds_deducted"
] += row.get("tds_deducted", 0.0)
party_category_wise_map.get((row.get("party"), row.get("section_code")))[
"tax_amount"
] += row.get("tax_amount", 0.0)

final_result = get_final_result(supplier_category_wise_map)
final_result = get_final_result(party_category_wise_map)

return final_result


def get_final_result(supplier_category_wise_map):
def get_final_result(party_category_wise_map):
out = []
for key, value in supplier_category_wise_map.items():
for key, value in party_category_wise_map.items():
out.append(value)

return out


def get_columns(filters):
pan = "pan" if frappe.db.has_column(filters.party_type, "pan") else "tax_id"
columns = [
{"label": _("PAN"), "fieldname": "pan", "fieldtype": "Data", "width": 90},
{"label": _(frappe.unscrub(pan)), "fieldname": pan, "fieldtype": "Data", "width": 90},
{
"label": _("Supplier"),
"options": "Supplier",
"fieldname": "supplier",
"fieldtype": "Link",
"label": _(filters.get("party_type")),
"fieldname": "party",
"fieldtype": "Dynamic Link",
"options": "party_type",
"width": 180,
},
]

if filters.naming_series == "Naming Series":
columns.append(
{"label": _("Supplier Name"), "fieldname": "supplier_name", "fieldtype": "Data", "width": 180}
{
"label": _(filters.party_type + " Name"),
"fieldname": "party_name",
"fieldtype": "Data",
"width": 180,
}
)

columns.extend(
Expand All @@ -109,18 +121,23 @@ def get_columns(filters):
"width": 180,
},
{"label": _("Entity Type"), "fieldname": "entity_type", "fieldtype": "Data", "width": 180},
{"label": _("TDS Rate %"), "fieldname": "tds_rate", "fieldtype": "Percent", "width": 90},
{
"label": _("Total Amount Credited"),
"fieldname": "total_amount_credited",
"label": _("TDS Rate %") if filters.get("party_type") == "Supplier" else _("TCS Rate %"),
"fieldname": "rate",
"fieldtype": "Percent",
"width": 120,
},
{
"label": _("Total Amount"),
"fieldname": "total_amount",
"fieldtype": "Float",
"width": 90,
"width": 120,
},
{
"label": _("Amount of TDS Deducted"),
"fieldname": "tds_deducted",
"label": _("Tax Amount"),
"fieldname": "tax_amount",
"fieldtype": "Float",
"width": 90,
"width": 120,
},
]
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,14 @@ frappe.query_reports["TDS Payable Monthly"] = {
frappe.throw(__("Please select Party Type first"));
}
return party_type;
}
},
"get_query": function() {
return {
"filters": {
"tax_withholding_category": ["!=",""],
}
}
},
},
{
"fieldname":"from_date",
Expand Down
Loading

0 comments on commit 90b390c

Please sign in to comment.