mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-15 11:09:17 +00:00
feat: Added a Chart to compare Vat and sales between emirates
This commit is contained in:
@@ -4,12 +4,12 @@
|
|||||||
from __future__ import unicode_literals
|
from __future__ import unicode_literals
|
||||||
import frappe
|
import frappe
|
||||||
from erpnext.regional.united_arab_emirates.utils import get_tax_accounts
|
from erpnext.regional.united_arab_emirates.utils import get_tax_accounts
|
||||||
|
from frappe import _
|
||||||
|
|
||||||
def execute(filters=None):
|
def execute(filters=None):
|
||||||
columns = get_columns()
|
columns = get_columns()
|
||||||
data = get_data(filters)
|
data, chart = get_data(filters)
|
||||||
|
return columns, data, None, chart
|
||||||
return columns, data
|
|
||||||
|
|
||||||
def get_columns():
|
def get_columns():
|
||||||
"""Creates a 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
|
||||||
@@ -51,13 +51,14 @@ def get_columns():
|
|||||||
]
|
]
|
||||||
|
|
||||||
def get_data(filters = None):
|
def get_data(filters = None):
|
||||||
"""Returns the list of dictionaries. Each dictionary is a row in the datatable
|
"""Returns the list of dictionaries. Each dictionary is a row in the datatable and chart data
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None.
|
filters (Dict, optional): Dictionary consisting of the filters selected by the user. Defaults to None.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List(Dict): Each dictionary is a row in the datatable
|
List(Dict): Each dictionary is a row in the datatable
|
||||||
|
Dict: Dictionary containing chart data
|
||||||
"""
|
"""
|
||||||
data = []
|
data = []
|
||||||
total_emiratewise = get_total_emiratewise(filters)
|
total_emiratewise = get_total_emiratewise(filters)
|
||||||
@@ -70,6 +71,9 @@ def get_data(filters = None):
|
|||||||
"amount": amount,
|
"amount": amount,
|
||||||
"vat_amount": vat
|
"vat_amount": vat
|
||||||
}
|
}
|
||||||
|
|
||||||
|
chart = get_chart_data(emirates, amounts_by_emirate)
|
||||||
|
|
||||||
for d, emirate in enumerate(emirates, 97):
|
for d, emirate in enumerate(emirates, 97):
|
||||||
if emirate in amounts_by_emirate:
|
if emirate in amounts_by_emirate:
|
||||||
amounts_by_emirate[emirate]["no"] = f'1{chr(d)}'
|
amounts_by_emirate[emirate]["no"] = f'1{chr(d)}'
|
||||||
@@ -92,9 +96,43 @@ def get_data(filters = None):
|
|||||||
"vat_amount": get_reverse_charge_tax(filters)
|
"vat_amount": get_reverse_charge_tax(filters)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
return data
|
return data, chart
|
||||||
|
|
||||||
|
|
||||||
|
def get_chart_data(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
|
||||||
|
"""
|
||||||
|
labels = []
|
||||||
|
amount = []
|
||||||
|
vat_amount = []
|
||||||
|
for d in emirates:
|
||||||
|
if d in amounts_by_emirate:
|
||||||
|
amount.append(amounts_by_emirate[d]["amount"])
|
||||||
|
vat_amount.append(amounts_by_emirate[d]["vat_amount"])
|
||||||
|
labels.append(d)
|
||||||
|
|
||||||
|
datasets = []
|
||||||
|
datasets.append({'name': _('Amount (AED)'), 'values': amount})
|
||||||
|
datasets.append({'name': _('Vat Amount (AED)'), 'values': vat_amount})
|
||||||
|
|
||||||
|
chart = {
|
||||||
|
"data": {
|
||||||
|
'labels': labels,
|
||||||
|
'datasets': datasets
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
chart["type"] = "bar"
|
||||||
|
chart["fieldtype"] = "Currency"
|
||||||
|
return chart
|
||||||
|
|
||||||
def get_total_emiratewise(filters):
|
def get_total_emiratewise(filters):
|
||||||
return frappe.db.sql(f"""
|
return frappe.db.sql(f"""
|
||||||
select emirate, sum(total), sum(total_taxes_and_charges) from `tabSales Invoice`
|
select emirate, sum(total), sum(total_taxes_and_charges) from `tabSales Invoice`
|
||||||
|
|||||||
Reference in New Issue
Block a user