fix: TDS report cleanup

This commit is contained in:
Deepesh Garg 2021-02-28 23:28:25 +05:30
parent 79b422c0a9
commit a87e3fcb7c
4 changed files with 42 additions and 51 deletions

View File

@ -967,7 +967,7 @@ def split_invoices_based_on_payment_terms(outstanding_invoices):
outstanding_invoices.pop(idx - 1) outstanding_invoices.pop(idx - 1)
outstanding_invoices += invoice_ref_based_on_payment_terms[idx] outstanding_invoices += invoice_ref_based_on_payment_terms[idx]
return outstanding_invoices return outstanding_invoices
def get_orders_to_be_billed(posting_date, party_type, party, def get_orders_to_be_billed(posting_date, party_type, party,
@ -1411,6 +1411,9 @@ def get_payment_entry(dt, dn, party_amount=None, bank_account=None, bank_amount=
}) })
pe.set_difference_amount() pe.set_difference_amount()
if doc.doctype == 'Purchase Order' and doc.apply_tds:
pe.apply_tax_withholding_amount = 1
return pe return pe
def get_bank_cash_account(doc, bank_account): def get_bank_cash_account(doc, bank_account):

View File

@ -127,7 +127,6 @@
"write_off_cost_center", "write_off_cost_center",
"advances_section", "advances_section",
"allocate_advances_automatically", "allocate_advances_automatically",
"adjust_advance_taxes",
"get_advances", "get_advances",
"advances", "advances",
"payment_schedule_section", "payment_schedule_section",
@ -1492,7 +1491,9 @@
"in_standard_filter": 1, "in_standard_filter": 1,
"label": "Status", "label": "Status",
"options": "\nDraft\nReturn\nDebit Note Issued\nSubmitted\nPaid\nUnpaid\nOverdue\nCancelled\nInternal Transfer", "options": "\nDraft\nReturn\nDebit Note Issued\nSubmitted\nPaid\nUnpaid\nOverdue\nCancelled\nInternal Transfer",
"print_hide": 1 "print_hide": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "inter_company_invoice_reference", "fieldname": "inter_company_invoice_reference",
@ -1501,7 +1502,9 @@
"no_copy": 1, "no_copy": 1,
"options": "Sales Invoice", "options": "Sales Invoice",
"print_hide": 1, "print_hide": 1,
"read_only": 1 "read_only": 1,
"show_days": 1,
"show_seconds": 1
}, },
{ {
"fieldname": "remarks", "fieldname": "remarks",
@ -1633,7 +1636,9 @@
"fieldname": "unrealized_profit_loss_account", "fieldname": "unrealized_profit_loss_account",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Unrealized Profit / Loss Account", "label": "Unrealized Profit / Loss Account",
"options": "Account" "options": "Account",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"depends_on": "eval:doc.is_internal_supplier", "depends_on": "eval:doc.is_internal_supplier",
@ -1642,7 +1647,9 @@
"fieldname": "represents_company", "fieldname": "represents_company",
"fieldtype": "Link", "fieldtype": "Link",
"label": "Represents Company", "label": "Represents Company",
"options": "Company" "options": "Company",
"show_days": 1,
"show_seconds": 1
}, },
{ {
"depends_on": "eval:doc.update_stock && doc.is_internal_supplier", "depends_on": "eval:doc.update_stock && doc.is_internal_supplier",
@ -1654,6 +1661,8 @@
"options": "Warehouse", "options": "Warehouse",
"print_hide": 1, "print_hide": 1,
"print_width": "50px", "print_width": "50px",
"show_days": 1,
"show_seconds": 1,
"width": "50px" "width": "50px"
}, },
{ {
@ -1681,7 +1690,7 @@
"idx": 204, "idx": 204,
"is_submittable": 1, "is_submittable": 1,
"links": [], "links": [],
"modified": "2020-10-27 21:21:22.647349", "modified": "2021-02-28 22:33:15.728392",
"modified_by": "Administrator", "modified_by": "Administrator",
"module": "Accounts", "module": "Accounts",
"name": "Purchase Invoice", "name": "Purchase Invoice",

View File

@ -70,13 +70,13 @@ frappe.query_reports["TDS Payable Monthly"] = {
let supplier = frappe.query_report.get_filter_value('supplier'); let supplier = frappe.query_report.get_filter_value('supplier');
if(!supplier) return; // return if no supplier selected if(!supplier) return; // return if no supplier selected
// filter order based on selected supplier // filter invoices based on selected supplier
let orders = []; let invoices = [];
frappe.query_report.order_data.map(d => { frappe.query_report.invoice_data.map(d => {
if(d.supplier==supplier) if(d.supplier==supplier)
orders.push(d.name) invoices.push(d.name)
}); });
frappe.query_report.orders = orders; frappe.query_report.invoices = invoices;
frappe.query_report.refresh(); frappe.query_report.refresh();
} }
}, },
@ -104,21 +104,14 @@ frappe.query_reports["TDS Payable Monthly"] = {
"method": "erpnext.accounts.report.tds_payable_monthly.tds_payable_monthly.get_tds_invoices_and_orders", "method": "erpnext.accounts.report.tds_payable_monthly.tds_payable_monthly.get_tds_invoices_and_orders",
callback: function(r) { callback: function(r) {
let invoices = []; let invoices = [];
let orders = [];
r.message.invoices.map(d => { r.message.map(d => {
invoices.push(d.name); invoices.push(d.name);
}); });
r.message.orders.map(d => {
orders.push(d.name);
});
report["invoice_data"] = r.message.invoices; report["invoice_data"] = r.message.invoices;
report["invoices"] = invoices; report["invoices"] = invoices;
report["order_data"] = r.message.orders;
report["invoices"] = orders;
} }
}); });
} }

