mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-28 06:08:25 +00:00
Sales Goal by Company (#9723)
* [sales goal] in company; dashboard, graph, notifs, wiz * [test] target notifications * cache past year monthly sales of every company daily, patch * [minor] query fixes * update sales goal docs
This commit is contained in:
committed by
Makarand Bauskar
parent
e2d0d0a0c1
commit
e012e24423
File diff suppressed because it is too large
Load Diff
@@ -147,7 +147,7 @@ class Company(Document):
|
||||
def validate_perpetual_inventory(self):
|
||||
if not self.get("__islocal"):
|
||||
if cint(self.enable_perpetual_inventory) == 1 and not self.default_inventory_account:
|
||||
frappe.msgprint(_("Set default inventory account for perpetual inventory"),
|
||||
frappe.msgprint(_("Set default inventory account for perpetual inventory"),
|
||||
alert=True, indicator='orange')
|
||||
|
||||
def set_default_accounts(self):
|
||||
@@ -310,3 +310,45 @@ def get_name_with_abbr(name, company):
|
||||
parts.append(company_abbr)
|
||||
|
||||
return " - ".join(parts)
|
||||
|
||||
def update_company_current_month_sales(company):
|
||||
from frappe.utils import today, formatdate
|
||||
current_month_year = formatdate(today(), "MM-yyyy")
|
||||
|
||||
results = frappe.db.sql(('''
|
||||
select
|
||||
sum(grand_total) as total, date_format(posting_date, '%m-%Y') as month_year
|
||||
from
|
||||
`tabSales Invoice`
|
||||
where
|
||||
date_format(posting_date, '%m-%Y')="{0}" and
|
||||
company = "{1}"
|
||||
group by
|
||||
month_year;
|
||||
''').format(current_month_year, frappe.db.escape(company)), as_dict = True)
|
||||
|
||||
monthly_total = results[0]['total'] if len(results) > 0 else 0
|
||||
|
||||
frappe.db.sql(('''
|
||||
update tabCompany set total_monthly_sales = %s where name=%s
|
||||
'''), (monthly_total, frappe.db.escape(company)))
|
||||
frappe.db.commit()
|
||||
|
||||
|
||||
def update_company_monthly_sales(company):
|
||||
'''Cache past year monthly sales of every company based on sales invoices'''
|
||||
from frappe.utils.goal import get_monthly_results
|
||||
import json
|
||||
filter_str = 'company = "'+ company +'" and status != "Draft"'
|
||||
month_to_value_dict = get_monthly_results("Sales Invoice", "grand_total", "posting_date", filter_str, "sum")
|
||||
|
||||
frappe.db.sql(('''
|
||||
update tabCompany set sales_monthly_history = %s where name=%s
|
||||
'''), (json.dumps(month_to_value_dict), frappe.db.escape(company)))
|
||||
frappe.db.commit()
|
||||
|
||||
def cache_companies_monthly_sales_history():
|
||||
companies = [d['name'] for d in frappe.get_list("Company")]
|
||||
for company in companies:
|
||||
update_company_monthly_sales(company)
|
||||
frappe.db.commit()
|
||||
|
||||
42
erpnext/setup/doctype/company/company_dashboard.py
Normal file
42
erpnext/setup/doctype/company/company_dashboard.py
Normal file
@@ -0,0 +1,42 @@
|
||||
from frappe import _
|
||||
|
||||
def get_data():
|
||||
return {
|
||||
'heatmap': True,
|
||||
'heatmap_message': _('This is based on transactions against this Company. See timeline below for details'),
|
||||
|
||||
'graph': True,
|
||||
'graph_method': "frappe.utils.goal.get_monthly_goal_graph_data",
|
||||
'graph_method_args': {
|
||||
'title': 'Sales',
|
||||
'goal_value_field': 'sales_target',
|
||||
'goal_total_field': 'total_monthly_sales',
|
||||
'goal_history_field': 'sales_monthly_history',
|
||||
'goal_doctype': 'Sales Invoice',
|
||||
'goal_doctype_link': 'company',
|
||||
'goal_field': 'grand_total',
|
||||
'date_field': 'posting_date',
|
||||
'filter_str': 'status != "Draft"',
|
||||
'aggregation': 'sum'
|
||||
},
|
||||
|
||||
'fieldname': 'company',
|
||||
'transactions': [
|
||||
{
|
||||
'label': _('Pre Sales'),
|
||||
'items': ['Quotation']
|
||||
},
|
||||
{
|
||||
'label': _('Orders'),
|
||||
'items': ['Sales Order', 'Delivery Note', 'Sales Invoice']
|
||||
},
|
||||
{
|
||||
'label': _('Support'),
|
||||
'items': ['Issue']
|
||||
},
|
||||
{
|
||||
'label': _('Projects'),
|
||||
'items': ['Project']
|
||||
}
|
||||
]
|
||||
}
|
||||
@@ -91,7 +91,8 @@ def create_fiscal_year_and_company(args):
|
||||
'country': args.get('country'),
|
||||
'create_chart_of_accounts_based_on': 'Standard Template',
|
||||
'chart_of_accounts': args.get('chart_of_accounts'),
|
||||
'domain': args.get('domain')
|
||||
'domain': args.get('domain'),
|
||||
'sales_target': args.get('sales_target')
|
||||
}).insert()
|
||||
|
||||
#Enable shopping cart
|
||||
|
||||
Reference in New Issue
Block a user