Merge branch 'wsgi' of https://github.com/webnotes/erpnext into i18n

Conflicts:
	accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js
	accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js
	public/js/complete_setup.js
	selling/doctype/opportunity/opportunity.js
	selling/doctype/quotation/quotation.js
This commit is contained in:
Bárbara Perretti
2013-10-16 15:09:18 -03:00
250 changed files with 5061 additions and 2506 deletions

View File

@@ -9,7 +9,6 @@ from webnotes.model.bean import getlist
from webnotes import session, msgprint
from setup.utils import get_company_currency
sql = webnotes.conn.sql
from utilities.transaction_base import TransactionBase
@@ -28,10 +27,10 @@ class DocType(TransactionBase):
amt_list.append(flt(x[0]))
max_amount = max(amt_list)
app_dtl = sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and company = %s %s" % ('%s', '%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on, company))
app_dtl = webnotes.conn.sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and company = %s %s" % ('%s', '%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on, company))
if not app_dtl:
app_dtl = sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and ifnull(company,'') = '' %s" % ('%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on))
app_dtl = webnotes.conn.sql("select approving_user, approving_role from `tabAuthorization Rule` where transaction = %s and (value = %s or value > %s) and docstatus != 2 and based_on = %s and ifnull(company,'') = '' %s" % ('%s', '%s', '%s', '%s', condition), (doctype_name, flt(max_amount), total, based_on))
for d in app_dtl:
if(d[0]): appr_users.append(d[0])
if(d[1]): appr_roles.append(d[1])
@@ -58,18 +57,18 @@ class DocType(TransactionBase):
add_cond1,add_cond2 = '',''
if based_on == 'Itemwise Discount':
add_cond1 += " and master_name = '"+cstr(item)+"'"
itemwise_exists = sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and company = %s and docstatus != 2 %s %s" % ('%s', '%s', '%s', '%s', cond, add_cond1), (doctype_name, total, based_on, company))
itemwise_exists = webnotes.conn.sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and company = %s and docstatus != 2 %s %s" % ('%s', '%s', '%s', '%s', cond, add_cond1), (doctype_name, total, based_on, company))
if not itemwise_exists:
itemwise_exists = sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and ifnull(company,'') = '' and docstatus != 2 %s %s" % ('%s', '%s', '%s', cond, add_cond1), (doctype_name, total, based_on))
itemwise_exists = webnotes.conn.sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and ifnull(company,'') = '' and docstatus != 2 %s %s" % ('%s', '%s', '%s', cond, add_cond1), (doctype_name, total, based_on))
if itemwise_exists:
self.get_appr_user_role(itemwise_exists, doctype_name, total, based_on, cond+add_cond1, item,company)
chk = 0
if chk == 1:
if based_on == 'Itemwise Discount': add_cond2 += " and ifnull(master_name,'') = ''"
appr = sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and company = %s and docstatus != 2 %s %s" % ('%s', '%s', '%s', '%s', cond, add_cond2), (doctype_name, total, based_on, company))
appr = webnotes.conn.sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and company = %s and docstatus != 2 %s %s" % ('%s', '%s', '%s', '%s', cond, add_cond2), (doctype_name, total, based_on, company))
if not appr:
appr = sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and ifnull(company,'') = '' and docstatus != 2 %s %s"% ('%s', '%s', '%s', cond, add_cond2), (doctype_name, total, based_on))
appr = webnotes.conn.sql("select value from `tabAuthorization Rule` where transaction = %s and value <= %s and based_on = %s and ifnull(company,'') = '' and docstatus != 2 %s %s"% ('%s', '%s', '%s', cond, add_cond2), (doctype_name, total, based_on))
self.get_appr_user_role(appr, doctype_name, total, based_on, cond+add_cond2, item, company)
@@ -112,7 +111,7 @@ class DocType(TransactionBase):
# ================
# Check for authorization set for individual user
based_on = [x[0] for x in sql("select distinct based_on from `tabAuthorization Rule` where transaction = %s and system_user = %s and (company = %s or ifnull(company,'')='') and docstatus != 2", (doctype_name, session['user'], company))]
based_on = [x[0] for x in webnotes.conn.sql("select distinct based_on from `tabAuthorization Rule` where transaction = %s and system_user = %s and (company = %s or ifnull(company,'')='') and docstatus != 2", (doctype_name, session['user'], company))]
for d in based_on:
self.bifurcate_based_on_type(doctype_name, total, av_dis, d, doc_obj, 1, company)
@@ -124,7 +123,7 @@ class DocType(TransactionBase):
# Specific Role
# ===============
# Check for authorization set on particular roles
based_on = [x[0] for x in sql("""select based_on
based_on = [x[0] for x in webnotes.conn.sql("""select based_on
from `tabAuthorization Rule`
where transaction = %s and system_role IN (%s) and based_on IN (%s)
and (company = %s or ifnull(company,'')='')
@@ -148,9 +147,9 @@ class DocType(TransactionBase):
# payroll related check
def get_value_based_rule(self,doctype_name,employee,total_claimed_amount,company):
val_lst =[]
val = sql("select value from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)< %s and company = %s and docstatus!=2",(doctype_name,employee,employee,total_claimed_amount,company))
val = webnotes.conn.sql("select value from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)< %s and company = %s and docstatus!=2",(doctype_name,employee,employee,total_claimed_amount,company))
if not val:
val = sql("select value from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)< %s and ifnull(company,'') = '' and docstatus!=2",(doctype_name, employee, employee, total_claimed_amount))
val = webnotes.conn.sql("select value from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)< %s and ifnull(company,'') = '' and docstatus!=2",(doctype_name, employee, employee, total_claimed_amount))
if val:
val_lst = [y[0] for y in val]
@@ -158,9 +157,9 @@ class DocType(TransactionBase):
val_lst.append(0)
max_val = max(val_lst)
rule = sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and company = %s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)= %s and docstatus!=2",(doctype_name,company,employee,employee,flt(max_val)), as_dict=1)
rule = webnotes.conn.sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and company = %s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)= %s and docstatus!=2",(doctype_name,company,employee,employee,flt(max_val)), as_dict=1)
if not rule:
rule = sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and ifnull(company,'') = '' and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)= %s and docstatus!=2",(doctype_name,employee,employee,flt(max_val)), as_dict=1)
rule = webnotes.conn.sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and ifnull(company,'') = '' and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(value,0)= %s and docstatus!=2",(doctype_name,employee,employee,flt(max_val)), as_dict=1)
return rule
@@ -175,9 +174,9 @@ class DocType(TransactionBase):
if doctype_name == 'Expense Claim':
rule = self.get_value_based_rule(doctype_name,doc_obj.doc.employee,doc_obj.doc.total_claimed_amount, doc_obj.doc.company)
elif doctype_name == 'Appraisal':
rule = sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and company = %s and docstatus!=2",(doctype_name,doc_obj.doc.employee, doc_obj.doc.employee, doc_obj.doc.company),as_dict=1)
rule = webnotes.conn.sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and company = %s and docstatus!=2",(doctype_name,doc_obj.doc.employee, doc_obj.doc.employee, doc_obj.doc.company),as_dict=1)
if not rule:
rule = sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(company,'') = '' and docstatus!=2",(doctype_name,doc_obj.doc.employee, doc_obj.doc.employee),as_dict=1)
rule = webnotes.conn.sql("select name, to_emp, to_designation, approving_role, approving_user from `tabAuthorization Rule` where transaction=%s and (to_emp=%s or to_designation IN (select designation from `tabEmployee` where name=%s)) and ifnull(company,'') = '' and docstatus!=2",(doctype_name,doc_obj.doc.employee, doc_obj.doc.employee),as_dict=1)
if rule:
for m in rule:
@@ -185,7 +184,7 @@ class DocType(TransactionBase):
if m['approving_user']:
app_specific_user.append(m['approving_user'])
elif m['approving_role']:
user_lst = [z[0] for z in sql("select distinct t1.name from `tabProfile` t1, `tabUserRole` t2 where t2.role=%s and t2.parent=t1.name and t1.name !='Administrator' and t1.name != 'Guest' and t1.docstatus !=2",m['approving_role'])]
user_lst = [z[0] for z in webnotes.conn.sql("select distinct t1.name from `tabProfile` t1, `tabUserRole` t2 where t2.role=%s and t2.parent=t1.name and t1.name !='Administrator' and t1.name != 'Guest' and t1.docstatus !=2",m['approving_role'])]
for x in user_lst:
if not x in app_user:
app_user.append(x)

