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

Conflicts:
	patches/december_2012/deprecate_tds.py
	patches/june_2012/reports_list_permission.py
	selling/doctype/sales_bom/locale/_messages_doc.json
	selling/doctype/sales_bom/locale/ar-doc.json
	selling/doctype/sales_bom/locale/de-doc.json
	selling/doctype/sales_bom/locale/es-doc.json
	selling/doctype/sales_bom/locale/fr-doc.json
	selling/doctype/sales_bom/locale/hi-doc.json
	selling/doctype/sales_bom/locale/hr-doc.json
	selling/doctype/sales_bom/locale/nl-doc.json
	selling/doctype/sales_bom/locale/pt-BR-doc.json
	selling/doctype/sales_bom/locale/pt-doc.json
	selling/doctype/sales_bom/locale/sr-doc.json
	selling/doctype/sales_bom/locale/ta-doc.json
	selling/doctype/sales_bom/locale/th-doc.json
	selling/doctype/sales_bom_item/locale/_messages_doc.json
	selling/doctype/sales_bom_item/locale/ar-doc.json
	selling/doctype/sales_bom_item/locale/de-doc.json
	selling/doctype/sales_bom_item/locale/es-doc.json
	selling/doctype/sales_bom_item/locale/fr-doc.json
	selling/doctype/sales_bom_item/locale/hi-doc.json
	selling/doctype/sales_bom_item/locale/hr-doc.json
	selling/doctype/sales_bom_item/locale/nl-doc.json
	selling/doctype/sales_bom_item/locale/pt-BR-doc.json
	selling/doctype/sales_bom_item/locale/pt-doc.json
	selling/doctype/sales_bom_item/locale/sr-doc.json
	selling/doctype/sales_bom_item/locale/ta-doc.json
	selling/doctype/sales_bom_item/locale/th-doc.json
This commit is contained in:
Anand Doshi
2013-06-26 14:07:29 +05:30
30 changed files with 273 additions and 214 deletions

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,39 @@
// 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/>.
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.toggle_enable('new_item_code', doc.__islocal);
if(!doc.__islocal) {
cur_frm.add_custom_button("Check for Duplicates", function() {
cur_frm.call_server('check_duplicate', 1)
}, 'icon-search')
}
}
cur_frm.fields_dict.new_item_code.get_query = function() {
return 'select name, description from tabItem where is_stock_item="No" and is_sales_item="Yes"\
and name not in (select name from `tabSales BOM`)\
and `%(key)s` like "%s"'
}
cur_frm.fields_dict.new_item_code.query_description = 'Select Item where "Is Stock Item" is "No" \
and "Is Sales Item" is "Yes" and there is no other Sales BOM';
cur_frm.cscript.item_code = function(doc, dt, dn) {
var d = locals[dt][dn];
if (d.item_code){
get_server_fields('get_item_details', d.item_code, 'sales_bom_items', doc ,dt, dn, 1);
}
}

View File

@@ -0,0 +1,85 @@
# 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 webnotes.utils import flt
from webnotes.model.utils import getlist
class DocType:
def __init__(self,d,dl):
self.doc, self.doclist = d,dl
def autoname(self):
self.doc.name = self.doc.new_item_code
def validate(self):
# check for duplicate
self.check_duplicate()
self.validate_main_item()
def validate_main_item(self):
"""main item must have Is Stock Item as No and Is Sales Item as Yes"""
if not webnotes.conn.sql("""select name from tabItem where name=%s and
ifnull(is_stock_item,'')='No' and ifnull(is_sales_item,'')='Yes'""", self.doc.new_item_code):
webnotes.msgprint("""Parent Item %s is either a Stock Item or a not a Sales Item""",
raise_exception=1)
def get_item_details(self, name):
det = webnotes.conn.sql("""select description, stock_uom from `tabItem`
where name = %s""", name)
rate = webnotes.conn.sql("""select ref_rate from `tabItem Price`
where price_list_name = %s and parent = %s
and ref_currency = %s""", (self.doc.price_list, name, self.doc.currency))
return {
'description' : det and det[0][0] or '',
'uom': det and det[0][1] or '',
'rate': rate and flt(rate[0][0]) or 0.00
}
def check_duplicate(self, finder=0):
il = getlist(self.doclist, "sales_bom_items")
if not il:
webnotes.msgprint("Add atleast one item")
return
# get all Sales BOM that have the first item
sbl = webnotes.conn.sql("""select distinct parent from `tabSales BOM Item` where item_code=%s
and parent != %s and docstatus != 2""", (il[0].item_code, self.doc.name))
# check all siblings
sub_items = [[d.item_code, flt(d.qty)] for d in il]
for s in sbl:
t = webnotes.conn.sql("""select item_code, qty from `tabSales BOM Item` where parent=%s and
docstatus != 2""", s[0])
t = [[d[0], flt(d[1])] for d in t]
if self.has_same_items(sub_items, t):
webnotes.msgprint("%s has the same Sales BOM details" % s[0])
raise Exception
if finder:
webnotes.msgprint("There is no Sales BOM present with the following Combination.")
def has_same_items(self, l1, l2):
if len(l1)!=len(l2): return 0
for l in l2:
if l not in l1:
return 0
for l in l1:
if l not in l2:
return 0
return 1

