fix: Contribution amount against invoices in Sales Person Dashboard

This commit is contained in:
Deepesh Garg 2022-03-21 12:04:18 +05:30
parent 01638a01cb
commit 3a7776ea7f
2 changed files with 15 additions and 8 deletions

View File

@ -4,8 +4,12 @@
frappe.ui.form.on('Sales Person', {
refresh: function(frm) {
if(frm.doc.__onload && frm.doc.__onload.dashboard_info) {
var info = frm.doc.__onload.dashboard_info;
frm.dashboard.add_indicator(__('Total Contribution Amount: {0}', [format_currency(info.allocated_amount, info.currency)]), 'blue');
let info = frm.doc.__onload.dashboard_info;
frm.dashboard.add_indicator(__('Total Contribution Amount Against Orders: {0}',
[format_currency(info.allocated_amount_against_order, info.currency)]), 'blue');
frm.dashboard.add_indicator(__('Total Contribution Amount Against Invoices: {0}',
[format_currency(info.allocated_amount_against_invoice, info.currency)]), 'blue');
}
},

View File

@ -28,14 +28,17 @@ class SalesPerson(NestedSet):
def load_dashboard_info(self):
company_default_currency = get_default_currency()
allocated_amount = frappe.db.sql("""
select sum(allocated_amount)
from `tabSales Team`
where sales_person = %s and docstatus=1 and parenttype = 'Sales Order'
""",(self.sales_person_name))
allocated_amount_against_order = flt(frappe.db.get_value('Sales Team',
{'docstatus': 1, 'parenttype': 'Sales Order', 'sales_person': self.sales_person_name},
'sum(allocated_amount)'))
allocated_amount_against_invoice = flt(frappe.db.get_value('Sales Team',
{'docstatus': 1, 'parenttype': 'Sales Invoice', 'sales_person': self.sales_person_name},
'sum(allocated_amount)'))
info = {}
info["allocated_amount"] = flt(allocated_amount[0][0]) if allocated_amount else 0
info["allocated_amount_against_order"] = allocated_amount_against_order
info["allocated_amount_against_invoice"] = allocated_amount_against_invoice
info["currency"] = company_default_currency
self.set_onload('dashboard_info', info)