View File

@@ -9,7 +9,6 @@ from webnotes.model import db_exists
from webnotes.model.bean import copy_doclist
from webnotes import msgprint
sql = webnotes.conn.sql
@@ -19,7 +18,7 @@ class DocType:
def check_duplicate_entry(self):
exists = sql("""select name, docstatus from `tabAuthorization Rule`
exists = webnotes.conn.sql("""select name, docstatus from `tabAuthorization Rule`
where transaction = %s and based_on = %s and system_user = %s
and system_role = %s and approving_user = %s and approving_role = %s
and to_emp =%s and to_designation=%s and name != %s""",
@@ -39,12 +38,12 @@ class DocType:
def validate_master_name(self):
if self.doc.based_on == 'Customerwise Discount' and \
not sql("select name from tabCustomer where name = '%s' and docstatus != 2" % \
not webnotes.conn.sql("select name from tabCustomer where name = '%s' and docstatus != 2" % \
(self.doc.master_name)):
msgprint("Please select valid Customer Name for Customerwise Discount",
raise_exception=1)
elif self.doc.based_on == 'Itemwise Discount' and \
not sql("select name from tabItem where name = '%s' and docstatus != 2" % \
not webnotes.conn.sql("select name from tabItem where name = '%s' and docstatus != 2" % \
(self.doc.master_name)):
msgprint("Please select valid Item Name for Itemwise Discount", raise_exception=1)
elif (self.doc.based_on == 'Grand Total' or \
@@ -65,7 +64,7 @@ class DocType:
Applicable To (Role).", raise_exception=1)
elif self.doc.system_user and self.doc.approving_role and \
has_common([self.doc.approving_role], [x[0] for x in \
sql("select role from `tabUserRole` where parent = '%s'" % \
webnotes.conn.sql("select role from `tabUserRole` where parent = '%s'" % \
(self.doc.system_user))]):
msgprint("System User : %s is assigned role : %s. So rule does not make sense" %
(self.doc.system_user,self.doc.approving_role), raise_exception=1)

View File

@@ -61,8 +61,8 @@ def dropbox_callback(oauth_token=None, not_approved=False):
allowed = 0
message = "Dropbox Access not approved."
webnotes.message_title = "Dropbox Approval"
webnotes.message = "<h3>%s</h3><p>Please close this window.</p>" % message
webnotes.local.message_title = "Dropbox Approval"
webnotes.local.message = "<h3>%s</h3><p>Please close this window.</p>" % message
webnotes.conn.commit()
webnotes.response['type'] = 'page'
@@ -96,6 +96,7 @@ def backup_to_dropbox():
error_log = []
path = os.path.join(get_base_path(), "public", "files")
for filename in os.listdir(path):
filename = cstr(filename)
if filename in ignore_list:
continue

View File

@@ -85,6 +85,7 @@ def backup_to_gdrive():
webnotes.conn.close()
path = os.path.join(get_base_path(), "public", "files")
for filename in os.listdir(path):
filename = cstr(filename)
found = False
filepath = os.path.join(path, filename)
ext = filename.split('.')[-1]
@@ -113,9 +114,9 @@ def backup_to_gdrive():
def get_gdrive_flow():
from oauth2client.client import OAuth2WebServerFlow
import conf
from webnotes import conf
if not hasattr(conf, "gdrive_client_id"):
if not "gdrive_client_id" in conf:
webnotes.msgprint(_("Please set Google Drive access keys in") + " conf.py",
raise_exception=True)
@@ -169,4 +170,4 @@ def create_folder(name, service, folder_id):
return database['id']
if __name__=="__main__":
backup_to_gdrive()
backup_to_gdrive()

View File

@@ -9,6 +9,7 @@ from __future__ import unicode_literals
import os, json
from xml.etree import ElementTree as ET
from webnotes.utils.datautils import read_csv_content
from webnotes.utils import cstr
path = "/Users/rmehta/Downloads/openerp/openerp/addons"
chart_roots = []
@@ -108,6 +109,7 @@ def find_charts():
basename = os.path.basename(basepath)
if basename.startswith("l10n"):
for fname in files:
fname = cstr(fname)
filepath = os.path.join(basepath, fname)
if fname.endswith(".xml"):
tree = ET.parse(filepath)

View File

@@ -10,7 +10,6 @@ from webnotes.model.doc import Document
from webnotes.model.code import get_obj
import webnotes.defaults
sql = webnotes.conn.sql
class DocType:
def __init__(self,d,dl):

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-04-10 08:35:39",
"docstatus": 0,
"modified": "2013-08-28 19:15:04",
"modified": "2013-10-08 15:18:34",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -80,7 +80,7 @@
"fieldtype": "Select",
"label": "Domain",
"options": "Distribution\nManufacturing\nRetail\nServices",
"reqd": 1
"reqd": 0
},
{
"doctype": "DocField",

View File

@@ -5,7 +5,6 @@ from __future__ import unicode_literals
import webnotes
from webnotes import msgprint
sql = webnotes.conn.sql
from webnotes.utils.nestedset import DocTypeNestedSet
class DocType(DocTypeNestedSet):
@@ -15,7 +14,7 @@ class DocType(DocTypeNestedSet):
self.nsm_parent_field = 'parent_customer_group';
def validate(self):
if sql("select name from `tabCustomer Group` where name = %s and docstatus = 2",
if webnotes.conn.sql("select name from `tabCustomer Group` where name = %s and docstatus = 2",
(self.doc.customer_group_name)):
msgprint("""Another %s record is trashed.
To untrash please go to Setup -> Recycle Bin.""" %
@@ -33,7 +32,7 @@ class DocType(DocTypeNestedSet):
self.doc.name, raise_exception=1)
def on_trash(self):
cust = sql("select name from `tabCustomer` where ifnull(customer_group, '') = %s",
cust = webnotes.conn.sql("select name from `tabCustomer` where ifnull(customer_group, '') = %s",
self.doc.name)
cust = [d[0] for d in cust]
if cust:
@@ -42,7 +41,7 @@ class DocType(DocTypeNestedSet):
To trash/delete this, remove/change customer group in customer master""" %
(self.doc.name, cust or ''), raise_exception=1)
if sql("select name from `tabCustomer Group` where parent_customer_group = %s \
if webnotes.conn.sql("select name from `tabCustomer Group` where parent_customer_group = %s \
and docstatus != 2", self.doc.name):
msgprint("Child customer group exists for this customer group. \
You can not trash/cancel/delete this customer group.", raise_exception=1)

View File

@@ -457,8 +457,8 @@ def send():
from webnotes.utils import getdate
now_date = now_datetime().date()
import conf
if hasattr(conf, "expires_on") and now_date > getdate(conf.expires_on):
from webnotes import conf
if "expires_on" in conf and now_date > getdate(conf.expires_on):
# do not send email digests to expired accounts
return

View File

@@ -3,7 +3,6 @@
from __future__ import unicode_literals
import webnotes
sql = webnotes.conn.sql
from webnotes.utils import cint

View File

@@ -7,6 +7,12 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.add_custom_button(wn._("Item Group Tree"), function() {
wn.set_route("Sales Browser", "Item Group");
})
if(!doc.__islocal && doc.show_in_website) {
cur_frm.add_custom_button("View In Website", function() {
window.open(doc.page_name);
}, "icon-globe");
}
}
cur_frm.cscript.set_root_readonly = function(doc) {

View File

@@ -8,7 +8,6 @@ from webnotes.utils import cstr
from webnotes import msgprint
import webnotes.model.doctype
sql = webnotes.conn.sql
class DocType:
def __init__(self, d, dl):
@@ -23,7 +22,7 @@ class DocType:
where fieldname='naming_series'""")
)))),
"prefixes": "\n".join([''] + [i[0] for i in
sql("""select name from tabSeries""")])
webnotes.conn.sql("""select name from tabSeries""")])
}
def scrub_options_list(self, ol):
@@ -126,12 +125,12 @@ class DocType:
def insert_series(self, series):
"""insert series if missing"""
if not webnotes.conn.exists('Series', series):
sql("insert into tabSeries (name, current) values (%s,0)", (series))
webnotes.conn.sql("insert into tabSeries (name, current) values (%s,0)", (series))
def update_series_start(self):
if self.doc.prefix:
self.insert_series(self.doc.prefix)
sql("update `tabSeries` set current = '%s' where name = '%s'" % (self.doc.current_value,self.doc.prefix))
webnotes.conn.sql("update `tabSeries` set current = '%s' where name = '%s'" % (self.doc.current_value,self.doc.prefix))
msgprint("Series Updated Successfully")
else:
msgprint("Please select prefix first")

View File

@@ -6,7 +6,6 @@ import webnotes
from webnotes import msgprint
sql = webnotes.conn.sql
class DocType:
def __init__(self,d,dl):
@@ -14,7 +13,7 @@ class DocType:
def get_message(self, arg):
fn = arg.lower().replace(' ', '_') + '_message'
v = sql("select value from tabSingles where field=%s and doctype=%s", (fn, 'Notification Control'))
v = webnotes.conn.sql("select value from tabSingles where field=%s and doctype=%s", (fn, 'Notification Control'))
return v and v[0][0] or ''
def set_message(self, arg = ''):

View File

@@ -0,0 +1,7 @@
.table-grid tbody tr {
cursor: pointer;
}
.table-grid thead tr {
height: 50px;
}

View File

@@ -5,4 +5,253 @@ $.extend(cur_frm.cscript, {
onload: function() {
erpnext.add_for_territory();
},
});
cur_frm.cscript.refresh = function(doc, cdt, cdn) {
cur_frm.cscript.show_item_prices();
}
cur_frm.cscript.show_item_prices = function() {
var item_price = wn.model.get("Item Price", {parent: cur_frm.doc.name});
$(cur_frm.fields_dict.item_prices_html.wrapper).empty();
new wn.ui.form.TableGrid({
parent: cur_frm.fields_dict.item_prices_html.wrapper,
frm: cur_frm,
table_field: wn.meta.get_docfield("Price List", "item_prices", cur_frm.doc.name)
});
}
wn.ui.form.TableGrid = Class.extend({
init: function(opts) {
$.extend(this, opts);
this.fields = wn.meta.get_docfields("Item Price", cur_frm.doc.name);
this.make_table();
},
make_table: function() {
var me = this;
// Creating table & assigning attributes
var grid_table = document.createElement("table");
grid_table.className = "table table-hover table-bordered table-grid";
// Appending header & rows to table
grid_table.appendChild(this.make_table_headers());
grid_table.appendChild(this.make_table_rows());
// Creating button to add new row
var btn_div = document.createElement("div");
var new_row_btn = document.createElement("button");
new_row_btn.className = "btn btn-success table-new-row";
new_row_btn.title = "Add new row";
var btn_icon = document.createElement("i");
btn_icon.className = "icon-plus";
new_row_btn.appendChild(btn_icon);
new_row_btn.innerHTML += " Add new row";
btn_div.appendChild(new_row_btn);
// Appending table & button to parent
var $grid_table = $(grid_table).appendTo($(this.parent));
var $btn_div = $(btn_div).appendTo($(this.parent));
$btn_div.on("click", ".table-new-row", function() {
me.make_dialog();
return false;
});
$grid_table.on("click", ".table-row", function() {
me.make_dialog(this);
return false;
});
},
make_table_headers: function() {
var me = this;
var header = document.createElement("thead");
// Creating header row
var row = document.createElement("tr");
row.className = "active";
// Creating head first cell
var th = document.createElement("th");
th.width = "8%";
th.className = "text-center";
th.innerHTML = "#";
row.appendChild(th);
// Make other headers with label as heading
for(var i=0, l=this.fields.length; i<l; i++) {
var df = this.fields[i];
if(!!!df.hidden && df.in_list_view === 1) {
var th = document.createElement("th");
// If currency then move header to right
if(["Int", "Currency", "Float"].indexOf(df.fieldtype) !== -1) th.className = "text-right";
th.innerHTML = wn._(df.label);
row.appendChild(th);
}
}
header.appendChild(row);
return header;
},
make_table_rows: function() {
var me = this;
// Creating table body
var table_body = document.createElement("tbody");
var item_prices = wn.model.get_children(this.table_field.options, this.frm.doc.name,
this.table_field.fieldname, this.frm.doctype);
for(var i=0, l=item_prices.length; i<l; i++) {
var d = item_prices[i];
// Creating table row
var tr = this.add_new_row(d);
// append row to table body
table_body.appendChild(tr);
}
this.table_body = table_body;
return table_body;
},
make_dialog: function(row) {
var me = this;
this.dialog = new wn.ui.Dialog({
title: this.table_field.options,
fields: this.fields
});
if (row)
this.dialog.set_values(this.make_dialog_values(row));
$a(this.dialog.body, 'div', '', '', this.make_dialog_buttons(row));
this.dialog.show();
this.dialog.$wrapper.find('button.update').on('click', function() {
me.update_row(row);
});
this.dialog.$wrapper.find('button.delete').on('click', function() {
me.delete_row(row);
});
return row;
},
make_dialog_values: function(row) {
var me = this;
var dialog_values = {};
$.each(this.fields, function(i, item) {
dialog_values[item.fieldname] = $(row).find('td[data-fieldname="'+ item.fieldname +'"]').attr('data-fieldvalue');
});
return dialog_values;
},
make_dialog_buttons: function(row) {
var me = this;
var buttons = '<button class="btn btn-primary update">Update</button>';
// if user can delete then only add the delete button in dialog
if (wn.model.can_delete(me.frm.doc.doctype) && row)
buttons += ' <button class="btn btn-default delete">Delete</button>';
return buttons;
},
update_row: function(row) {
var me = this;
if (!row) {
var d = wn.model.add_child(this.frm.doc, this.table_field.options,
this.table_field.fieldname);
refresh_field(this.table_field.fieldname);
this.update_item_price(d.name);
var tr = this.add_new_row(d);
this.table_body.appendChild(tr);
}
else {
this.update_item_price(null, row);
}
this.dialog.hide();
},
update_item_price: function(docname, row) {
var me = this;
if(!docname && row) docname = $(row).attr("data-docname");
$.each(me.fields, function(i, df) {
var val = me.dialog.get_values()[df.fieldname];
if(["Currency", "Float"].indexOf(df.fieldtype)!==-1) {
val = flt(val);
} else if(["Int", "Check"].indexOf(df.fieldtype)!==-1) {
val = cint(val);
}
wn.model.set_value(me.table_field.options, docname,
df.fieldname, val);
if(row) {
var $td = $(row).find('td[data-fieldname="'+ df.fieldname +'"]');
$td.attr('data-fieldvalue', val);
// If field type is currency the update with format currency
$td.html(wn.format(val, df));
}
});
},
delete_row: function(row) {
var me = this;
var docname = $(row).find('td:last').attr('data-docname');
wn.model.clear_doc(me.table_field.options, docname);
$(row).remove();
// Re-assign idx
$.each($(this.parent).find("tbody tr"), function(idx, data) {
var $td = $(data).find('td:first');
$td.html(idx + 1);
});
this.dialog.hide();
},
add_new_row: function(d) {
var tr = document.createElement("tr");
tr.className = "table-row";
tr.setAttribute("data-docname", d.name);
// Creating table data & appending to row
var td = document.createElement("td");
td.className = "text-center";
td.innerHTML = d.idx;
tr.appendChild(td);
for(var f=0, lf=this.fields.length; f<lf; f++) {
var df = this.fields[f];
if(!!!df.hidden && df.in_list_view===1) {
var td = document.createElement("td");
td.setAttribute("data-fieldname", df.fieldname);
td.setAttribute("data-fieldvalue", d[df.fieldname]);
td.setAttribute("data-docname", d.name);
// If currency then move header to right
if(["Int", "Currency", "Float"].indexOf(df.fieldtype) !== -1) {
td.className = "text-right";
}
// format and set display
td.innerHTML = wn.format(d[df.fieldname], df);
// append column to tabel row
tr.appendChild(td);
}
}
return tr;
}
});

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-01-25 11:35:09",
"docstatus": 0,
"modified": "2013-09-06 15:03:38",
"modified": "2013-10-02 11:36:09",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -85,16 +85,23 @@
"reqd": 1
},
{
"description": "To change row values, click on the respective row",
"doctype": "DocField",
"fieldname": "item_prices_section",
"fieldtype": "Section Break",
"hidden": 0,
"label": "Item Prices"
},
{
"doctype": "DocField",
"fieldname": "item_prices_html",
"fieldtype": "HTML"
},
{
"doctype": "DocField",
"fieldname": "item_prices",
"fieldtype": "Table",
"hidden": 1,
"label": "Item Prices",
"options": "Item Price"
},

View File

@@ -7,7 +7,6 @@ import webnotes
from webnotes.model import db_exists
from webnotes.model.bean import copy_doclist
sql = webnotes.conn.sql

View File

@@ -5,13 +5,16 @@ from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint, cstr, filter_strip_join
sql = webnotes.conn.sql
class DocType:
def __init__(self, doc, doclist=None):
self.doc = doc
self.doclist = doclist
def validate(self):
if self.doc.partner_website and not self.doc.partner_website.startswith("http"):
self.doc.partner_website = "http://" + self.doc.partner_website
def on_update(self):
if cint(self.doc.show_in_website):
from webnotes.webutils import update_page_name
@@ -24,7 +27,7 @@ class DocType:
def get_contacts(self,nm):
if nm:
contact_details =webnotes.conn.convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where sales_partner = '%s'"%nm))
contact_details =webnotes.conn.convert_to_lists(webnotes.conn.sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where sales_partner = '%s'"%nm))
return contact_details
else:
return ''

View File

@@ -1 +0,0 @@
Account setup utility on first login.

View File

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

View File

@@ -1,255 +0,0 @@
# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
import webnotes
from webnotes.utils import cint, cstr, getdate, now, nowdate, get_defaults
from webnotes.model.doc import Document, addchild
from webnotes.model.code import get_obj
from webnotes import session, form, msgprint
class DocType:
def __init__(self, d, dl):
self.doc, self.doclist = d, dl
def setup_account(self, args):
import webnotes, json
if isinstance(args, basestring):
args = json.loads(args)
webnotes.conn.begin()
self.update_profile_name(args)
add_all_roles_to(webnotes.session.user)
self.create_fiscal_year_and_company(args)
self.set_defaults(args)
create_territories()
self.create_price_lists(args)
self.create_feed_and_todo()
self.create_email_digest()
webnotes.clear_cache()
msgprint("Company setup is complete. This page will be refreshed in a moment.")
webnotes.conn.commit()
return {
'sys_defaults': get_defaults(),
'user_fullname': (args.get('first_name') or '') + (args.get('last_name')
and (" " + args.get('last_name')) or '')
}
def update_profile_name(self, args):
args['name'] = webnotes.session.get('user')
# Update Profile
if not args.get('last_name') or args.get('last_name')=='None': args['last_name'] = None
webnotes.conn.sql("""\
UPDATE `tabProfile` SET first_name=%(first_name)s,
last_name=%(last_name)s
WHERE name=%(name)s AND docstatus<2""", args)
def create_fiscal_year_and_company(self, args):
curr_fiscal_year, fy_start_date, fy_abbr = self.get_fy_details(args.get('fy_start'), True)
webnotes.bean([{
"doctype":"Fiscal Year",
'year': curr_fiscal_year,
'year_start_date': fy_start_date
}]).insert()
curr_fiscal_year, fy_start_date, fy_abbr = self.get_fy_details(args.get('fy_start'))
webnotes.bean([{
"doctype":"Fiscal Year",
'year': curr_fiscal_year,
'year_start_date': fy_start_date,
}]).insert()
# Company
webnotes.bean([{
"doctype":"Company",
'domain': args.get("industry"),
'company_name':args.get('company_name'),
'abbr':args.get('company_abbr'),
'default_currency':args.get('currency'),
}]).insert()
self.curr_fiscal_year = curr_fiscal_year
def create_price_lists(self, args):
for pl_type in ["Selling", "Buying"]:
webnotes.bean([
{
"doctype": "Price List",
"price_list_name": "Standard " + pl_type,
"buying_or_selling": pl_type,
"currency": args["currency"]
},
{
"doctype": "For Territory",
"parentfield": "valid_for_territories",
"territory": "All Territories"
}
]).insert()
def set_defaults(self, args):
# enable default currency
webnotes.conn.set_value("Currency", args.get("currency"), "enabled", 1)
global_defaults = webnotes.bean("Global Defaults", "Global Defaults")
global_defaults.doc.fields.update({
'current_fiscal_year': self.curr_fiscal_year,
'default_currency': args.get('currency'),
'default_company':args.get('company_name'),
'date_format': webnotes.conn.get_value("Country", args.get("country"), "date_format"),
"float_precision": 4
})
global_defaults.save()
accounts_settings = webnotes.bean("Accounts Settings")
accounts_settings.doc.auto_accounting_for_stock = 1
accounts_settings.save()
stock_settings = webnotes.bean("Stock Settings")
stock_settings.doc.item_naming_by = "Item Code"
stock_settings.doc.valuation_method = "FIFO"
stock_settings.doc.stock_uom = "Nos"
stock_settings.doc.auto_indent = 1
stock_settings.save()
selling_settings = webnotes.bean("Selling Settings")
selling_settings.doc.cust_master_name = "Customer Name"
selling_settings.doc.so_required = "No"
selling_settings.doc.dn_required = "No"
selling_settings.save()
buying_settings = webnotes.bean("Buying Settings")
buying_settings.doc.supp_master_name = "Supplier Name"
buying_settings.doc.po_required = "No"
buying_settings.doc.pr_required = "No"
buying_settings.doc.maintain_same_rate = 1
buying_settings.save()
notification_control = webnotes.bean("Notification Control")
notification_control.doc.quotation = 1
notification_control.doc.sales_invoice = 1
notification_control.doc.purchase_order = 1
notification_control.save()
hr_settings = webnotes.bean("HR Settings")
hr_settings.doc.emp_created_by = "Naming Series"
hr_settings.save()
# control panel
cp = webnotes.doc("Control Panel", "Control Panel")
for k in ['country', 'timezone', 'company_name']:
cp.fields[k] = args[k]
cp.save()
def create_feed_and_todo(self):
"""update activty feed and create todo for creation of item, customer, vendor"""
import home
home.make_feed('Comment', 'ToDo', '', webnotes.session['user'],
'<i>"' + 'Setup Complete. Please check your <a href="#!todo">\
To Do List</a>' + '"</i>', '#6B24B3')
d = Document('ToDo')
d.description = '<a href="#Setup">Complete ERPNext Setup</a>'
d.priority = 'High'
d.date = nowdate()
d.save(1)
def create_email_digest(self):
"""
create a default weekly email digest
* Weekly Digest
* For all companies
* Recipients: System Managers
* Full content
* Enabled by default
"""
import webnotes
companies_list = webnotes.conn.sql("SELECT company_name FROM `tabCompany`", as_list=1)
from webnotes.profile import get_system_managers
system_managers = get_system_managers()
if not system_managers: return
from webnotes.model.doc import Document
for company in companies_list:
if company and company[0]:
edigest = webnotes.bean({
"doctype": "Email Digest",
"name": "Default Weekly Digest - " + company[0],
"company": company[0],
"frequency": "Weekly",
"recipient_list": "\n".join(system_managers)
})
if webnotes.conn.sql("""select name from `tabEmail Digest` where name=%s""", edigest.doc.name):
continue
for fieldname in edigest.meta.get_fieldnames({"fieldtype": "Check"}):
edigest.doc.fields[fieldname] = 1
edigest.insert()
# Get Fiscal year Details
# ------------------------
def get_fy_details(self, fy_start, last_year=False):
st = {'1st Jan':'01-01','1st Apr':'04-01','1st Jul':'07-01', '1st Oct': '10-01'}
if cint(getdate(nowdate()).month) < cint((st[fy_start].split('-'))[0]):
curr_year = getdate(nowdate()).year - 1
else:
curr_year = getdate(nowdate()).year
if last_year:
curr_year = curr_year - 1
stdt = cstr(curr_year)+'-'+cstr(st[fy_start])
if(fy_start == '1st Jan'):
fy = cstr(curr_year)
abbr = cstr(fy)[-2:]
else:
fy = cstr(curr_year) + '-' + cstr(curr_year+1)
abbr = cstr(curr_year)[-2:] + '-' + cstr(curr_year+1)[-2:]
return fy, stdt, abbr
def create_profile(self, user_email, user_fname, user_lname, pwd=None):
pr = Document('Profile')
pr.first_name = user_fname
pr.last_name = user_lname
pr.name = pr.email = user_email
pr.enabled = 1
pr.save(1)
if pwd:
webnotes.conn.sql("""insert into __Auth (user, `password`)
values (%s, password(%s))
on duplicate key update `password`=password(%s)""",
(user_email, pwd, pwd))
add_all_roles_to(pr.name)
def add_all_roles_to(name):
profile = webnotes.doc("Profile", name)
for role in webnotes.conn.sql("""select name from tabRole"""):
if role[0] not in ["Administrator", "Guest", "All", "Customer", "Supplier", "Partner"]:
d = profile.addchild("user_roles", "UserRole")
d.role = role[0]
d.insert()
def create_territories():
"""create two default territories, one for home country and one named Rest of the World"""
from setup.utils import get_root_of
country = webnotes.conn.get_value("Control Panel", None, "country")
root_territory = get_root_of("Territory")
for name in (country, "Rest Of The World"):
if name and not webnotes.conn.exists("Territory", name):
webnotes.bean({
"doctype": "Territory",
"territory_name": name.replace("'", ""),
"parent_territory": root_territory,
"is_group": "No"
}).insert()

View File

@@ -1,24 +0,0 @@
[
{
"creation": "2012-03-27 14:36:25",
"docstatus": 0,
"modified": "2012-03-27 14:36:25",
"modified_by": "Administrator",
"owner": "Administrator"
},
{
"doctype": "DocType",
"in_create": 1,
"issingle": 1,
"istable": 0,
"module": "Setup",
"name": "__common__",
"read_only": 1,
"section_style": "Simple",
"version": 73
},
{
"doctype": "DocType",
"name": "Setup Control"
}
]

View File

@@ -2,7 +2,7 @@
{
"creation": "2013-01-10 16:34:24",
"docstatus": 0,
"modified": "2013-07-25 16:18:17",
"modified": "2013-10-10 15:06:53",
"modified_by": "Administrator",
"owner": "Administrator"
},
@@ -38,22 +38,6 @@
"doctype": "DocType",
"name": "UOM"
},
{
"doctype": "DocField",
"fieldname": "trash_reason",
"fieldtype": "Small Text",
"label": "Trash Reason",
"oldfieldname": "trash_reason",
"oldfieldtype": "Small Text",
"read_only": 1
},
{
"doctype": "DocField",
"fieldname": "uom_details",
"fieldtype": "Section Break",
"label": "UOM Details",
"oldfieldtype": "Section Break"
},
{
"doctype": "DocField",
"fieldname": "uom_name",