View File

@@ -0,0 +1,99 @@
[
{
"creation": "2013-06-20 11:53:21",
"docstatus": 0,
"modified": "2013-06-25 16:43:18",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"description": "Aggregate group of **Items** into another **Item**. This is useful if you are bundling a certain **Items** into a package and you maintain stock of the packed **Items** and not the aggregate **Item**. \n\nThe package **Item** will have \"Is Stock Item\" as \"No\" and \"Is Sales Item\" as \"Yes\".\n\nFor Example: If you are selling Laptops and Backpacks separately and have a special price if the customer buys both, then the Laptop + Backpack will be a new Sales BOM Item.\n\nNote: BOM = Bill of Materials",
"doctype": "DocType",
"document_type": "Master",
"is_submittable": 0,
"module": "Selling",
"name": "__common__"
},
{
"doctype": "DocField",
"name": "__common__",
"parent": "Sales BOM",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0
},
{
"doctype": "DocPerm",
"name": "__common__",
"parent": "Sales BOM",
"parentfield": "permissions",
"parenttype": "DocType",
"permlevel": 0,
"read": 1,
"report": 1,
"submit": 0
},
{
"doctype": "DocType",
"name": "Sales BOM"
},
{
"doctype": "DocField",
"fieldname": "basic_section",
"fieldtype": "Section Break",
"label": "Sales BOM Item"
},
{
"description": "The Item that represents the Package. This Item must have \"Is Stock Item\" as \"No\" and \"Is Sales Item\" as \"Yes\"",
"doctype": "DocField",
"fieldname": "new_item_code",
"fieldtype": "Link",
"label": "Parent Item",
"no_copy": 1,
"oldfieldname": "new_item_code",
"oldfieldtype": "Data",
"options": "Item",
"reqd": 1
},
{
"description": "List items that form the package.",
"doctype": "DocField",
"fieldname": "item_section",
"fieldtype": "Section Break",
"label": "Package Items"
},
{
"doctype": "DocField",
"fieldname": "sales_bom_items",
"fieldtype": "Table",
"label": "Sales BOM Items",
"oldfieldname": "sales_bom_items",
"oldfieldtype": "Table",
"options": "Sales BOM Item",
"reqd": 1
},
{
"amend": 1,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"role": "Material Manager",
"write": 1
},
{
"amend": 0,
"cancel": 0,
"create": 0,
"doctype": "DocPerm",
"role": "Material User",
"write": 0
},
{
"amend": 0,
"cancel": 1,
"create": 1,
"doctype": "DocPerm",
"role": "Sales User",
"write": 1
}
]

View File

@@ -0,0 +1,20 @@
test_records = [
[
{
"doctype": "Sales BOM",
"new_item_code": "_Test Sales BOM Item"
},
{
"doctype": "Sales BOM Item",
"item_code": "_Test Item",
"parentfield": "sales_bom_items",
"qty": 5.0
},
{
"doctype": "Sales BOM Item",
"item_code": "_Test Item Home Desktop 100",
"parentfield": "sales_bom_items",
"qty": 2.0
}
],
]

View File

@@ -0,0 +1 @@
from __future__ import unicode_literals

View File

@@ -0,0 +1,22 @@
# 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
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl

View File

