refactor: fix linting
This commit is contained in:
parent
a5e8e449ee
commit
3294f86b92
@ -3,7 +3,6 @@
|
||||
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from erpnext.regional.united_arab_emirates.utils import get_tax_accounts
|
||||
from frappe import _
|
||||
|
||||
def execute(filters=None):
|
||||
@ -14,11 +13,7 @@ def execute(filters=None):
|
||||
return columns, data, None, chart
|
||||
|
||||
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
|
||||
"""
|
||||
"""Creates a list of dictionaries that are used to generate column headers of the data table."""
|
||||
return [
|
||||
{
|
||||
"fieldname": "no",
|
||||
@ -47,22 +42,15 @@ def get_columns():
|
||||
]
|
||||
|
||||
def get_data(filters = None):
|
||||
"""Returns the list of dictionaries. Each dictionary is a row in the datatable and chart data
|
||||
|
||||
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
|
||||
Dict: Dictionary containing chart data
|
||||
"""
|
||||
"""Returns the list of dictionaries. Each dictionary is a row in the datatable and chart data."""
|
||||
data = []
|
||||
data.append({
|
||||
"no": '',
|
||||
"legend": f'VAT on Sales and All Other Outputs',
|
||||
"legend": 'VAT on Sales and All Other Outputs',
|
||||
"amount": '',
|
||||
"vat_amount": ''
|
||||
})
|
||||
|
||||
total_emiratewise = get_total_emiratewise(filters)
|
||||
emirates = get_emirates()
|
||||
amounts_by_emirate = {}
|
||||
@ -92,7 +80,7 @@ def get_data(filters = None):
|
||||
data.append(
|
||||
{
|
||||
"no": '2',
|
||||
"legend": f'Tax Refunds provided to Tourists under the Tax Refunds for Tourists Scheme',
|
||||
"legend": 'Tax Refunds provided to Tourists under the Tax Refunds for Tourists Scheme',
|
||||
"amount": (-1) * get_tourist_tax_return_total(filters),
|
||||
"vat_amount": (-1) * get_tourist_tax_return_tax(filters)
|
||||
}
|
||||
@ -101,7 +89,7 @@ def get_data(filters = None):
|
||||
data.append(
|
||||
{
|
||||
"no": '3',
|
||||
"legend": f'Supplies subject to the reverse charge provision',
|
||||
"legend": 'Supplies subject to the reverse charge provision',
|
||||
"amount": get_reverse_charge_total(filters),
|
||||
"vat_amount": get_reverse_charge_tax(filters)
|
||||
}
|
||||
@ -110,7 +98,7 @@ def get_data(filters = None):
|
||||
data.append(
|
||||
{
|
||||
"no": '4',
|
||||
"legend": f'Zero Rated',
|
||||
"legend": 'Zero Rated',
|
||||
"amount": get_zero_rated_total(filters),
|
||||
"vat_amount": "-"
|
||||
}
|
||||
@ -119,7 +107,7 @@ def get_data(filters = None):
|
||||
data.append(
|
||||
{
|
||||
"no": '5',
|
||||
"legend": f'Exempt Supplies',
|
||||
"legend": 'Exempt Supplies',
|
||||
"amount": get_exempt_total(filters),
|
||||
"vat_amount": "-"
|
||||
}
|
||||
@ -127,22 +115,24 @@ def get_data(filters = None):
|
||||
|
||||
data.append({
|
||||
"no": '',
|
||||
"legend": f'VAT on Expenses and All Other Inputs',
|
||||
"legend": 'VAT on Expenses and All Other Inputs',
|
||||
"amount": '',
|
||||
"vat_amount": ''
|
||||
})
|
||||
|
||||
data.append(
|
||||
{
|
||||
"no": '9',
|
||||
"legend": f'Standard Rated Expenses',
|
||||
"legend": 'Standard Rated Expenses',
|
||||
"amount": get_standard_rated_expenses_total(filters),
|
||||
"vat_amount": get_standard_rated_expenses_tax(filters)
|
||||
}
|
||||
)
|
||||
|
||||
data.append(
|
||||
{
|
||||
"no": '10',
|
||||
"legend": f'Supplies subject to the reverse charge provision',
|
||||
"legend": 'Supplies subject to the reverse charge provision',
|
||||
"amount": get_reverse_charge_recoverable_total(filters),
|
||||
"vat_amount": get_reverse_charge_recoverable_tax(filters)
|
||||
}
|
||||
@ -152,15 +142,7 @@ def get_data(filters = None):
|
||||
|
||||
|
||||
def get_chart(emirates, amounts_by_emirate):
|
||||
"""Returns chart data
|
||||
|
||||
Args:
|
||||
emirates (List): List of Emirates
|
||||
amounts_by_emirate (Dict): Vat and Tax amount by emirates with emirates as key
|
||||
|
||||
Returns:
|
||||
[Dict]: Chart Data
|
||||
"""
|
||||
"""Returns chart data."""
|
||||
labels = []
|
||||
amount = []
|
||||
vat_amount = []
|
||||
@ -186,6 +168,7 @@ def get_chart(emirates, amounts_by_emirate):
|
||||
return chart
|
||||
|
||||
def get_total_emiratewise(filters):
|
||||
"""Returns Emiratewise Amount and Taxes."""
|
||||
return frappe.db.sql(f"""
|
||||
select emirate, sum(total), sum(total_taxes_and_charges) from `tabSales Invoice`
|
||||
where docstatus = 1 {get_conditions(filters)}
|
||||
@ -193,11 +176,7 @@ 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
|
||||
"""
|
||||
"""Returns a List of emirates in the order that they are to be displayed."""
|
||||
return [
|
||||
'Abu Dhabi',
|
||||
'Dubai',
|
||||
@ -209,14 +188,7 @@ 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
|
||||
"""
|
||||
"""The conditions to be used to filter data to calculate the total sale."""
|
||||
conditions = ""
|
||||
for opts in (("company", " and company=%(company)s"),
|
||||
("from_date", " and posting_date>=%(from_date)s"),
|
||||
@ -226,22 +198,8 @@ def get_conditions(filters):
|
||||
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
|
||||
"""
|
||||
"""Returns the sum of the total of each Purchase invoice made."""
|
||||
conditions = get_conditions(filters)
|
||||
print("""
|
||||
select sum(total) from
|
||||
`tabPurchase Invoice`
|
||||
where
|
||||
reverse_charge = "Y"
|
||||
and docstatus = 1 {where_conditions} ;
|
||||
""".format(where_conditions=conditions))
|
||||
return frappe.db.sql("""
|
||||
select sum(total) from
|
||||
`tabPurchase Invoice`
|
||||
@ -251,14 +209,7 @@ def get_reverse_charge_total(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 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
|
||||
"""
|
||||
"""Returns the sum of the tax of each Purchase invoice made."""
|
||||
conditions = get_conditions_join(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(debit) from
|
||||
@ -273,14 +224,7 @@ def get_reverse_charge_tax(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 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
|
||||
"""
|
||||
"""The conditions to be used to filter data to calculate the total vat."""
|
||||
conditions = ""
|
||||
for opts in (("company", " and `tabPurchase Invoice`.company=%(company)s"),
|
||||
("from_date", " and `tabPurchase Invoice`.posting_date>=%(from_date)s"),
|
||||
@ -290,14 +234,7 @@ def get_conditions_join(filters):
|
||||
return conditions
|
||||
|
||||
def get_reverse_charge_recoverable_total(filters):
|
||||
"""Returns the sum of the total of each Purchase invoice made with claimable reverse charge
|
||||
|
||||
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 with claimable reverse charge
|
||||
"""
|
||||
"""Returns the sum of the total of each Purchase invoice made with claimable reverse charge."""
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(total) from
|
||||
@ -309,14 +246,7 @@ def get_reverse_charge_recoverable_total(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 0
|
||||
|
||||
def get_reverse_charge_recoverable_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
|
||||
"""
|
||||
"""Returns the sum of the tax of each Purchase invoice made."""
|
||||
conditions = get_conditions_join(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(debit * `tabPurchase Invoice`.claimable_reverse_charge / 100) from
|
||||
@ -332,14 +262,7 @@ def get_reverse_charge_recoverable_tax(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 0
|
||||
|
||||
def get_standard_rated_expenses_total(filters):
|
||||
"""Returns the sum of the total of each Purchase invoice made with claimable reverse charge
|
||||
|
||||
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 with claimable reverse charge
|
||||
"""
|
||||
"""Returns the sum of the total of each Purchase invoice made with claimable reverse charge."""
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(total) from
|
||||
@ -350,14 +273,7 @@ def get_standard_rated_expenses_total(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 0
|
||||
|
||||
def get_standard_rated_expenses_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
|
||||
"""
|
||||
"""Returns the sum of the tax of each Purchase invoice made."""
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(standard_rated_expenses) from
|
||||
@ -368,14 +284,7 @@ def get_standard_rated_expenses_tax(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 0
|
||||
|
||||
def get_tourist_tax_return_total(filters):
|
||||
"""Returns the sum of the total of each Sales invoice with non zero tourist_tax_return
|
||||
|
||||
Args:
|
||||
filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Float: sum of the total of each Sales invoice with non zero tourist_tax_return
|
||||
"""
|
||||
"""Returns the sum of the total of each Sales invoice with non zero tourist_tax_return."""
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(total) from
|
||||
@ -386,14 +295,7 @@ def get_tourist_tax_return_total(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 0
|
||||
|
||||
def get_tourist_tax_return_tax(filters):
|
||||
"""Returns the sum of the tax of each Sales invoice with non zero tourist_tax_return
|
||||
|
||||
Args:
|
||||
filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Float: sum of the tax of each Sales invoice with non zero tourist_tax_return
|
||||
"""
|
||||
"""Returns the sum of the tax of each Sales invoice with non zero tourist_tax_return."""
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(tourist_tax_return) from
|
||||
@ -404,14 +306,7 @@ def get_tourist_tax_return_tax(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 0
|
||||
|
||||
def get_zero_rated_total(filters):
|
||||
"""Returns the sum of each Sales Invoice Item Amount which is zero rated
|
||||
|
||||
Args:
|
||||
filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Float: sum of each Sales Invoice Item Amount which is zero rated
|
||||
"""
|
||||
"""Returns the sum of each Sales Invoice Item Amount which is zero rated."""
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(i.base_amount) as total from
|
||||
@ -421,14 +316,7 @@ def get_zero_rated_total(filters):
|
||||
""".format(where_conditions=conditions), filters)[0][0] or 0
|
||||
|
||||
def get_exempt_total(filters):
|
||||
"""Returns the sum of each Sales Invoice Item Amount which is Vat Exempt
|
||||
|
||||
Args:
|
||||
filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None.
|
||||
|
||||
Returns:
|
||||
Float: sum of each Sales Invoice Item Amount which is Vat Exempt
|
||||
"""
|
||||
"""Returns the sum of each Sales Invoice Item Amount which is Vat Exempt."""
|
||||
conditions = get_conditions(filters)
|
||||
return frappe.db.sql("""
|
||||
select sum(i.base_amount) as total from
|
||||
|
@ -131,8 +131,7 @@ def add_print_formats():
|
||||
name in('Simplified Tax Invoice', 'Detailed Tax Invoice', 'Tax Invoice') """)
|
||||
|
||||
def add_custom_roles_for_reports():
|
||||
"""Add Access Control to UAE VAT 21
|
||||
"""
|
||||
"""Add Access Control to UAE VAT 21."""
|
||||
if not frappe.db.get_value('Custom Role', dict(report='UAE VAT 21')):
|
||||
frappe.get_doc(dict(
|
||||
doctype='Custom Role',
|
||||
@ -145,8 +144,7 @@ def add_custom_roles_for_reports():
|
||||
)).insert()
|
||||
|
||||
def add_permissions():
|
||||
"""Add Permissions for UAE VAT Settings and UAE VAT Account
|
||||
"""
|
||||
"""Add Permissions for UAE VAT Settings and UAE VAT Account."""
|
||||
for doctype in ('UAE VAT Setting', 'UAE VAT Account'):
|
||||
add_permission(doctype, 'All', 0)
|
||||
for role in ('Accounts Manager', 'Accounts User', 'System Manager'):
|
||||
|
@ -31,7 +31,7 @@ def update_itemised_tax_data(doc):
|
||||
row.total_amount = flt((row.net_amount + row.tax_amount), row.precision("total_amount"))
|
||||
|
||||
def get_account_currency(account):
|
||||
"""Helper function to get account currency"""
|
||||
"""Helper function to get account currency."""
|
||||
if not account:
|
||||
return
|
||||
def generator():
|
||||
@ -44,14 +44,7 @@ def get_account_currency(account):
|
||||
return frappe.local_cache("account_currency", account, generator)
|
||||
|
||||
def get_tax_accounts(company):
|
||||
"""Get the list of tax accounts for a specific company
|
||||
|
||||
Args:
|
||||
company (String): Current Company set as default
|
||||
|
||||
Returns:
|
||||
tax_accounts: List of Tax Accounts for the company
|
||||
"""
|
||||
"""Get the list of tax accounts for a specific company."""
|
||||
tax_accounts_dict = frappe._dict()
|
||||
tax_accounts_list = frappe.get_all("UAE VAT Account",
|
||||
filters={"parent": company},
|
||||
@ -67,11 +60,7 @@ def get_tax_accounts(company):
|
||||
return tax_accounts_dict
|
||||
|
||||
def update_grand_total_for_rcm(doc, method):
|
||||
"""If the Reverse Charge is Applicable subtract the tax amount from the grand total and update in the form
|
||||
|
||||
Args:
|
||||
doc (Document): The document for the current Purchase Invoice
|
||||
"""
|
||||
"""If the Reverse Charge is Applicable subtract the tax amount from the grand total and update in the form."""
|
||||
country = frappe.get_cached_value('Company', doc.company, 'country')
|
||||
|
||||
if country != 'United Arab Emirates':
|
||||
@ -102,14 +91,7 @@ def update_grand_total_for_rcm(doc, method):
|
||||
update_totals(vat_tax, base_vat_tax, doc)
|
||||
|
||||
def update_totals(vat_tax, base_vat_tax, doc):
|
||||
"""Update the grand total values in the form
|
||||
|
||||
Args:
|
||||
vat_tax (float): Vat Tax to be subtracted
|
||||
base_vat_tax (float): Base Vat Tax to be subtracted
|
||||
doc (Document): The document for the current Purchase Invoice
|
||||
"""
|
||||
|
||||
"""Update the grand total values in the form."""
|
||||
doc.base_grand_total -= base_vat_tax
|
||||
doc.grand_total -= vat_tax
|
||||
|
||||
@ -130,16 +112,7 @@ def update_totals(vat_tax, base_vat_tax, doc):
|
||||
doc.set_payment_schedule()
|
||||
|
||||
def make_regional_gl_entries(gl_entries, doc):
|
||||
"""This method is hooked to the make_regional_gl_entries in Purchase Invoice.
|
||||
It appends the region specific general ledger entries to the list of GL Entries.
|
||||
|
||||
Args:
|
||||
gl_entries (List): List of GL entries to be made
|
||||
doc (Document): The document for the current Purchase Invoice
|
||||
|
||||
Returns:
|
||||
List: Updates list of GL Entries
|
||||
"""
|
||||
"""Hooked to make_regional_gl_entries in Purchase Invoice.It appends the region specific general ledger entries to the list of GL Entries."""
|
||||
country = frappe.get_cached_value('Company', doc.company, 'country')
|
||||
|
||||
if country != 'United Arab Emirates':
|
||||
@ -170,7 +143,7 @@ def make_regional_gl_entries(gl_entries, doc):
|
||||
return gl_entries
|
||||
|
||||
def validate_returns(doc, method):
|
||||
print("validate_returns")
|
||||
"""Sum of Tourist Returns and Standard Rated Expenses should be less than Total Tax."""
|
||||
country = frappe.get_cached_value('Company', doc.company, 'country')
|
||||
|
||||
if country != 'United Arab Emirates':
|
||||
|
Loading…
x
Reference in New Issue
Block a user