item group cleanup

This commit is contained in:
Rushabh Mehta 2012-07-12 11:33:00 +05:30
parent cf969143f2
commit 5faf37f312
18 changed files with 256 additions and 672 deletions

View File

@ -210,6 +210,7 @@ class DocType:
# ON UPDATE
def on_update(self):
# update nsm
self.update_nsm_model()
# Add curret year balance
@ -256,8 +257,8 @@ class DocType:
self.check_balance_before_trash()
# rebuild tree
set(self.doc,'old_parent', '')
self.update_nsm_model()
from webnotes.utils.nestedset import update_remove_node
update_remove_node('Account', self.doc.name)
# delete all cancelled gl entry of this account
sql("delete from `tabGL Entry` where account = %s and ifnull(is_cancelled, 'No') = 'Yes'", self.doc.name)

View File

@ -17,9 +17,10 @@
import webnotes
from webnotes.model.doclist import getlist
from webnotes import msgprint
class DocType:
from webnotes.utils.nestedset import DocTypeNestedSet
class DocType(DocTypeNestedSet):
def __init__(self,d,dl):
self.doc, self.doclist = d,dl
self.nsm_parent_field = 'parent_cost_center'
@ -78,7 +79,6 @@ class DocType:
msgprint("Account " + d.account + "has been entered more than once for fiscal year " + d.fiscal_year, raise_exception=1)
else:
check_acc_list.append([d.account, d.fiscal_year])
def validate(self):
"""
@ -89,21 +89,3 @@ class DocType:
self.validate_mandatory()
self.validate_budget_details()
def update_nsm_model(self):
"""
update Nested Set Model
"""
import webnotes.utils.nestedset
webnotes.utils.nestedset.update_nsm(self)
def on_update(self):
self.update_nsm_model()
def on_trash(self):
if self.check_if_child_exists():
msgprint("Child exists for this cost center. You can not trash this account.", raise_exception=1)
# rebuild tree
webnotes.conn.set_value(self.doc,'old_parent', '')
self.update_nsm_model()

View File

@ -64,7 +64,8 @@ pscript['onshow_Accounts Browser'] = function(wrapper){
var ctype = wn.get_route()[1] || 'Account';
wrapper.appframe.clear_breadcrumbs();
wrapper.appframe.add_breadcrumb('Chart of '+ctype+'s')
wrapper.appframe.add_breadcrumb('Chart of '+ctype+'s');
document.title = 'Chart of '+ctype+'s';
wrapper.appframe.add_breadcrumb(' in <a href="#!accounts-home">Accounts</a>');
if(erpnext.account_chart && erpnext.account_chart.ctype != ctype) {

View File

@ -34,6 +34,8 @@ pscript['onshow_Sales Browser'] = function(wrapper){
wrapper.appframe.clear_breadcrumbs();
wrapper.appframe.add_breadcrumb(ctype+' Tree')
document.title = ctype+' Tree';
wrapper.appframe.add_breadcrumb(' in <a href="#!selling-home">Selling</a>');
if(erpnext.sales_chart && erpnext.sales_chart.ctype != ctype) {

View File

@ -77,6 +77,11 @@
title = "Commission partners and targets"
href="#!List/Sales Partner">Sales Partner</a>
</div>
<div class="section-item">
<a class="section-link"
title = "Tree of item classification"
href="#!Sales Browser/Item Group">Item Group</a>
</div>
<div class="section-item">
<a class="section-link"
title = "Sales campaigns"
@ -84,7 +89,7 @@
</div>
<div class="section-item">
<a class="section-link"
title = "Send mass SMS to your conatacts, leads and employees"
title = "Send mass SMS to your contacts, leads and employees"
href="#!Form/SMS Center/SMS Center">SMS Center</a>
</div>
</div>

View File

@ -14,21 +14,14 @@
// 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.onload = function(){
if(doc.__islocal){
doc.parent_item_group = 'Root';
refresh('parent_item_group');
}
cur_frm.cscript.set_breadcrumbs = function(barea) {
cur_frm.frm_head.appframe.add_breadcrumb(cur_frm.docname);
cur_frm.frm_head.appframe.add_breadcrumb(' in <a href="#!Sales Browser/Item Group">\
Item Group Tree</a>');
cur_frm.frm_head.appframe.add_breadcrumb(' in <a href="#!selling-home">Selling</a>');
}
//get query select item group
cur_frm.fields_dict['parent_item_group'].get_query = function(doc,cdt,cdn) {
return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.`is_group` = "Yes" AND `tabItem Group`.`docstatus`!= 2 AND `tabItem Group`.`name` !="'+doc.item_group_name+'" AND `tabItem Group`.%(key)s LIKE "%s" ORDER BY `tabItem Group`.`name` ASC LIMIT 50';
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}

View File

@ -14,66 +14,15 @@
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, getchildren, make_autoname
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
from webnotes.model.doclist import getlist
from webnotes.utils import flt
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
from webnotes.utils.nestedset import DocTypeNestedSet
class DocType:
def __init__(self,d,dl):
self.doc, self.doclist = d,dl
self.nsm_parent_field = 'parent_item_group';
# update Node Set Model
def update_nsm_model(self):
import webnotes
import webnotes.utils.nestedset
webnotes.utils.nestedset.update_nsm(self)
# ON UPDATE
#--------------------------------------
def on_update(self):
# update nsm
self.update_nsm_model()
def validate(self):
if self.doc.lft and self.doc.rgt:
res = sql("select name from `tabItem Group` where is_group = 'Yes' and docstatus!= 2 and name ='%s' and name !='%s'"%(self.doc.parent_item_group,self.doc.item_group_name))
if not res:
msgprint("Please enter proper parent item group.")
raise Exception
r = sql("select name from `tabItem Group` where name = '%s' and docstatus = 2"%(self.doc.item_group_name))
if r:
msgprint("'%s' record is trashed. To untrash please go to Setup & click on Trash."%(self.doc.item_group_name))
raise Exception
def on_trash(self):
item = sql("select name from `tabItem` where ifnull(item_group, '') = %s", self.doc.name)
item = [d[0] for d in item]
if item:
msgprint("""Item Group: %s can not be trashed/deleted because it is used in item: %s.
To trash/delete this, remove/change item group in item master""" % (self.doc.name, item or ''), raise_exception=1)
if sql("select name from `tabItem Group` where parent_item_group = %s and docstatus != 2", self.doc.name):
msgprint("Child item group exists for this item group. You can not trash/cancel/delete this item group.", raise_exception=1)
# rebuild tree
set(self.doc,'old_parent', '')
self.update_nsm_model()
class DocType(DocTypeNestedSet):
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
self.nsm_parent_field = 'parent_item_group';

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:36:21',
'creation': '2012-07-03 13:30:53',
'docstatus': 0,
'modified': '2012-03-27 14:36:21',
'modified': '2012-07-12 11:26:21',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -17,6 +17,7 @@
'autoname': u'field:item_group_name',
'colour': u'White:FFF',
'default_print_format': u'Standard',
'description': u'Item Classification',
'doctype': 'DocType',
'document_type': u'Master',
'in_create': 1,
@ -27,7 +28,7 @@
'section_style': u'Simple',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 59
'version': 1
},
# These values are common for all DocField
@ -55,6 +56,54 @@
'name': u'Item Group'
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Material Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'cancel': 1,
@ -75,54 +124,6 @@
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Material Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Material User',
'submit': 0,
'write': 0
},
# DocField
{
'doctype': u'DocField',
@ -137,20 +138,6 @@
'search_index': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'description',
'fieldtype': u'Text',
'label': u'Description',
'no_copy': 0,
'oldfieldname': u'description',
'oldfieldtype': u'Text',
'permlevel': 0,
'search_index': 0,
'width': u'300px'
},
# DocField
{
'colour': u'White:FFF',
@ -167,14 +154,9 @@
# DocField
{
'doctype': u'DocField',
'fieldname': u'show_in_catalogue',
'fieldtype': u'Check',
'label': u'Show in catalogue',
'no_copy': 0,
'oldfieldname': u'show_in_catalogue',
'oldfieldtype': u'Check',
'permlevel': 0,
'search_index': 0
'fieldname': u'cb0',
'fieldtype': u'Column Break',
'permlevel': 0
},
# DocField

View File

@ -95,55 +95,7 @@ cur_frm.cscript.make_contact = function() {
}
// ******************** ITEM Group ********************************
cur_frm.fields_dict['partner_target_details'].grid.get_field("item_group").get_query = function(doc, dt, dn) {
return 'SELECT `tabItem Group`.`name`,`tabItem Group`.`parent_item_group` FROM `tabItem Group` WHERE `tabItem Group`.is_group="No" AND `tabItem Group`.docstatus != 2 AND `tabItem Group`.%(key)s LIKE "%s" LIMIT 50'
}
// make sales order list
cur_frm.cscript.make_so_list = function(parent, doc){
var lst = new Listing();
lst.colwidths = ['5%','20%','20%','15%','20%','20%'];
lst.colnames = ['Sr.','Id','Status','SO Date','Total Commission','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency','Currency'];
lst.coloptions = ['','Sales Order','','','','',''];
cur_frm.cscript.set_list_opts(lst);
var q = repl("select name,status,transaction_date, total_commission,grand_total from `tabSales Order` where sales_partner='%(sp)s'", {'sp':doc.name});
var q_max = repl("select count(name) from `tabSales Order` where sales_partner='%(cust)s'", {'sp':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Sales Order','Sales Order');
}
// make delivery note list
cur_frm.cscript.make_dn_list = function(parent,doc){
var lst = new Listing();
lst.colwidths = ['5%','20%','20%','15%','20%','20%'];
lst.colnames = ['Sr.','Id','Status','Date','Total Commission','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency','Currency'];
lst.coloptions = ['','Delivery Note','','','','',''];
cur_frm.cscript.set_list_opts(lst);
var q = repl("select name,status,transaction_date, total_commission,grand_total from `tabDelivery Note` where sales_partner='%(sp)s'", {'sp':doc.name});
var q_max = repl("select count(name) from `tabDelivery Note` where sales_partner='%(cust)s'", {'sp':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Delivery Note','Delivery Note');
}
// make sales invoice list
cur_frm.cscript.make_si_list = function(parent,doc){
var lst = new Listing();
lst.colwidths = ['5%','25%','20%','25%','25%'];
lst.colnames = ['Sr.','Id','Invoice Date','Total Commission','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency','Currency'];
lst.coloptions = ['','Sales Invoice','','','',''];
cur_frm.cscript.set_list_opts(lst);
var q = repl("select name,posting_date, total_commission,grand_total from `tabSales Invoice` where sales_partner='%(sp)s'", {'sp':doc.name});
var q_max = repl("select count(name) from `tabSales Invoice` where sales_partner='%(cust)s'", {'sp':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Sales Invoice','Sales Invoice');
}

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-03-27 14:36:23',
'creation': '2012-07-03 13:30:54',
'docstatus': 0,
'modified': '2012-03-27 18:49:33',
'modified': '2012-07-12 11:22:15',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -17,6 +17,7 @@
'autoname': u'field:partner_name',
'colour': u'White:FFF',
'default_print_format': u'Standard',
'description': u'A **Sales Partner** is a third party distributor / dealer / commission agent / affiliate / reseller who sells the companies products for a commission. This is useful if you make the end sale to the **Customer**, involving your **Sales Partner**.\n\nIf you sell to your **Sales Partner** who in-turn sells it to the **Customer**, then you must make a **Customer** instead.',
'doctype': 'DocType',
'document_type': u'Master',
'in_create': 0,
@ -26,7 +27,7 @@
'section_style': u'Tabbed',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 74
'version': 1
},
# These values are common for all DocField
@ -54,49 +55,6 @@
'name': u'Sales Partner'
},
# DocPerm
{
'amend': 0,
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Sales Master Manager',
'submit': 0,
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Sales Master Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'System Manager',
'write': 1
},
# DocPerm
{
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'System Manager',
'write': 0
},
# DocPerm
{
'amend': 0,
@ -145,6 +103,49 @@
'write': 0
},
# DocPerm
{
'amend': 0,
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'Sales Master Manager',
'submit': 0,
'write': 1
},
# DocPerm
{
'amend': 0,
'cancel': 0,
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'Sales Master Manager',
'submit': 0,
'write': 0
},
# DocPerm
{
'cancel': 1,
'create': 1,
'doctype': u'DocPerm',
'permlevel': 0,
'role': u'System Manager',
'write': 1
},
# DocPerm
{
'create': 0,
'doctype': u'DocPerm',
'permlevel': 1,
'role': u'System Manager',
'write': 0
},
# DocField
{
'colour': u'White:FFF',
@ -152,7 +153,7 @@
'doctype': u'DocField',
'fieldname': u'basic_info',
'fieldtype': u'Section Break',
'label': u'Basic Info',
'label': u'Sales Partner Details',
'oldfieldtype': u'Section Break',
'permlevel': 0
},
@ -282,23 +283,11 @@
'doctype': u'DocField',
'fieldname': u'partner_target_details_section_break',
'fieldtype': u'Section Break',
'label': u'Partner Target Details',
'label': u'Sales Partner Target',
'oldfieldtype': u'Section Break',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'distribution_id',
'fieldtype': u'Link',
'label': u'Distribution Id',
'oldfieldname': u'distribution_id',
'oldfieldtype': u'Link',
'options': u'Budget Distribution',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
@ -312,37 +301,17 @@
'reqd': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'manage_html',
'fieldtype': u'HTML',
'hidden': 1,
'label': u'Manage HTML',
'oldfieldtype': u'HTML',
'permlevel': 0,
'print_hide': 1
},
# DocField
{
'colour': u'White:FFF',
'depends_on': u'eval:!doc.__islocal',
'description': u'Select Budget Distribution to unevenly distribute targets across months.',
'doctype': u'DocField',
'fieldname': u'transaction_history',
'fieldtype': u'Section Break',
'label': u'Transaction History',
'oldfieldtype': u'Section Break',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'history_html',
'fieldtype': u'HTML',
'label': u'History HTML',
'oldfieldtype': u'HTML',
'fieldname': u'distribution_id',
'fieldtype': u'Link',
'label': u'Target Distribution',
'oldfieldname': u'distribution_id',
'oldfieldtype': u'Link',
'options': u'Budget Distribution',
'permlevel': 0
},

View File

@ -14,30 +14,19 @@
// 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.set_breadcrumbs = function(barea) {
cur_frm.frm_head.appframe.add_breadcrumb(cur_frm.docname);
cur_frm.frm_head.appframe.add_breadcrumb(' in <a href="#!Sales Browser/Sales Person">\
Sales Person Tree</a>');
cur_frm.frm_head.appframe.add_breadcrumb(' in <a href="#!selling-home">Selling</a>');
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}
cur_frm.cscript.onload = function(){
if(doc.__islocal){
doc.parent_sales_person = 'Root';
refresh('parent_sales_person');
}
}
cur_frm.cscript.country = function(doc, cdt, cdn) {
var mydoc=doc;
$c('runserverobj', args={'method':'check_state', 'docs':compress_doclist(make_doclist(doc.doctype, doc.name))},
function(r,rt){
if(r.message) {
var doc = locals[mydoc.doctype][mydoc.name];
doc.state = '';
get_field(doc.doctype, 'state' , doc.name).options = r.message;
refresh_field('state');
}
}
);
}
}
//get query select sales person
cur_frm.fields_dict['parent_sales_person'].get_query = function(doc,cdt,cdn) {

View File

@ -17,79 +17,19 @@
# Please edit this list and import only required elements
import webnotes
from webnotes.model.doc import Document
from webnotes.model.doclist import getlist
from webnotes.model.code import get_obj
from webnotes import session, form, is_testing, msgprint, errprint
from webnotes.utils import flt, cstr
from webnotes.utils import flt
sql = webnotes.conn.sql
convert_to_lists = webnotes.conn.convert_to_lists
# -----------------------------------------------------------------------------------------
from webnotes.utils.nestedset import DocTypeNestedSet
class DocType:
class DocType(DocTypeNestedSet):
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
self.nsm_parent_field = 'parent_sales_person';
def check_state(self):
return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
# update Node Set Model
def update_nsm_model(self):
import webnotes
import webnotes.utils.nestedset
webnotes.utils.nestedset.update_nsm(self)
# ON UPDATE
#--------------------------------------
def on_update(self):
# update nsm
self.update_nsm_model()
def validate(self):
for d in getlist(self.doclist, 'target_details'):
if not flt(d.target_qty) and not flt(d.target_amount):
msgprint("Either target qty or target amount is mandatory.")
webnotes.msgprint("Either target qty or target amount is mandatory.")
raise Exception
#self.sync_with_contact()
def sync_with_contact(self):
cid = sql("select name from tabContact where sales_person_id = %s and is_sales_person=1", self.doc.name)
if cid:
d = Document('Contact', cid[0][0])
else:
d = Document('Contact')
name_split = self.doc.sales_person_name.split()
d.contact_name = self.doc.sales_person_name
d.first_name = name_split[0]
d.last_name = len(name_split) > 1 and name_split[1] or ''
d.email_id = self.doc.email_id
d.contact_no = d.mobile_no = self.doc.mobile_no
d.designation = self.doc.designation
d.department = self.doc.department
d.sales_person_id = self.doc.name
d.is_sales_person = 1
d.save(new = (not d.name))
def on_trash(self):
st = sql("select parent, parenttype from `tabSales Team` where ifnull(sales_person, '') = %s and docstatus != 2", self.doc.name)
st = [(d[1] + ' : ' + d[0]) for d in st]
if st:
msgprint("""Sales Person: %s can not be trashed/deleted because it is used in %s.
To trash/delete this, remove/change sales person in %s""" % (self.doc.name, st or '', st or ''), raise_exception=1)
if sql("select name from `tabSales Person` where parent_sales_person = %s and docstatus != 2", self.doc.name):
msgprint("Child sales person exists for this sales person. You can not trash/cancel this sales person.", raise_exception=1)
# rebuild tree
webnotes.conn.set(self.doc,'old_parent', '')
self.update_nsm_model()

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-04-13 11:56:32',
'creation': '2012-07-03 13:30:54',
'docstatus': 0,
'modified': '2012-05-31 11:28:32',
'modified': '2012-07-12 10:33:10',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -16,6 +16,7 @@
'allow_trash': 1,
'autoname': u'field:sales_person_name',
'colour': u'White:FFF',
'description': u'All Sales Transactions can be tagged against multiple **Sales Persons** so that you can set and monitor targets.',
'doctype': 'DocType',
'document_type': u'Master',
'in_create': 1,
@ -126,17 +127,6 @@
'permlevel': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'general_info',
'fieldtype': u'Section Break',
'label': u'General Info',
'oldfieldtype': u'Section Break',
'options': u'Simple',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
@ -167,17 +157,6 @@
'trigger': u'Client'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'sphelp',
'fieldtype': u'HTML',
'label': u'SPHelp',
'oldfieldtype': u'HTML',
'options': u'<a href="#!Sales Browser/Sales Person">To manage Sales Person, click here</a>',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
@ -191,6 +170,14 @@
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'cb0',
'fieldtype': u'Column Break',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
@ -201,125 +188,6 @@
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'department',
'fieldtype': u'Data',
'label': u'Department',
'oldfieldname': u'department',
'oldfieldtype': u'Data',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'designation',
'fieldtype': u'Data',
'label': u'Designation',
'oldfieldname': u'designation',
'oldfieldtype': u'Data',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'mobile_no',
'fieldtype': u'Data',
'label': u'Mobile No',
'oldfieldname': u'mobile_no',
'oldfieldtype': u'Data',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'column_break0',
'fieldtype': u'Column Break',
'oldfieldtype': u'Column Break',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'email_id',
'fieldtype': u'Data',
'label': u'Email Id',
'oldfieldname': u'email_id',
'oldfieldtype': u'Data',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'country',
'fieldtype': u'Select',
'in_filter': 1,
'label': u'Country',
'oldfieldname': u'country',
'oldfieldtype': u'Select',
'options': u'link:Country',
'permlevel': 0,
'search_index': 0,
'trigger': u'Client'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'state',
'fieldtype': u'Select',
'in_filter': 1,
'label': u'State',
'oldfieldname': u'state',
'oldfieldtype': u'Select',
'options': u'link:State',
'permlevel': 0,
'search_index': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'city',
'fieldtype': u'Data',
'label': u'City',
'oldfieldname': u'city',
'oldfieldtype': u'Data',
'permlevel': 0,
'reqd': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'territory',
'fieldtype': u'Link',
'hidden': 0,
'label': u'Territory',
'oldfieldname': u'territory',
'oldfieldtype': u'Link',
'options': u'Territory',
'permlevel': 0,
'search_index': 0
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'territory_help',
'fieldtype': u'HTML',
'label': u'Territory Help',
'oldfieldtype': u'HTML',
'options': u'<a href="#!Sales Browser/Territory">To manage Territories, click here</a>',
'permlevel': 0
},
# DocField
{
'doctype': u'DocField',
@ -368,25 +236,13 @@
# DocField
{
'doctype': u'DocField',
'fieldname': u'distribution_id',
'fieldtype': u'Link',
'label': u'Distribution Id',
'oldfieldname': u'distribution_id',
'oldfieldtype': u'Link',
'options': u'Budget Distribution',
'permlevel': 0,
'search_index': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Set targets Item Group-wise for this Sales Person.',
'doctype': u'DocField',
'fieldname': u'target_details_section_break',
'fieldtype': u'Section Break',
'label': u'Target Details',
'label': u'Sales Person Targets',
'oldfieldtype': u'Section Break',
'options': u'Simple',
'permlevel': 0
},
@ -400,5 +256,20 @@
'oldfieldtype': u'Table',
'options': u'Target Detail',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Select Budget Distribution to unevenly distribute targets across months.',
'doctype': u'DocField',
'fieldname': u'distribution_id',
'fieldtype': u'Link',
'label': u'Target Distribution',
'oldfieldname': u'distribution_id',
'oldfieldtype': u'Link',
'options': u'Budget Distribution',
'permlevel': 0,
'search_index': 0
}
]

View File

@ -15,17 +15,19 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
cur_frm.cscript.set_breadcrumbs = function(barea) {
cur_frm.frm_head.appframe.add_breadcrumb(cur_frm.docname);
cur_frm.frm_head.appframe.add_breadcrumb(' in <a href="#!Sales Browser/Territory">\
Territory Tree</a>');
cur_frm.frm_head.appframe.add_breadcrumb(' in <a href="#!selling-home">Selling</a>');
}
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
}
cur_frm.cscript.onload = function(){
if(doc.__islocal){
doc.parent_territory = 'All Territories';
refresh('parent_territory');
}
}

View File

@ -8,87 +8,28 @@
#
# 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
# 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/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# Please edit this list and import only required elements
import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, generate_hash, getTraceback, get_defaults, get_first_day, get_last_day, getdate, has_common, month_name, now, nowdate, replace_newlines, sendmail, set_default, str_esc_quote, user_format, validate_email_add
from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, getchildren, make_autoname
from webnotes.model.doclist import getlist, copy_doclist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
from webnotes import session, form, is_testing, msgprint, errprint
from webnotes.model.doclist import getlist
from webnotes.utils import flt
set = webnotes.conn.set
sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists
from webnotes.utils.nestedset import DocTypeNestedSet
# -----------------------------------------------------------------------------------------
class DocType(DocTypeNestedSet):
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
self.nsm_parent_field = 'parent_territory'
class DocType:
def __init__(self, doc, doclist=[]):
self.doc = doc
self.doclist = doclist
self.nsm_parent_field = 'parent_territory'
def check_state(self):
return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
# update Node Set Model
def update_nsm_model(self):
import webnotes
import webnotes.utils.nestedset
webnotes.utils.nestedset.update_nsm(self)
# ON UPDATE
#--------------------------------------
def on_update(self):
# update nsm
self.update_nsm_model()
def validate(self):
if self.doc.lft and self.doc.rgt:
res = sql("select name from `tabTerritory` where is_group = 'Yes' and docstatus!= 2 and name ='%s' and name !='%s'"%(self.doc.parent_territory,self.doc.territory_name))
if not res:
msgprint("Please enter proper parent territory.")
raise Exception
r = sql("select name from `tabTerritory` where name = '%s' and docstatus = 2"%(self.doc.territory_name))
if r:
msgprint("%s record is trashed. To untrash please go to Setup & click on Trash."%(self.doc.territory_name))
raise Exception
for d in getlist(self.doclist, 'target_details'):
if not flt(d.target_qty) and not flt(d.target_amount):
msgprint("Either target qty or target amount is mandatory.")
raise Exception
def on_trash(self):
cust = sql("select name from `tabCustomer` where ifnull(territory, '') = %s", self.doc.name)
cust = [d[0] for d in cust]
if cust:
msgprint("""Territory: %s can not be trashed/deleted because it is used in customer: %s.
To trash/delete this, remove/change territory in customer master""" % (self.doc.name, cust or ''), raise_exception=1)
if sql("select name from `tabTerritory` where parent_territory = %s and docstatus != 2", self.doc.name):
msgprint("Child territory exists for this territory. You can not trash/cancel/delete this territory.", raise_exception=1)
# rebuild tree
set(self.doc,'old_parent', '')
self.update_nsm_model()
def validate(self):
for d in getlist(self.doclist, 'target_details'):
if not flt(d.target_qty) and not flt(d.target_amount):
msgprint("Either target qty or target amount is mandatory.")
raise Exception

View File

@ -3,9 +3,9 @@
# These values are common in all dictionaries
{
'creation': '2012-04-13 11:56:32',
'creation': '2012-07-03 13:30:55',
'docstatus': 0,
'modified': '2012-05-31 11:39:33',
'modified': '2012-07-12 10:01:47',
'modified_by': u'Administrator',
'owner': u'Administrator'
},
@ -17,12 +17,14 @@
'autoname': u'field:territory_name',
'colour': u'White:FFF',
'default_print_format': u'Standard',
'description': u'You can create **Territories** If your organization operates in multiple regions (could be countries, states or cities). Once you group **Customers** by **Territories**, you can set annual targets for each **Item Group** and get reports that will show your actual performance in the territory v/s what you had planned.',
'doctype': 'DocType',
'document_type': u'Master',
'in_create': 1,
'module': u'Setup',
'name': '__common__',
'name_case': u'Title Case',
'read_only': 1,
'search_fields': u'name,parent_territory,territory_manager',
'section_style': u'Simple',
'server_code_error': u' ',
@ -141,20 +143,6 @@
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'territory_manager',
'fieldtype': u'Link',
'in_filter': 1,
'label': u'Territory Manager',
'oldfieldname': u'territory_manager',
'oldfieldtype': u'Link',
'options': u'Sales Person',
'permlevel': 0,
'search_index': 1
},
# DocField
{
'doctype': u'DocField',
@ -169,17 +157,6 @@
'trigger': u'Client'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'territoryhelp',
'fieldtype': u'HTML',
'label': u'TerritoryHelp',
'oldfieldtype': u'HTML',
'options': u'<a href="#!Sales Browser/Territory">To manage Territories, click here</a>',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
@ -195,6 +172,30 @@
'reqd': 1
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'cb0',
'fieldtype': u'Column Break',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'For reference',
'doctype': u'DocField',
'fieldname': u'territory_manager',
'fieldtype': u'Link',
'in_filter': 1,
'label': u'Territory Manager',
'oldfieldname': u'territory_manager',
'oldfieldtype': u'Link',
'options': u'Sales Person',
'permlevel': 0,
'search_index': 1
},
# DocField
{
'doctype': u'DocField',
@ -247,22 +248,12 @@
# DocField
{
'doctype': u'DocField',
'fieldname': u'distribution_id',
'fieldtype': u'Link',
'label': u'Distribution Id',
'oldfieldname': u'distribution_id',
'oldfieldtype': u'Link',
'options': u'Budget Distribution',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Set Item Group-wise budgets on this Territory. You can also include seasonality by setting the Distribution.',
'doctype': u'DocField',
'fieldname': u'target_details_section_break',
'fieldtype': u'Section Break',
'label': u'Target Details',
'label': u'Territory Targets',
'oldfieldtype': u'Section Break',
'permlevel': 0
},
@ -272,10 +263,24 @@
'doctype': u'DocField',
'fieldname': u'target_details',
'fieldtype': u'Table',
'label': u'Target Details1',
'label': u'Target Details',
'oldfieldname': u'target_details',
'oldfieldtype': u'Table',
'options': u'Target Detail',
'permlevel': 0
},
# DocField
{
'colour': u'White:FFF',
'description': u'Select Budget Distribution to unevenly distribute targets across months.',
'doctype': u'DocField',
'fieldname': u'distribution_id',
'fieldtype': u'Link',
'label': u'Target Distribution',
'oldfieldname': u'distribution_id',
'oldfieldtype': u'Link',
'options': u'Budget Distribution',
'permlevel': 0
}
]

View File

@ -363,7 +363,7 @@ $(page).bind('hide',onhide);page.label=label;wn.pages[label]=page;return page;},
var me=this;if(label.tagName){var page=label;}else{var page=wn.pages[label];}
if(!page){console.log('Page not found '+label);return;}
if(this.page){$(this.page).toggle(false);$(this.page).trigger('hide');}
this.page=page;$(this.page).fadeIn();$(this.page).trigger('show');this.page._route=window.location.hash;document.title=this.page.label;scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
this.page=page;$(this.page).fadeIn();this.page._route=window.location.hash;document.title=this.page.label;$(this.page).trigger('show');scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
onclick="wn.set_route(\'%(module_small)s-home\')">\
<i class="icon-home icon-white"></i> %(module)s Home\
</span>',{module:module,module_small:module.toLowerCase()}));}
@ -875,6 +875,7 @@ wn.widgets.FieldGroup=function(){this.first_button=false;this.make_fields=functi
$y(this.body,{padding:'11px'});this.fields_dict={};for(var i=0;i<fl.length;i++){var df=fl[i];var div=$a(body,'div','',{margin:'6px 0px'})
f=make_field(df,null,div,null);f.not_in_form=1;this.fields_dict[df.fieldname]=f
f.refresh();if(df.fieldtype=='Button'&&!this.first_button){$(f.input).addClass('btn-info');this.first_button=true;}}}
this.catch_enter_as_submit=function(){var me=this;$(this.body).find(':input[type="text"], :input[type="password"]').keypress(function(e){if(e.which==13){$(me.body).find('.btn-info:first').click();}})}
this.get_values=function(){var ret={};var errors=[];for(var key in this.fields_dict){var f=this.fields_dict[key];var v=f.get_value?f.get_value():null;if(f.df.reqd&&!v)
errors.push(f.df.label+' is mandatory');if(v)ret[f.df.fieldname]=v;}
if(errors.length){msgprint('<b>Please check the following Errors</b>\n'+errors.join('\n'));return null;}
@ -885,13 +886,12 @@ this.clear=function(){for(key in this.fields_dict){var f=this.fields_dict[key];i
wn.widgets.Dialog=function(opts){this.display=false;this.make=function(opts){if(opts){this.opts=opts;$.extend(this,opts);}
if(!this.opts.width)this.opts.width=480;if(!$('#dialog-container').length){$('<div id="dialog-container">').appendTo('body');}
this.wrapper=$('<div class="dialog_wrapper">').appendTo('#dialog-container').get(0);if(this.opts.width)
this.wrapper.style.width=this.opts.width+'px';this.make_head();this.body=$a(this.wrapper,'div','dialog_body');if(this.opts.fields)
this.make_fields(this.body,this.opts.fields);}
this.wrapper.style.width=this.opts.width+'px';this.make_head();this.body=$a(this.wrapper,'div','dialog_body');if(this.opts.fields){this.make_fields(this.body,this.opts.fields);this.catch_enter_as_submit();}}
this.make_head=function(){var me=this;this.appframe=new wn.ui.AppFrame(this.wrapper);this.appframe.$titlebar.find('.close').unbind('click').click(function(){if(me.oncancel)me.oncancel();me.hide();});this.set_title(this.opts.title);}
this.set_title=function(t){this.appframe.$titlebar.find('.appframe-title').html(t||'');}
this.set_postion=function(){this.wrapper.style.left=(($(window).width()-cint(this.wrapper.style.width))/2)+'px';this.wrapper.style.top=($(window).scrollTop()+60)+'px';top_index++;$y(this.wrapper,{zIndex:top_index});}
this.show=function(){if(this.display)return;this.set_postion()
$ds(this.wrapper);freeze();this.display=true;cur_dialog=this;if(this.onshow)this.onshow();}
$ds(this.wrapper);freeze();this.display=true;cur_dialog=this;if(this.onshow)this.onshow();$(this.wrapper).find(':input:first').focus();}
this.hide=function(){if(this.onhide)this.onhide();unfreeze();$dh(this.wrapper);this.display=false;cur_dialog=null;}
this.no_cancel=function(){this.appframe.$titlebar.find('.close').toggle(false);}
if(opts)this.make(opts);}

View File

@ -250,7 +250,7 @@ $(page).bind('hide',onhide);page.label=label;wn.pages[label]=page;return page;},
var me=this;if(label.tagName){var page=label;}else{var page=wn.pages[label];}
if(!page){console.log('Page not found '+label);return;}
if(this.page){$(this.page).toggle(false);$(this.page).trigger('hide');}
this.page=page;$(this.page).fadeIn();$(this.page).trigger('show');this.page._route=window.location.hash;document.title=this.page.label;scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
this.page=page;$(this.page).fadeIn();this.page._route=window.location.hash;document.title=this.page.label;$(this.page).trigger('show');scroll(0,0);return this.page;}});wn.views.add_module_btn=function(parent,module){$(parent).append(repl('<span class="label" style="margin-right: 8px; cursor: pointer;"\
onclick="wn.set_route(\'%(module_small)s-home\')">\
<i class="icon-home icon-white"></i> %(module)s Home\
</span>',{module:module,module_small:module.toLowerCase()}));}
@ -533,6 +533,7 @@ wn.widgets.FieldGroup=function(){this.first_button=false;this.make_fields=functi
$y(this.body,{padding:'11px'});this.fields_dict={};for(var i=0;i<fl.length;i++){var df=fl[i];var div=$a(body,'div','',{margin:'6px 0px'})
f=make_field(df,null,div,null);f.not_in_form=1;this.fields_dict[df.fieldname]=f
f.refresh();if(df.fieldtype=='Button'&&!this.first_button){$(f.input).addClass('btn-info');this.first_button=true;}}}
this.catch_enter_as_submit=function(){var me=this;$(this.body).find(':input[type="text"], :input[type="password"]').keypress(function(e){if(e.which==13){$(me.body).find('.btn-info:first').click();}})}
this.get_values=function(){var ret={};var errors=[];for(var key in this.fields_dict){var f=this.fields_dict[key];var v=f.get_value?f.get_value():null;if(f.df.reqd&&!v)
errors.push(f.df.label+' is mandatory');if(v)ret[f.df.fieldname]=v;}
if(errors.length){msgprint('<b>Please check the following Errors</b>\n'+errors.join('\n'));return null;}
@ -543,13 +544,12 @@ this.clear=function(){for(key in this.fields_dict){var f=this.fields_dict[key];i
wn.widgets.Dialog=function(opts){this.display=false;this.make=function(opts){if(opts){this.opts=opts;$.extend(this,opts);}
if(!this.opts.width)this.opts.width=480;if(!$('#dialog-container').length){$('<div id="dialog-container">').appendTo('body');}
this.wrapper=$('<div class="dialog_wrapper">').appendTo('#dialog-container').get(0);if(this.opts.width)
this.wrapper.style.width=this.opts.width+'px';this.make_head();this.body=$a(this.wrapper,'div','dialog_body');if(this.opts.fields)
this.make_fields(this.body,this.opts.fields);}
this.wrapper.style.width=this.opts.width+'px';this.make_head();this.body=$a(this.wrapper,'div','dialog_body');if(this.opts.fields){this.make_fields(this.body,this.opts.fields);this.catch_enter_as_submit();}}
this.make_head=function(){var me=this;this.appframe=new wn.ui.AppFrame(this.wrapper);this.appframe.$titlebar.find('.close').unbind('click').click(function(){if(me.oncancel)me.oncancel();me.hide();});this.set_title(this.opts.title);}
this.set_title=function(t){this.appframe.$titlebar.find('.appframe-title').html(t||'');}
this.set_postion=function(){this.wrapper.style.left=(($(window).width()-cint(this.wrapper.style.width))/2)+'px';this.wrapper.style.top=($(window).scrollTop()+60)+'px';top_index++;$y(this.wrapper,{zIndex:top_index});}
this.show=function(){if(this.display)return;this.set_postion()
$ds(this.wrapper);freeze();this.display=true;cur_dialog=this;if(this.onshow)this.onshow();}
$ds(this.wrapper);freeze();this.display=true;cur_dialog=this;if(this.onshow)this.onshow();$(this.wrapper).find(':input:first').focus();}
this.hide=function(){if(this.onhide)this.onhide();unfreeze();$dh(this.wrapper);this.display=false;cur_dialog=null;}
this.no_cancel=function(){this.appframe.$titlebar.find('.close').toggle(false);}
if(opts)this.make(opts);}