@@ -0,0 +1,75 @@
[
{
"creation": "2013-05-23 16:55:51",
"docstatus": 0,
"modified": "2013-06-26 13:45:41",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "DocType",
"istable": 1,
"module": "Selling",
"name": "__common__"
},
{
"doctype": "DocField",
"name": "__common__",
"parent": "Sales BOM Item",
"parentfield": "fields",
"parenttype": "DocType",
"permlevel": 0
},
{
"doctype": "DocType",
"name": "Sales BOM Item"
},
{
"doctype": "DocField",
"fieldname": "item_code",
"fieldtype": "Link",
"label": "Item",
"oldfieldname": "item_code",
"oldfieldtype": "Link",
"options": "Item",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "qty",
"fieldtype": "Float",
"label": "Qty",
"oldfieldname": "qty",
"oldfieldtype": "Currency",
"reqd": 1
},
{
"doctype": "DocField",
"fieldname": "description",
"fieldtype": "Text",
"label": "Description",
"oldfieldname": "description",
"oldfieldtype": "Text",
"print_width": "300px",
"width": "300px"
},
{
"doctype": "DocField",
"fieldname": "rate",
"fieldtype": "Float",
"label": "Rate",
"oldfieldname": "rate",
"oldfieldtype": "Currency"
},
{
"doctype": "DocField",
"fieldname": "uom",
"fieldtype": "Link",
"label": "UOM",
"oldfieldname": "uom",
"oldfieldtype": "Link",
"options": "UOM",
"read_only": 1,
"search_index": 0
}
]

View File

@@ -24,7 +24,7 @@ from webnotes.model.code import get_obj
from webnotes import msgprint
sql = webnotes.conn.sql
# ----------
class DocType:
@@ -45,17 +45,16 @@ class DocType:
elif self.doc.send_to == 'All Lead (Open)':
rec = sql("select lead_name, mobile_no from tabLead where ifnull(mobile_no,'')!='' and docstatus != 2 and status = 'Open'")
elif self.doc.send_to == 'All Employee (Active)':
where_clause = self.doc.department and " and t1.department = '%s'" % self.doc.department or ""
where_clause += self.doc.branch and " and t1.branch = '%s'" % self.doc.branch or ""
rec = sql("select t1.employee_name, t2.cell_number from `tabEmployee` t1, `tabEmployee Profile` t2 where t2.employee = t1.name and t1.status = 'Active' and t1.docstatus != 2 and ifnull(t2.cell_number,'')!='' %s" % where_clause)
where_clause = self.doc.department and " and department = '%s'" % self.doc.department or ""
where_clause += self.doc.branch and " and branch = '%s'" % self.doc.branch or ""
rec = sql("select employee_name, cell_number from `tabEmployee` where status = 'Active' and docstatus < 2 and ifnull(cell_number,'')!='' %s" % where_clause)
elif self.doc.send_to == 'All Sales Person':
rec = sql("select sales_person_name, mobile_no from `tabSales Person` where docstatus != 2 and ifnull(mobile_no,'')!=''")
rec_list = ''
for d in rec:
rec_list += d[0] + ' - ' + d[1] + '\n'
self.doc.receiver_list = rec_list
webnotes.errprint(rec_list)
def get_receiver_nos(self):
receiver_nos = []
for d in self.doc.receiver_list.split('\n'):

View File

