Merge branch 'master' of github.com:webnotes/erpnext into responsive

Conflicts:
	accounts/search_criteria/trend_analyzer/trend_analyzer.py
	buying/doctype/purchase_common/purchase_common.js
This commit is contained in:
Anand Doshi
2013-06-21 12:22:52 +05:30
57 changed files with 1572 additions and 95 deletions

View File

@@ -252,6 +252,21 @@ wn.module_page["Accounts"] = [
route: "query-report/Item-wise Purchase Register",
doctype: "Purchase Invoice"
},
{
"label":wn._("Budget Variance Report"),
route: "query-report/Budget Variance Report",
doctype: "Cost Center"
},
{
"label":wn._("Purchase Invoice Trends"),
route: "query-report/Purchase Invoice Trends",
doctype: "Purchase Invoice"
},
{
"label":wn._("Sales Invoice Trends"),
route: "query-report/Sales Invoice Trends",
doctype: "Sales Invoice"
},
]
}
]

View File

@@ -0,0 +1,25 @@
wn.query_reports["Budget Variance Report"] = {
"filters": [
{
fieldname: "fiscal_year",
label: "Fiscal Year",
fieldtype: "Link",
options: "Fiscal Year",
default: sys_defaults.fiscal_year
},
{
fieldname: "period",
label: "Period",
fieldtype: "Select",
options: "Monthly\nQuarterly\nHalf-Yearly\nYearly",
default: "Monthly"
},
{
fieldname: "company",
label: "Company",
fieldtype: "Link",
options: "Company",
default: sys_defaults.company
},
]
}

View File

@@ -0,0 +1,168 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
import calendar
from webnotes import _, msgprint
from webnotes.utils import flt
import time
def execute(filters=None):
if not filters: filters = {}
columns = get_columns(filters)
period_month_ranges = get_period_month_ranges(filters)
cam_map = get_costcenter_account_month_map(filters)
data = []
for cost_center, cost_center_items in cam_map.items():
for account, monthwise_data in cost_center_items.items():
row = [cost_center, account]
totals = [0, 0, 0]
for relevant_months in period_month_ranges:
period_data = [0, 0, 0]
for month in relevant_months:
month_data = monthwise_data.get(month, {})
for i, fieldname in enumerate(["target", "actual", "variance"]):
value = flt(month_data.get(fieldname))
period_data[i] += value
totals[i] += value
period_data[2] = period_data[0] - period_data[1]
row += period_data
totals[2] = totals[0] - totals[1]
row += totals
data.append(row)
return columns, sorted(data, key=lambda x: (x[0], x[1]))
def get_columns(filters):
for fieldname in ["fiscal_year", "period", "company"]:
if not filters.get(fieldname):
label = (" ".join(fieldname.split("_"))).title()
msgprint(_("Please specify") + ": " + label,
raise_exception=True)
columns = ["Cost Center:Link/Cost Center:100", "Account:Link/Account:100"]
group_months = False if filters["period"] == "Monthly" else True
for from_date, to_date in get_period_date_ranges(filters):
for label in ["Target (%s)", "Actual (%s)", "Variance (%s)"]:
if group_months:
columns.append(label % (from_date.strftime("%b") + " - " + to_date.strftime("%b")))
else:
columns.append(label % from_date.strftime("%b"))
return columns + ["Total Target::80", "Total Actual::80", "Total Variance::80"]
def get_period_date_ranges(filters):
from dateutil.relativedelta import relativedelta
year_start_date, year_end_date = get_year_start_end_date(filters)
increment = {
"Monthly": 1,
"Quarterly": 3,
"Half-Yearly": 6,
"Yearly": 12
}.get(filters["period"])
period_date_ranges = []
for i in xrange(1, 13, increment):
period_end_date = year_start_date + relativedelta(months=increment,
days=-1)
period_date_ranges.append([year_start_date, period_end_date])
year_start_date = period_end_date + relativedelta(days=1)
return period_date_ranges
def get_period_month_ranges(filters):
from dateutil.relativedelta import relativedelta
period_month_ranges = []
for start_date, end_date in get_period_date_ranges(filters):
months_in_this_period = []
while start_date <= end_date:
months_in_this_period.append(start_date.strftime("%B"))
start_date += relativedelta(months=1)
period_month_ranges.append(months_in_this_period)
return period_month_ranges
#Get cost center & target details
def get_costcenter_target_details(filters):
return webnotes.conn.sql("""select cc.name, cc.distribution_id,
cc.parent_cost_center, bd.account, bd.budget_allocated
from `tabCost Center` cc, `tabBudget Detail` bd
where bd.parent=cc.name and bd.fiscal_year=%s and
cc.company_name=%s and ifnull(cc.distribution_id, '')!=''
order by cc.name""" % ('%s', '%s'),
(filters.get("fiscal_year"), filters.get("company")), as_dict=1)
#Get target distribution details of accounts of cost center
def get_target_distribution_details(filters):
target_details = {}
for d in webnotes.conn.sql("""select bdd.month, bdd.percentage_allocation \
from `tabBudget Distribution Detail` bdd, `tabBudget Distribution` bd, \
`tabCost Center` cc where bdd.parent=bd.name and cc.distribution_id=bd.name and \
bd.fiscal_year=%s""" % ('%s'), (filters.get("fiscal_year")), as_dict=1):
target_details.setdefault(d.month, d)
return target_details
#Get actual details from gl entry
def get_actual_details(filters):
return webnotes.conn.sql("""select gl.account, gl.debit, gl.credit,
gl.cost_center, MONTHNAME(gl.posting_date) as month_name
from `tabGL Entry` gl, `tabBudget Detail` bd
where gl.fiscal_year=%s and company=%s and is_cancelled='No'
and bd.account=gl.account""" % ('%s', '%s'),
(filters.get("fiscal_year"), filters.get("company")), as_dict=1)
def get_costcenter_account_month_map(filters):
costcenter_target_details = get_costcenter_target_details(filters)
tdd = get_target_distribution_details(filters)
actual_details = get_actual_details(filters)
cam_map = {}
for ccd in costcenter_target_details:
for month in tdd:
cam_map.setdefault(ccd.name, {}).setdefault(ccd.account, {})\
.setdefault(month, webnotes._dict({
"target": 0.0, "actual": 0.0, "variance": 0.0
}))
tav_dict = cam_map[ccd.name][ccd.account][month]
tav_dict.target = ccd.budget_allocated*(tdd[month]["percentage_allocation"]/100)
for ad in actual_details:
if ad.month_name == month and ad.account == ccd.account \
and ad.cost_center == ccd.name:
tav_dict.actual += ad.debit - ad.credit
return cam_map
def get_year_start_end_date(filters):
return webnotes.conn.sql("""select year_start_date,
subdate(adddate(year_start_date, interval 1 year), interval 1 day)
as year_end_date
from `tabFiscal Year`
where name=%s""", filters["fiscal_year"])[0]

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-06-18 12:56:36",
"docstatus": 0,
"modified": "2013-06-18 12:56:36",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Cost Center",
"report_name": "Budget Variance Report",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Budget Variance Report"
}
]

