refactor(UAE VAT 201): break functions
diff --git a/erpnext/regional/report/uae_vat_201/uae_vat_201.py b/erpnext/regional/report/uae_vat_201/uae_vat_201.py
index b5ff838..90e7501 100644
--- a/erpnext/regional/report/uae_vat_201/uae_vat_201.py
+++ b/erpnext/regional/report/uae_vat_201/uae_vat_201.py
@@ -46,109 +46,8 @@
def get_data(filters = None):
"""Returns the list of dictionaries. Each dictionary is a row in the datatable and chart data."""
data = []
- data.append({
- "no": '',
- "legend": _('VAT on Sales and All Other Outputs'),
- "amount": '',
- "vat_amount": ''
- })
-
- total_emiratewise = get_total_emiratewise(filters)
- emirates = get_emirates()
- amounts_by_emirate = {}
- for d in total_emiratewise:
- emirate, amount, vat= d
- amounts_by_emirate[emirate] = {
- "legend": emirate,
- "raw_amount": amount,
- "raw_vat_amount": vat,
- "amount": frappe.format(amount, 'Currency'),
- "vat_amount": frappe.format(vat, 'Currency'),
- }
-
- for d, emirate in enumerate(emirates, 97):
- if emirate in amounts_by_emirate:
- amounts_by_emirate[emirate]["no"] = _('1{0}').format(chr(d))
- amounts_by_emirate[emirate]["legend"] = _('Standard rated supplies in {0}').format(emirate)
- data.append(amounts_by_emirate[emirate])
- else:
- data.append(
- {
- "no": _('1{0}').format(chr(d)),
- "legend": _('Standard rated supplies in {0}').format(emirate),
- "amount": frappe.format(0, 'Currency'),
- "vat_amount": frappe.format(0, 'Currency')
- }
- )
-
- data.append(
- {
- "no": '2',
- "legend": _('Tax Refunds provided to Tourists under the Tax Refunds for Tourists Scheme'),
- "amount": frappe.format((-1) * get_tourist_tax_return_total(filters), 'Currency'),
- "vat_amount": frappe.format((-1) * get_tourist_tax_return_tax(filters), 'Currency')
- }
- )
-
- data.append(
- {
- "no": '3',
- "legend": _('Supplies subject to the reverse charge provision'),
- "amount": frappe.format(get_reverse_charge_total(filters), 'Currency'),
- "vat_amount": frappe.format(get_reverse_charge_tax(filters), 'Currency')
- }
- )
-
- data.append(
- {
- "no": '4',
- "legend": _('Zero Rated'),
- "amount": frappe.format(get_zero_rated_total(filters), 'Currency'),
- "vat_amount": "-"
- }
- )
-
- data.append(
- {
- "no": '5',
- "legend": _('Exempt Supplies'),
- "amount": frappe.format(get_exempt_total(filters), 'Currency'),
- "vat_amount": "-"
- }
- )
-
- data.append({
- "no": '',
- "legend": '',
- "amount": '',
- "vat_amount": ''
- })
-
- data.append({
- "no": '',
- "legend": _('VAT on Expenses and All Other Inputs'),
- "amount": '',
- "vat_amount": ''
- })
-
- data.append(
- {
- "no": '9',
- "legend": _('Standard Rated Expenses'),
- "amount": frappe.format(get_standard_rated_expenses_total(filters), 'Currency'),
- "vat_amount": frappe.format(get_standard_rated_expenses_tax(filters), 'Currency')
- }
- )
-
- data.append(
- {
- "no": '10',
- "legend": _('Supplies subject to the reverse charge provision'),
- "amount": frappe.format(get_reverse_charge_recoverable_total(filters), 'Currency'),
- "vat_amount": frappe.format(get_reverse_charge_recoverable_tax(filters), 'Currency')
- }
- )
-
+ emirates, amounts_by_emirate = append_vat_on_sales(data, filters)
+ append_vat_on_expenses(data, filters)
return data, emirates, amounts_by_emirate
@@ -178,6 +77,73 @@
chart["fieldtype"] = "Currency"
return chart
+def append_vat_on_sales(data, filters):
+ """Appends Sales and All Other Outputs"""
+ append_data(data, '', _('VAT on Sales and All Other Outputs'), '', '')
+
+ emirates, amounts_by_emirate = standard_rated_expenses_emiratewise(data, filters)
+
+ append_data(data, '2', _('Tax Refunds provided to Tourists under the Tax Refunds for Tourists Scheme'),
+ frappe.format((-1) * get_tourist_tax_return_total(filters), 'Currency'),
+ frappe.format((-1) * get_tourist_tax_return_tax(filters), 'Currency'))
+
+ append_data(data, '3', _('Supplies subject to the reverse charge provision'),
+ frappe.format(get_reverse_charge_total(filters), 'Currency'),
+ frappe.format(get_reverse_charge_tax(filters), 'Currency'))
+
+ append_data(data, '4', _('Zero Rated'),
+ frappe.format(get_zero_rated_total(filters), 'Currency'), "-")
+
+ append_data(data, '5', _('Exempt Supplies'),
+ frappe.format(get_exempt_total(filters), 'Currency'),"-")
+
+ append_data(data, '', '', '', '')
+
+ return emirates, amounts_by_emirate
+
+def standard_rated_expenses_emiratewise(data, filters):
+ """"Append emiratewise standard rated expenses and vat"""
+ total_emiratewise = get_total_emiratewise(filters)
+ emirates = get_emirates()
+ amounts_by_emirate = {}
+ for d in total_emiratewise:
+ emirate, amount, vat= d
+ amounts_by_emirate[emirate] = {
+ "legend": emirate,
+ "raw_amount": amount,
+ "raw_vat_amount": vat,
+ "amount": frappe.format(amount, 'Currency'),
+ "vat_amount": frappe.format(vat, 'Currency'),
+ }
+
+ for d, emirate in enumerate(emirates, 97):
+ if emirate in amounts_by_emirate:
+ amounts_by_emirate[emirate]["no"] = _('1{0}').format(chr(d))
+ amounts_by_emirate[emirate]["legend"] = _('Standard rated supplies in {0}').format(emirate)
+ data.append(amounts_by_emirate[emirate])
+ else:
+ append_data(data, _('1{0}').format(chr(d)),
+ _('Standard rated supplies in {0}').format(emirate),
+ frappe.format(0, 'Currency'), frappe.format(0, 'Currency'))
+ return emirates, amounts_by_emirate
+
+
+def append_vat_on_expenses(data, filters):
+ """Appends Expenses and All Other Inputs"""
+ append_data(data, '', _('VAT on Expenses and All Other Inputs'), '', '')
+ append_data(data, '9', _('Standard Rated Expenses'),
+ frappe.format(get_standard_rated_expenses_total(filters), 'Currency'),
+ frappe.format(get_standard_rated_expenses_tax(filters), 'Currency'))
+
+ append_data(data, '10', _('Supplies subject to the reverse charge provision'),
+ frappe.format(get_reverse_charge_recoverable_total(filters), 'Currency'),
+ frappe.format(get_reverse_charge_recoverable_tax(filters), 'Currency')
+)
+
+def append_data(data, no, legend, amount, vat_amount):
+ """Returns data with appended value."""
+ data.append({"no": no, "legend":legend, "amount": amount, "vat_amount": vat_amount})
+
def get_total_emiratewise(filters):
"""Returns Emiratewise Amount and Taxes."""
return frappe.db.sql(f"""