@@ -173,13 +173,11 @@ wn.module_page["Selling"] = [
},
{
"label":wn._("Territory Target Variance (Item Group-Wise)"),
route: "query-report/Territory Target Variance (Item Group-Wise)",
doctype: "Sales Order"
route: "query-report/Territory Target Variance Item Group-Wise"
},
{
"label":wn._("Sales Person Target Variance (Item Group-Wise)"),
route: "query-report/Sales Person Target Variance (Item Group-Wise)",
doctype: "Sales Order"
route: "query-report/Sales Person Target Variance Item Group-Wise"
},
{
"label":wn._("Customers Not Buying Since Long Time"),
@@ -196,6 +194,10 @@ wn.module_page["Selling"] = [
route: "query-report/Sales Order Trends",
doctype: "Sales Order"
},
{
"label":wn._("Available Stock for Packing Items"),
route: "query-report/Available Stock for Packing Items",
},
{
"label":wn._("Pending SO Items For Purchase Request"),
route: "query-report/Pending SO Items For Purchase Request"

View File

@@ -0,0 +1,92 @@
# 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 webnotes.utils import flt
def execute(filters=None):
if not filters: filters = {}
columns = get_columns()
iwq_map = get_item_warehouse_quantity_map()
item_map = get_item_details()
data = []
for sbom, warehouse in iwq_map.items():
total = 0
total_qty = 0
for wh, item_qty in warehouse.items():
total += 1
row = [sbom, item_map.get(sbom).item_name, item_map.get(sbom).description,
item_map.get(sbom).stock_uom, wh]
available_qty = min(item_qty.values())
total_qty += flt(available_qty)
row += [available_qty]
if available_qty:
data.append(row)
if (total == len(warehouse)):
row = ["", "", "Total", "", "", total_qty]
data.append(row)
return columns, data
def get_columns():
columns = ["Item Code:Link/Item:100", "Item Name::100", "Description::120", \
"UOM:Link/UOM:80", "Warehouse:Link/Warehouse:100", "Quantity::100"]
return columns
def get_sales_bom_items():
sbom_item_map = {}
for sbom in webnotes.conn.sql("""select parent, item_code, qty from `tabSales BOM Item`
where docstatus < 2""", as_dict=1):
sbom_item_map.setdefault(sbom.parent, {}).setdefault(sbom.item_code, sbom.qty)
return sbom_item_map
def get_item_details():
item_map = {}
for item in webnotes.conn.sql("""select name, item_name, description, stock_uom
from `tabItem`""", as_dict=1):
item_map.setdefault(item.name, item)
return item_map
def get_item_warehouse_quantity():
iwq_map = {}
bin = webnotes.conn.sql("""select item_code, warehouse, actual_qty from `tabBin`
where actual_qty > 0""")
for item, wh, qty in bin:
iwq_map.setdefault(item, {}).setdefault(wh, qty)
return iwq_map
def get_item_warehouse_quantity_map():
sbom_map = {}
iwq_map = get_item_warehouse_quantity()
sbom_item_map = get_sales_bom_items()
for sbom, sbom_items in sbom_item_map.items():
for item, child_qty in sbom_items.items():
for wh, qty in iwq_map.get(item, {}).items():
avail_qty = flt(qty) / flt(child_qty)
sbom_map.setdefault(sbom, {}).setdefault(wh, {}) \
.setdefault(item, avail_qty)
return sbom_map

View File

@@ -0,0 +1,21 @@
[
{
"creation": "2013-06-21 13:40:05",
"docstatus": 0,
"modified": "2013-06-21 15:06:40",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "Report",
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Sales BOM",
"report_name": "Available Stock for Packing Items",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Available Stock for Packing Items"
}
]

View File

@@ -1,4 +1,4 @@
wn.query_reports["Sales Person Target Variance (Item Group-Wise)"] = {
wn.query_reports["Sales Person Target Variance Item Group-Wise"] = {
"filters": [
{
fieldname: "fiscal_year",

View File

@@ -16,18 +16,21 @@
from __future__ import unicode_literals
import webnotes
import calendar
from webnotes import _, msgprint
from webnotes.utils import flt
import time
from accounts.utils import get_fiscal_year
from controllers.trends import get_period_date_ranges, get_period_month_ranges
def execute(filters=None):
if not filters: filters = {}
columns = get_columns(filters)
period_month_ranges = get_period_month_ranges(filters)
period_month_ranges = get_period_month_ranges(filters["period"], filters["fiscal_year"])
sim_map = get_salesperson_item_month_map(filters)
precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2
data = []
for salesperson, salesperson_items in sim_map.items():
@@ -39,7 +42,7 @@ def execute(filters=None):
for month in relevant_months:
month_data = monthwise_data.get(month, {})
for i, fieldname in enumerate(["target", "achieved", "variance"]):
value = flt(month_data.get(fieldname))
value = flt(month_data.get(fieldname), precision)
period_data[i] += value
totals[i] += value
period_data[2] = period_data[0] - period_data[1]
@@ -61,7 +64,7 @@ def get_columns(filters):
group_months = False if filters["period"] == "Monthly" else True
for from_date, to_date in get_period_date_ranges(filters):
for from_date, to_date in get_period_date_ranges(filters["period"], filters["fiscal_year"]):
for label in ["Target (%s)", "Achieved (%s)", "Variance (%s)"]:
if group_months:
columns.append(label % (from_date.strftime("%b") + " - " + to_date.strftime("%b")))
@@ -70,49 +73,14 @@ def get_columns(filters):
return columns + ["Total Target::80", "Total Achieved::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 sales person & item group details
def get_salesperson_details(filters):
return webnotes.conn.sql("""select sp.name, td.item_group, td.target_qty,
td.target_amount, sp.distribution_id
from `tabSales Person` sp, `tabTarget Detail` td
where td.parent=sp.name and td.fiscal_year=%s and
ifnull(sp.distribution_id, '')!='' order by sp.name""" %
('%s'), (filters.get("fiscal_year")), as_dict=1)
ifnull(sp.distribution_id, '')!='' order by sp.name""",
(filters["fiscal_year"]), as_dict=1)
#Get target distribution details of item group
def get_target_distribution_details(filters):
@@ -121,14 +89,14 @@ def get_target_distribution_details(filters):
for d in webnotes.conn.sql("""select bdd.month, bdd.percentage_allocation \
from `tabBudget Distribution Detail` bdd, `tabBudget Distribution` bd, \
`tabTerritory` t where bdd.parent=bd.name and t.distribution_id=bd.name and \
bd.fiscal_year=%s """ % ('%s'), (filters.get("fiscal_year")), as_dict=1):
bd.fiscal_year=%s""", (filters["fiscal_year"]), as_dict=1):
target_details.setdefault(d.month, d)
return target_details
#Get achieved details from sales order
def get_achieved_details(filters):
start_date, end_date = get_year_start_end_date(filters)
start_date, end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
return webnotes.conn.sql("""select soi.item_code, soi.qty, soi.amount, so.transaction_date,
st.sales_person, MONTHNAME(so.transaction_date) as month_name
@@ -149,35 +117,27 @@ def get_salesperson_item_month_map(filters):
for month in tdd:
sim_map.setdefault(sd.name, {}).setdefault(sd.item_group, {})\
.setdefault(month, webnotes._dict({
"target": 0.0, "achieved": 0.0, "variance": 0.0
"target": 0.0, "achieved": 0.0
}))
tav_dict = sim_map[sd.name][sd.item_group][month]
for ad in achieved_details:
if (filters["target_on"] == "Quantity"):
tav_dict.target = sd.target_qty*(tdd[month]["percentage_allocation"]/100)
if ad.month_name == month and ''.join(get_item_group(ad.item_code)) == sd.item_group \
tav_dict.target = flt(sd.target_qty) * \
(tdd[month]["percentage_allocation"]/100)
if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \
and ad.sales_person == sd.name:
tav_dict.achieved += ad.qty
if (filters["target_on"] == "Amount"):
tav_dict.target = sd.target_amount*(tdd[month]["percentage_allocation"]/100)
if ad.month_name == month and ''.join(get_item_group(ad.item_code)) == sd.item_group \
tav_dict.target = flt(sd.target_amount) * \
(tdd[month]["percentage_allocation"]/100)
if ad.month_name == month and get_item_group(ad.item_code) == sd.item_group \
and ad.sales_person == sd.name:
tav_dict.achieved += ad.amount
return sim_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]
def get_item_group(item_name):
"""Get Item Group of an item"""
return webnotes.conn.sql_list("select item_group from `tabItem` where name=%s""" %
('%s'), (item_name))
return webnotes.conn.get_value("Item", item_name, "item_group")

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-06-18 12:09:40",
"creation": "2013-06-21 12:14:15",
"docstatus": 0,
"modified": "2013-06-18 12:09:40",
"modified": "2013-06-21 12:14:15",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -11,11 +11,11 @@
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Sales Order",
"report_name": "Sales Person Target Variance (Item Group-Wise)",
"report_name": "Sales Person Target Variance Item Group-Wise",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Sales Person Target Variance (Item Group-Wise)"
"name": "Sales Person Target Variance Item Group-Wise"
}
]

View File

@@ -1,4 +1,4 @@
wn.query_reports["Territory Target Variance (Item Group-Wise)"] = {
wn.query_reports["Territory Target Variance Item Group-Wise"] = {
"filters": [
{
fieldname: "fiscal_year",

View File

@@ -16,19 +16,21 @@
from __future__ import unicode_literals
import webnotes
import calendar
from webnotes import _, msgprint
from webnotes.utils import flt
import time
from accounts.utils import get_fiscal_year
from controllers.trends import get_period_date_ranges, get_period_month_ranges
def execute(filters=None):
if not filters: filters = {}
columns = get_columns(filters)
period_month_ranges = get_period_month_ranges(filters)
period_month_ranges = get_period_month_ranges(filters["period"], filters["fiscal_year"])
tim_map = get_territory_item_month_map(filters)
precision = webnotes.conn.get_value("Global Defaults", None, "float_precision") or 2
data = []
for territory, territory_items in tim_map.items():
@@ -40,7 +42,7 @@ def execute(filters=None):
for month in relevant_months:
month_data = monthwise_data.get(month, {})
for i, fieldname in enumerate(["target", "achieved", "variance"]):
value = flt(month_data.get(fieldname))
value = flt(month_data.get(fieldname), precision)
period_data[i] += value
totals[i] += value
period_data[2] = period_data[0] - period_data[1]
@@ -61,7 +63,7 @@ def get_columns(filters):
group_months = False if filters["period"] == "Monthly" else True
for from_date, to_date in get_period_date_ranges(filters):
for from_date, to_date in get_period_date_ranges(filters["period"], filters["fiscal_year"]):
for label in ["Target (%s)", "Achieved (%s)", "Variance (%s)"]:
if group_months:
columns.append(label % (from_date.strftime("%b") + " - " + to_date.strftime("%b")))
@@ -70,41 +72,6 @@ def get_columns(filters):
return columns + ["Total Target::80", "Total Achieved::80", "Total Variance::80"]
def get_period_date_ranges(filters):
from dateutil.relativedelta import relativedelta
year_start_date, year_end_date = get_fiscal_year(fiscal_year = filters["fiscal_year"])[1:]
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 territory & item group details
def get_territory_details(filters):
return webnotes.conn.sql("""select t.name, td.item_group, td.target_qty,
@@ -112,7 +79,7 @@ def get_territory_details(filters):
from `tabTerritory` t, `tabTarget Detail` td
where td.parent=t.name and td.fiscal_year=%s and
ifnull(t.distribution_id, '')!='' order by t.name""",
filters.get("fiscal_year"), as_dict=1)
(filters["fiscal_year"]), as_dict=1)
#Get target distribution details of item group
def get_target_distribution_details(filters):
@@ -121,7 +88,7 @@ def get_target_distribution_details(filters):
for d in webnotes.conn.sql("""select bdd.month, bdd.percentage_allocation \
from `tabBudget Distribution Detail` bdd, `tabBudget Distribution` bd, \
`tabTerritory` t where bdd.parent=bd.name and t.distribution_id=bd.name and \
bd.fiscal_year=%s""" % ('%s'), (filters.get("fiscal_year")), as_dict=1):
bd.fiscal_year=%s""", (filters["fiscal_year"]), as_dict=1):
target_details.setdefault(d.month, d)
return target_details
@@ -155,7 +122,8 @@ def get_territory_item_month_map(filters):
for ad in achieved_details:
if (filters["target_on"] == "Quantity"):
tav_dict.target = flt(td.target_qty) * (tdd[month]["percentage_allocation"]/100)
tav_dict.target = flt(td.target_qty) * \
(tdd[month]["percentage_allocation"]/100)
if ad.month_name == month and get_item_group(ad.item_code) == td.item_group \
and ad.territory == td.name:
tav_dict.achieved += ad.qty

View File

@@ -1,8 +1,8 @@
[
{
"creation": "2013-06-07 15:13:13",
"creation": "2013-06-21 12:15:00",
"docstatus": 0,
"modified": "2013-06-07 15:13:13",
"modified": "2013-06-21 12:15:00",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -11,11 +11,11 @@
"is_standard": "Yes",
"name": "__common__",
"ref_doctype": "Sales Order",
"report_name": "Territory Target Variance (Item Group-Wise)",
"report_name": "Territory Target Variance Item Group-Wise",
"report_type": "Script Report"
},
{
"doctype": "Report",
"name": "Territory Target Variance (Item Group-Wise)"
"name": "Territory Target Variance Item Group-Wise"
}
]