View File

@ -8,7 +8,6 @@ from frappe.utils import getdate
def execute(filters=None): def execute(filters=None):
filters["invoices"] = frappe.cache().hget("invoices", frappe.session.user) filters["invoices"] = frappe.cache().hget("invoices", frappe.session.user)
filters["orders"] = frappe.cache().hget("orders", frappe.session.user)
validate_filters(filters) validate_filters(filters)
set_filters(filters) set_filters(filters)
@ -16,7 +15,7 @@ def execute(filters=None):
payment_entries = get_payment_entires(filters) payment_entries = get_payment_entires(filters)
columns = get_columns(filters) columns = get_columns(filters)
if not (filters.get("invoices") and filters.get('orders')): if not filters.get("invoices"):
return columns, [] return columns, []
res = get_result(filters, payment_entries) res = get_result(filters, payment_entries)
@ -30,13 +29,9 @@ def validate_filters(filters):
def set_filters(filters): def set_filters(filters):
invoices = [] invoices = []
orders = []
if not filters.get("invoices"): if not filters.get("invoices"):
filters["invoices"] = get_tds_invoices_and_orders()['invoices'] filters["invoices"] = get_tds_invoices_and_orders()
if not filters.get("orders"):
filters["orders"] = get_tds_invoices_and_orders()['orders']
if filters.supplier and filters.purchase_invoice: if filters.supplier and filters.purchase_invoice:
for d in filters["invoices"]: for d in filters["invoices"]:
@ -50,24 +45,25 @@ def set_filters(filters):
for d in filters["invoices"]: for d in filters["invoices"]:
if d.name == filters.purchase_invoice: if d.name == filters.purchase_invoice:
invoices.append(d) invoices.append(d)
elif filters.supplier and filters.purchase_order:
if filters.supplier and filters.purchase_order: for d in filters.get("invoices"):
for d in filters.get("orders"):
if d.name == filters.purchase_order and d.supplier == filters.supplier: if d.name == filters.purchase_order and d.supplier == filters.supplier:
orders.append(d) invoices.append(d)
elif filters.supplier and not filters.purchase_order: elif filters.supplier and not filters.purchase_order:
for d in filters.get("orders"): for d in filters.get("invoices"):
if d.supplier == filters.supplier: if d.supplier == filters.supplier:
orders.append(d) invoices.append(d)
elif filters.purchase_order and not filters.supplier: elif filters.purchase_order and not filters.supplier:
for d in filters.get("invoices"): for d in filters.get("invoices"):
if d.name == filters.purchase_order: if d.name == filters.purchase_order:
orders.append(d) print("$#$#$$#")
invoices.append(d)
filters["invoices"] = invoices if invoices else filters["invoices"] filters["invoices"] = invoices if invoices else filters["invoices"]
filters["orders"] = orders if orders else filters["orders"]
filters.naming_series = frappe.db.get_single_value('Buying Settings', 'supp_master_name') filters.naming_series = frappe.db.get_single_value('Buying Settings', 'supp_master_name')
#print(filters.get('invoices'))
def get_result(filters, payment_entries): def get_result(filters, payment_entries):
supplier_map, tds_docs = get_supplier_map(filters, payment_entries) supplier_map, tds_docs = get_supplier_map(filters, payment_entries)
documents = [d.get('name') for d in filters.get('invoices')] + [d.get('name') for d in payment_entries] documents = [d.get('name') for d in filters.get('invoices')] + [d.get('name') for d in payment_entries]
@ -115,7 +111,7 @@ def get_supplier_map(filters, payment_entries):
# pre-fetch all distinct applicable tds docs # pre-fetch all distinct applicable tds docs
supplier_map, tds_docs = {}, {} supplier_map, tds_docs = {}, {}
pan = "pan" if frappe.db.has_column("Supplier", "pan") else "tax_id" pan = "pan" if frappe.db.has_column("Supplier", "pan") else "tax_id"
supplier_list = [d.supplier for d in filters["invoices"]] + [d.supplier for d in filters["orders"]] supplier_list = [d.supplier for d in filters["invoices"]]
supplier_detail = frappe.db.get_all('Supplier', supplier_detail = frappe.db.get_all('Supplier',
{"name": ["in", supplier_list]}, {"name": ["in", supplier_list]},
@ -125,10 +121,6 @@ def get_supplier_map(filters, payment_entries):
supplier_map[d.get("name")] = [k for k in supplier_detail supplier_map[d.get("name")] = [k for k in supplier_detail
if k.name == d.get("supplier")][0] if k.name == d.get("supplier")][0]
for d in filters["orders"]:
supplier_map[d.get("name")] = [k for k in supplier_detail
if k.name == d.get("supplier")][0]
for d in payment_entries: for d in payment_entries:
supplier_map[d.get("name")] = [k for k in supplier_detail supplier_map[d.get("name")] = [k for k in supplier_detail
if k.name == d.get("supplier")][0] if k.name == d.get("supplier")][0]
@ -248,12 +240,10 @@ def get_payment_entires(filters):
'apply_tax_withholding_amount': 1 'apply_tax_withholding_amount': 1
} }
if filters.get('purchase_order') or filters.get('purchase_invoice'): if filters.get('purchase_invoice') or filters.get('purchase_order'):
parent = frappe.db.get_all('Payment Entry Reference', parent = frappe.db.get_all('Payment Entry Reference',
{ { 'reference_name': ('in', [d.get('name') for d in filters.get('invoices')])}, ['parent'])
'reference_name': ('in', [d.get('name') for d in filters.get('orders')] +
[d.get('name') for d in filters.get('invoices')])
}, ['parent'])
filter_dict.update({'name': ('in', [d.get('parent') for d in parent])}) filter_dict.update({'name': ('in', [d.get('parent') for d in parent])})
payment_entries = frappe.get_all('Payment Entry', fields=['name', 'party_name as supplier'], payment_entries = frappe.get_all('Payment Entry', fields=['name', 'party_name as supplier'],
@ -273,13 +263,9 @@ def get_tds_invoices_and_orders():
orders = frappe.db.get_list("Purchase Order", orders = frappe.db.get_list("Purchase Order",
{"supplier": ["in", suppliers]}, ["name", "supplier"]) {"supplier": ["in", suppliers]}, ["name", "supplier"])
invoices = invoices + orders
invoices = [d for d in invoices if d.supplier] invoices = [d for d in invoices if d.supplier]
orders = [d for d in orders if d.supplier]
frappe.cache().hset("invoices", frappe.session.user, invoices) frappe.cache().hset("invoices", frappe.session.user, invoices)
frappe.cache().hset("orders", frappe.session.user, invoices)
return { return invoices
'invoices': invoices,
'orders': orders
}