View File

@@ -23,7 +23,6 @@ def execute(filters=None):
columns = get_columns()
item_list = get_items(filters)
aii_account_map = get_aii_accounts()
webnotes.errprint(aii_account_map)
data = []
for d in item_list:
expense_head = d.expense_head or aii_account_map.get(d.company)

View File

@@ -0,0 +1,5 @@
wn.require("app/js/purchase_trends_filters.js");
wn.query_reports["Purchase Invoice Trends"] = {
filters: get_filters()
}

View File

@@ -0,0 +1,34 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from controllers.trends import get_columns,get_data
def execute(filters=None):
if not filters: filters ={}
data = []
trans = "Purchase Invoice"
tab = ["tabPurchase Invoice","tabPurchase Invoice Item"]
details = get_columns(filters, trans)
data = get_data(filters, tab, details)
if not data :
webnotes.msgprint("Data not found for selected criterias")
return details["columns"], data

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-06-13 18:46:55",
"docstatus": 0,
"modified": "2013-06-13 18:46:55",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Purchase Invoice",
"report_name": "Purchase Invoice Trends",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Purchase Invoice Trends"
}
]

View File

@@ -107,6 +107,7 @@ def get_invoices(filters):
from `tabPurchase Invoice` where docstatus = 1 %s
order by posting_date desc, name desc""" % conditions, filters, as_dict=1)
def get_invoice_expense_map(invoice_list):
expense_details = webnotes.conn.sql("""select parent, expense_head, sum(amount) as amount
from `tabPurchase Invoice Item` where parent in (%s) group by parent, expense_head""" %

View File

@@ -0,0 +1,5 @@
wn.require("app/js/sales_trends_filters.js");
wn.query_reports["Sales Invoice Trends"] = {
filters: get_filters()
}

View File

@@ -0,0 +1,34 @@
# ERPNext - web based ERP (http://erpnext.com)
# Copyright (C) 2012 Web Notes Technologies Pvt Ltd
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from __future__ import unicode_literals
import webnotes
from controllers.trends import get_columns,get_data
def execute(filters=None):
if not filters: filters ={}
data = []
trans = "Sales Invoice"
tab = ["tabSales Invoice","tabSales Invoice Item"]
details = get_columns(filters, trans)
data = get_data(filters, tab, details)
if not data :
webnotes.msgprint("Data not found for selected criterias")
return details["columns"], data

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-06-13 18:44:21",
"docstatus": 0,
"modified": "2013-06-13 18:44:21",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Sales Invoice",
"report_name": "Sales Invoice Trends",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Sales Invoice Trends"
}
]

View File

@@ -26,17 +26,23 @@ from utilities import build_filter_conditions
class FiscalYearError(webnotes.ValidationError): pass
def get_fiscal_year(date, verbose=1):
return get_fiscal_years(date, verbose=1)[0]
def get_fiscal_year(date=None, fiscal_year=None, verbose=1):
return get_fiscal_years(date, fiscal_year, verbose=1)[0]
def get_fiscal_years(date, verbose=1):
def get_fiscal_years(date=None, fiscal_year=None, verbose=1):
# if year start date is 2012-04-01, year end date should be 2013-03-31 (hence subdate)
cond = ""
if fiscal_year:
cond = "name = '%s'" % fiscal_year
else:
cond = "'%s' >= year_start_date and '%s' < adddate(year_start_date, interval 1 year)" % \
(date, date)
fy = webnotes.conn.sql("""select name, year_start_date,
subdate(adddate(year_start_date, interval 1 year), interval 1 day)
as year_end_date
from `tabFiscal Year`
where %s >= year_start_date and %s < adddate(year_start_date, interval 1 year)
order by year_start_date desc""", (date, date))
where %s
order by year_start_date desc""" % cond)
if not fy:
error_msg = """%s not in any Fiscal Year""" % formatdate(date)