From 323791d123e63e9a7b61109d7a727137e7fe81d0 Mon Sep 17 00:00:00 2001 From: hasnain2808 Date: Thu, 10 Sep 2020 17:53:29 +0530 Subject: [PATCH] refactor: added docstrings --- erpnext/regional/report/uae_vat/uae_vat.py | 75 +++++++++++++++++++--- 1 file changed, 67 insertions(+), 8 deletions(-) diff --git a/erpnext/regional/report/uae_vat/uae_vat.py b/erpnext/regional/report/uae_vat/uae_vat.py index 50d1ddd351..4c4c6bc2ab 100644 --- a/erpnext/regional/report/uae_vat/uae_vat.py +++ b/erpnext/regional/report/uae_vat/uae_vat.py @@ -12,6 +12,11 @@ def execute(filters=None): return columns, data def get_columns(): + """Creates a list of dictionaries that are used to generate column headers of the data table + + Returns: + List(Dict): list of dictionaries that are used to generate column headers of the data table + """ return [ { "fieldname": "no", @@ -46,6 +51,14 @@ def get_columns(): ] def get_data(filters = None): + """Returns the list of dictionaries. Each dictionary is a row in the datatable + + Args: + filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None. + + Returns: + List(Dict): Each dictionary is a row in the datatable + """ data = [] total_emiratewise = get_total_emiratewise(filters) emirates = get_emirates() @@ -90,6 +103,11 @@ def get_total_emiratewise(filters): """, filters) def get_emirates(): + """Returns a List of emirates in the order that they are to be displayed + + Returns: + List(String): List of emirates in the order that they are to be displayed + """ return [ 'Abu Dhabi', 'Dubai', @@ -101,6 +119,14 @@ def get_emirates(): ] def get_conditions(filters): + """The conditions to be used to filter data to calculate the total sale + + Args: + filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None. + + Returns: + String: Concatenated list of conditions to be applied to calculate the total sale + """ conditions = "" for opts in (("company", f' and company="{filters.get("company")}"'), ("from_date", f' and posting_date>="{filters.get("from_date")}"'), @@ -109,7 +135,40 @@ def get_conditions(filters): conditions += opts[1] return conditions +def get_reverse_charge_total(filters): + """Returns the sum of the total of each Purchase invoice made + + Args: + filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None. + + Returns: + Float: sum of the total of each Purchase invoice made + """ + conditions = """ + for opts in (("company", f' and company="{filters.get("company")}"'), + ("from_date", f' and posting_date>="{filters.get("from_date")}"'), + ("to_date", f' and posting_date<="{filters.get("to_date")}"')): + if filters.get(opts[0]): + conditions += opts[1] + return conditions + """ + return frappe.db.sql(f""" + select sum(total) from + `tabPurchase Invoice` + where + reverse_charge = "Y" + and docstatus = 1 {get_conditions(filters)} ; + """)[0][0] + def get_reverse_charge_tax(filters): + """Returns the sum of the tax of each Purchase invoice made + + Args: + filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None. + + Returns: + Float: sum of the tax of each Purchase invoice made + """ return frappe.db.sql(f""" select sum(debit) from `tabPurchase Invoice` inner join `tabGL Entry` @@ -122,16 +181,16 @@ def get_reverse_charge_tax(filters): """)[0][0] -def get_reverse_charge_total(filters): - return frappe.db.sql(f""" - select sum(total) from - `tabPurchase Invoice` - where - reverse_charge = "Y" - and docstatus = 1 {get_conditions(filters)} ; - """)[0][0] def get_conditions_join(filters): + """The conditions to be used to filter data to calculate the total vat + + Args: + filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None. + + Returns: + String: Concatenated list of conditions to be applied to calculate the total vat + """ conditions = "" for opts in (("company", f' and `tabPurchase Invoice`.company="{filters.get("company")}"'), ("from_date", f' and `tabPurchase Invoice`.posting_date>="{filters.get("from_date")}"'),