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

This commit is contained in:
Anand Doshi 2012-11-30 12:48:53 +05:30
commit f991fe3997
34 changed files with 1395 additions and 1834 deletions

View File

@ -25,7 +25,6 @@ cur_frm.pformat.print_heading = 'Invoice';
wn.require('app/selling/doctype/sales_common/sales_common.js'); wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/setup/doctype/notification_control/notification_control.js');
// On Load // On Load
// ------- // -------
@ -498,11 +497,9 @@ cur_frm.cscript.view_ledger_entry = function(){
} }
cur_frm.cscript.on_submit = function(doc, cdt, cdn) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
var args = { if(cint(wn.boot.notification_settings.sales_invoice)) {
type: 'Sales Invoice', cur_frm.email_doc(wn.boot.notification_settings.sales_invoice);
doctype: 'Sales Invoice'
} }
cur_frm.cscript.notify(doc, args);
} }
cur_frm.cscript.convert_into_recurring_invoice = function(doc, dt, dn) { cur_frm.cscript.convert_into_recurring_invoice = function(doc, dt, dn) {

View File

@ -125,7 +125,6 @@ class DocType(TransactionBase):
def on_update_after_submit(self): def on_update_after_submit(self):
self.convert_into_recurring() self.convert_into_recurring()
def set_pos_fields(self): def set_pos_fields(self):
"""Set retail related fields from pos settings""" """Set retail related fields from pos settings"""
pos = webnotes.conn.sql("select * from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1) pos = webnotes.conn.sql("select * from `tabPOS Setting` where ifnull(user,'') = '%s' and company = '%s'" % (session['user'], self.doc.company), as_dict=1)

View File

@ -21,7 +21,6 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js'); wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/setup/doctype/notification_control/notification_control.js');
cur_frm.cscript.onload = function(doc, cdt, cdn) { cur_frm.cscript.onload = function(doc, cdt, cdn) {
// set missing values in parent doc // set missing values in parent doc
@ -220,9 +219,7 @@ cur_frm.pformat.indent_no = function(doc, cdt, cdn){
} }
cur_frm.cscript.on_submit = function(doc, cdt, cdn) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
var args = { if(cint(wn.boot.notification_settings.purchase_order)) {
type: 'Purchase Order', cur_frm.email_doc(wn.boot.notification_settings.purchase_order);
doctype: 'Purchase Order'
} }
cur_frm.cscript.notify(doc, args);
} }

View File

@ -15,7 +15,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.require('app/setup/doctype/contact_control/contact_control.js'); wn.require('app/setup/doctype/contact_control/contact_control.js');
wn.require('app/support/doctype/communication/communication.js');
cur_frm.cscript.onload = function(doc,dt,dn){ cur_frm.cscript.onload = function(doc,dt,dn){
@ -29,7 +28,6 @@ cur_frm.cscript.onload = function(doc,dt,dn){
// make contact, history list body // make contact, history list body
//cur_frm.cscript.make_cl_body(); //cur_frm.cscript.make_cl_body();
cur_frm.cscript.make_hl_body(); cur_frm.cscript.make_hl_body();
cur_frm.cscript.make_communication_body();
} }
cur_frm.cscript.refresh = function(doc,dt,dn) { cur_frm.cscript.refresh = function(doc,dt,dn) {
@ -46,8 +44,13 @@ cur_frm.cscript.refresh = function(doc,dt,dn) {
// make lists // make lists
cur_frm.cscript.make_address(doc,dt,dn); cur_frm.cscript.make_address(doc,dt,dn);
cur_frm.cscript.make_contact(doc,dt,dn); cur_frm.cscript.make_contact(doc,dt,dn);
cur_frm.cscript.render_communication_list(doc, cdt, cdn);
cur_frm.cscript.make_history(doc,dt,dn); cur_frm.cscript.make_history(doc,dt,dn);
cur_frm.communication_view = new wn.views.CommunicationList({
list: wn.model.get("Communication", {"supplier": doc.name}),
parent: cur_frm.fields_dict.communication_html.wrapper,
doc: doc
})
} }
} }

View File

@ -18,26 +18,23 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, 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.utils import cint, cstr, get_defaults
from webnotes.model import db_exists from webnotes.model.code import get_obj
from webnotes.model.doc import Document, addchild, getchildren, make_autoname from webnotes import form, msgprint
from webnotes.model.wrapper 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, msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql sql = webnotes.conn.sql
get_value = webnotes.conn.get_value
in_transaction = webnotes.conn.in_transaction
convert_to_lists = webnotes.conn.convert_to_lists convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- from utilities.transaction_base import TransactionBase
class DocType: class DocType(TransactionBase):
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
def onload(self):
self.add_communication_list()
def autoname(self): def autoname(self):
#get default naming conventional from control panel #get default naming conventional from control panel
supp_master_name = get_defaults()['supp_master_name'] supp_master_name = get_defaults()['supp_master_name']
@ -59,22 +56,17 @@ class DocType:
else: else:
self.doc.name = make_autoname(self.doc.naming_series+'.#####') self.doc.name = make_autoname(self.doc.naming_series+'.#####')
# ----------------------------------------
# update credit days and limit in account
# ----------------------------------------
def update_credit_days_limit(self): def update_credit_days_limit(self):
sql("update tabAccount set credit_days = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.name + " - " + self.get_company_abbr())) sql("update tabAccount set credit_days = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.name + " - " + self.get_company_abbr()))
def on_update(self): def on_update(self):
if not self.doc.naming_series: if not self.doc.naming_series:
self.doc.naming_series = '' self.doc.naming_series = ''
# create address # create address
addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode] addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds)) address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
set(self.doc,'address', address_line) webnotes.conn.set(self.doc,'address', address_line)
# create account head # create account head
self.create_account_head() self.create_account_head()
@ -82,12 +74,9 @@ class DocType:
# update credit days and limit in account # update credit days and limit in account
self.update_credit_days_limit() self.update_credit_days_limit()
def check_state(self): 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)]) return "\n" + "\n".join([i[0] for i in sql("select state_name from `tabState` where `tabState`.country='%s' " % self.doc.country)])
# ACCOUNTS
# -------------------------------------------
def get_payables_group(self): def get_payables_group(self):
g = sql("select payables_group from tabCompany where name=%s", self.doc.company) g = sql("select payables_group from tabCompany where name=%s", self.doc.company)
g = g and g[0][0] or '' g = g and g[0][0] or ''
@ -116,7 +105,6 @@ class DocType:
return self.doc.supplier_type + " - " + abbr return self.doc.supplier_type + " - " + abbr
def validate(self): def validate(self):
#validation for Naming Series mandatory field... #validation for Naming Series mandatory field...
if get_defaults()['supp_master_name'] == 'Naming Series': if get_defaults()['supp_master_name'] == 'Naming Series':
@ -124,9 +112,6 @@ class DocType:
msgprint("Series is Mandatory.") msgprint("Series is Mandatory.")
raise Exception raise Exception
# create accont head - in tree under zone + territory
# -------------------------------------------------------
def create_account_head(self): def create_account_head(self):
if self.doc.company : if self.doc.company :
abbr = self.get_company_abbr() abbr = self.get_company_abbr()
@ -142,7 +127,6 @@ class DocType:
else : else :
msgprint("Please select Company under which you want to create account head") msgprint("Please select Company under which you want to create account head")
def get_contacts(self,nm): def get_contacts(self,nm):
if nm: if nm:
contact_details =convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm)) contact_details =convert_to_lists(sql("select name, CONCAT(IFNULL(first_name,''),' ',IFNULL(last_name,'')),contact_no,email_id from `tabContact` where supplier = '%s'"%nm))
@ -172,16 +156,12 @@ class DocType:
from webnotes.model import delete_doc from webnotes.model import delete_doc
delete_doc('Account', acc[0][0]) delete_doc('Account', acc[0][0])
def on_trash(self): def on_trash(self):
self.delete_supplier_address() self.delete_supplier_address()
self.delete_supplier_contact() self.delete_supplier_contact()
self.delete_supplier_communication() self.delete_supplier_communication()
self.delete_supplier_account() self.delete_supplier_account()
# on rename
# ---------
def on_rename(self,newdn,olddn): def on_rename(self,newdn,olddn):
#update supplier_name if not naming series #update supplier_name if not naming series
if get_defaults().get('supp_master_name') == 'Supplier Name': if get_defaults().get('supp_master_name') == 'Supplier Name':

View File

@ -2,11 +2,12 @@
{ {
"owner": "Administrator", "owner": "Administrator",
"docstatus": 0, "docstatus": 0,
"creation": "2012-07-18 20:34:42", "creation": "2012-11-02 17:17:04",
"modified_by": "Administrator", "modified_by": "Administrator",
"modified": "2012-07-18 17:41:49" "modified": "2012-11-30 10:53:32"
}, },
{ {
"autoname": "naming_series:",
"name": "__common__", "name": "__common__",
"search_fields": "supplier_name,supplier_type", "search_fields": "supplier_name,supplier_type",
"module": "Buying", "module": "Buying",
@ -32,6 +33,16 @@
"name": "Supplier", "name": "Supplier",
"doctype": "DocType" "doctype": "DocType"
}, },
{
"description": "Note: You Can Manage Multiple Address or Contacts via Addresses & Contacts",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Basic Info",
"fieldname": "basic_info",
"fieldtype": "Section Break",
"permlevel": 0
},
{ {
"no_copy": 1, "no_copy": 1,
"oldfieldtype": "Data", "oldfieldtype": "Data",
@ -124,7 +135,6 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"label": "Communication History",
"fieldname": "communication_history", "fieldname": "communication_history",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"permlevel": 0 "permlevel": 0
@ -246,8 +256,7 @@
"write": 1, "write": 1,
"role": "Purchase Master Manager", "role": "Purchase Master Manager",
"cancel": 1, "cancel": 1,
"permlevel": 0, "permlevel": 0
"match": ""
}, },
{ {
"amend": 0, "amend": 0,

View File

@ -1,4 +1,9 @@
erpnext.updates = [ erpnext.updates = [
["30th November 2012", [
"Auto Notifications: System will prompt user with pre-set message for auto-notification.",
"Employee: Users with role Employee will only be able to see their Employee Records.",
"Leave Application: Users with role Employee can now apply for leaves. HR User will be able to set Approval or Rejection.",
]],
["29th November 2012", [ ["29th November 2012", [
"EMail: Form Emails are now via Communication (with Rich Text Etc.).", "EMail: Form Emails are now via Communication (with Rich Text Etc.).",
]], ]],

View File

@ -38,6 +38,8 @@ class DocType:
elif ret[0][0]=='Employee Number': elif ret[0][0]=='Employee Number':
self.doc.name = make_autoname(self.doc.employee_number) self.doc.name = make_autoname(self.doc.employee_number)
self.doc.employee = self.doc.name
def get_retirement_date(self): def get_retirement_date(self):
import datetime import datetime
ret = {} ret = {}
@ -51,6 +53,7 @@ class DocType:
return ret_sal_struct and ret_sal_struct[0][0] or '' return ret_sal_struct and ret_sal_struct[0][0] or ''
def validate(self): def validate(self):
self.doc.employee = self.doc.name
self.validate_date() self.validate_date()
self.validate_email() self.validate_email()
self.validate_name() self.validate_name()

File diff suppressed because it is too large Load Diff

View File

@ -1,120 +1,75 @@
# DocType, Employee External Work History
[ [
# These values are common in all dictionaries
{ {
'creation': '2012-03-27 14:35:59', "owner": "Administrator",
'docstatus': 0, "docstatus": 0,
'modified': '2012-03-27 14:35:59', "creation": "2012-07-03 13:29:41",
'modified_by': u'Administrator', "modified_by": "Administrator",
'owner': u'Administrator' "modified": "2012-11-30 11:57:58"
}, },
# These values are common for all DocType
{ {
'colour': u'White:FFF', "istable": 1,
'doctype': 'DocType', "name": "__common__",
'istable': 1, "doctype": "DocType",
'module': u'HR', "module": "HR"
'name': '__common__',
'section_style': u'Simple',
'server_code_error': u' ',
'show_in_menu': 0,
'version': 3
}, },
# These values are common for all DocField
{ {
'doctype': u'DocField', "name": "__common__",
'name': '__common__', "parent": "Employee External Work History",
'parent': u'Employee External Work History', "doctype": "DocField",
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType', "permlevel": 0,
'permlevel': 0 "parentfield": "fields"
}, },
# These values are common for all DocPerm
{ {
'create': 1, "name": "Employee External Work History",
'doctype': u'DocPerm', "doctype": "DocType"
'name': '__common__',
'parent': u'Employee External Work History',
'parentfield': u'permissions',
'parenttype': u'DocType',
'permlevel': 0,
'read': 1,
'role': u'All',
'write': 1
}, },
# DocType, Employee External Work History
{ {
'doctype': 'DocType', "oldfieldtype": "Data",
'name': u'Employee External Work History' "doctype": "DocField",
"label": "Company",
"oldfieldname": "company_name",
"fieldname": "company_name",
"fieldtype": "Data"
}, },
# DocPerm
{ {
'doctype': u'DocPerm' "oldfieldtype": "Data",
"doctype": "DocField",
"label": "Designation",
"oldfieldname": "designation",
"fieldname": "designation",
"fieldtype": "Data"
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Currency",
'fieldname': u'company_name', "doctype": "DocField",
'fieldtype': u'Data', "label": "Salary",
'label': u'Company', "oldfieldname": "salary",
'oldfieldname': u'company_name', "fieldname": "salary",
'oldfieldtype': u'Data' "fieldtype": "Currency"
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Small Text",
'fieldname': u'designation', "doctype": "DocField",
'fieldtype': u'Data', "label": "Address",
'label': u'Designation', "oldfieldname": "address",
'oldfieldname': u'designation', "fieldname": "address",
'oldfieldtype': u'Data' "fieldtype": "Small Text"
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Data",
'fieldname': u'salary', "doctype": "DocField",
'fieldtype': u'Currency', "label": "Contact",
'label': u'Salary', "oldfieldname": "contact",
'oldfieldname': u'salary', "fieldname": "contact",
'oldfieldtype': u'Currency' "fieldtype": "Data"
}, },
# DocField
{ {
'doctype': u'DocField', "oldfieldtype": "Data",
'fieldname': u'address', "doctype": "DocField",
'fieldtype': u'Small Text', "label": "Total Experience",
'label': u'Address', "oldfieldname": "total_experience",
'oldfieldname': u'address', "fieldname": "total_experience",
'oldfieldtype': u'Small Text' "fieldtype": "Data"
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'contact',
'fieldtype': u'Data',
'label': u'Contact',
'oldfieldname': u'contact',
'oldfieldtype': u'Data'
},
# DocField
{
'doctype': u'DocField',
'fieldname': u'total_experience',
'fieldtype': u'Data',
'label': u'Total Experience',
'oldfieldname': u'total_experience',
'oldfieldtype': u'Data'
} }
] ]

View File

@ -100,8 +100,6 @@ cur_frm.cscript.sanctioned_amount = function(doc,cdt,cdn){
cur_frm.cscript.calculate_total(doc,cdt,cdn); cur_frm.cscript.calculate_total(doc,cdt,cdn);
} }
wn.require('app/setup/doctype/notification_control/notification_control.js');
cur_frm.cscript.approve = function(doc,cdt,cdn){ cur_frm.cscript.approve = function(doc,cdt,cdn){
cur_frm.cscript.calculate_total(doc,cdt,cdn); cur_frm.cscript.calculate_total(doc,cdt,cdn);
@ -248,12 +246,9 @@ cur_frm.cscript.update_voucher = function(doc){
} }
cur_frm.cscript.on_submit = function(doc, cdt, cdn) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
var args = { if(cint(wn.boot.notification_settings.expense_claim)) {
type: 'Expense Claim', cur_frm.email_doc(wn.boot.notification_settings.expense_claim);
doctype: 'Expense Claim',
send_to: doc.exp_approver
} }
cur_frm.cscript.notify(doc, args);
} }
cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query; cur_frm.fields_dict.employee.get_query = erpnext.utils.employee_query;

View File

@ -14,39 +14,49 @@
// You should have received a copy of the GNU General Public License // 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/>.
// ****************************************** onload ********************************************************
cur_frm.cscript.onload = function(doc, dt, dn) { cur_frm.cscript.onload = function(doc, dt, dn) {
if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()}); if(!doc.posting_date) set_multiple(dt,dn,{posting_date:get_today()});
} }
cur_frm.cscript.refresh = function(doc, dt, dn) {
cur_frm.set_intro("");
if(doc.__islocal && !in_list(user_roles, "HR User")) {
cur_frm.set_intro("Fill the form and save it")
} else {
if(in_list(user_roles, "HR User")) {
if(doc.status=="Open") {
cur_frm.set_intro("Please Approve (and Submit) or Reject, or re-assign to applicant for further review.");
}
} else {
if(doc.status=="Open") {
cur_frm.set_intro("Leave application is pending approval.");
} else if(doc.status=="Approved") {
cur_frm.set_intro("Leave application has been approved.");
} else if(doc.status=="Rejected") {
cur_frm.set_intro("Leave application has been rejected.");
}
}
}
if(doc.status=="Approved" && doc.docstatus!=1) {
cur_frm.savesubmit()
}
}
// ************************************** client triggers ***************************************************
// ---------
// employee
// ---------
cur_frm.add_fetch('employee','employee_name','employee_name'); cur_frm.add_fetch('employee','employee_name','employee_name');
cur_frm.cscript.employee = function (doc, dt, dn){ cur_frm.cscript.employee = function (doc, dt, dn){
get_leave_balance(doc, dt, dn); get_leave_balance(doc, dt, dn);
} }
// ------------
// fiscal_year
// ------------
cur_frm.cscript.fiscal_year = function (doc, dt, dn){ cur_frm.cscript.fiscal_year = function (doc, dt, dn){
get_leave_balance(doc, dt, dn); get_leave_balance(doc, dt, dn);
} }
// -----------
// leave type
// -----------
cur_frm.cscript.leave_type = function (doc, dt, dn){ cur_frm.cscript.leave_type = function (doc, dt, dn){
get_leave_balance(doc, dt, dn); get_leave_balance(doc, dt, dn);
} }
// ---------
// half day
// ---------
cur_frm.cscript.half_day = function(doc, dt, dn) { cur_frm.cscript.half_day = function(doc, dt, dn) {
if(doc.from_date) { if(doc.from_date) {
set_multiple(dt,dn,{to_date:doc.from_date}); set_multiple(dt,dn,{to_date:doc.from_date});
@ -54,9 +64,6 @@ cur_frm.cscript.half_day = function(doc, dt, dn) {
} }
} }
// ---------
// from date
// ---------
cur_frm.cscript.from_date = function(doc, dt, dn) { cur_frm.cscript.from_date = function(doc, dt, dn) {
if(cint(doc.half_day) == 1){ if(cint(doc.half_day) == 1){
set_multiple(dt,dn,{to_date:doc.from_date}); set_multiple(dt,dn,{to_date:doc.from_date});
@ -64,9 +71,6 @@ cur_frm.cscript.from_date = function(doc, dt, dn) {
calculate_total_days(doc, dt, dn); calculate_total_days(doc, dt, dn);
} }
// --------
// to date
// --------
cur_frm.cscript.to_date = function(doc, dt, dn) { cur_frm.cscript.to_date = function(doc, dt, dn) {
if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){ if(cint(doc.half_day) == 1 && cstr(doc.from_date) && doc.from_date != doc.to_date){
msgprint("To Date should be same as From Date for Half Day leave"); msgprint("To Date should be same as From Date for Half Day leave");
@ -75,20 +79,11 @@ cur_frm.cscript.to_date = function(doc, dt, dn) {
calculate_total_days(doc, dt, dn); calculate_total_days(doc, dt, dn);
} }
// ******************************************* utilities ****************************************************
// ------------------
// get leave balance
// ------------------
get_leave_balance = function(doc, dt, dn) { get_leave_balance = function(doc, dt, dn) {
if(doc.employee && doc.leave_type && doc.fiscal_year) if(doc.employee && doc.leave_type && doc.fiscal_year)
get_server_fields('get_leave_balance', '','', doc, dt, dn, 1); get_server_fields('get_leave_balance', '','', doc, dt, dn, 1);
} }
// ---------------
// calculate days
// ---------------
calculate_total_days = function(doc, dt, dn) { calculate_total_days = function(doc, dt, dn) {
if(doc.from_date && doc.to_date){ if(doc.from_date && doc.to_date){
if(cint(doc.half_day) == 1) set_multiple(dt,dn,{total_leave_days:0.5}); if(cint(doc.half_day) == 1) set_multiple(dt,dn,{total_leave_days:0.5});

View File

@ -38,12 +38,6 @@ class DocType:
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
# ******************************************** client triggers ***********************************************
# ------------------
# get leave balance
# ------------------
def get_leave_balance(self): def get_leave_balance(self):
leave_all = sql("select total_leaves_allocated from `tabLeave Allocation` where employee = '%s' and leave_type = '%s' and fiscal_year = '%s' and docstatus = 1" % (self.doc.employee, self.doc.leave_type, self.doc.fiscal_year)) leave_all = sql("select total_leaves_allocated from `tabLeave Allocation` where employee = '%s' and leave_type = '%s' and fiscal_year = '%s' and docstatus = 1" % (self.doc.employee, self.doc.leave_type, self.doc.fiscal_year))
leave_all = leave_all and flt(leave_all[0][0]) or 0 leave_all = leave_all and flt(leave_all[0][0]) or 0
@ -52,10 +46,6 @@ class DocType:
ret = {'leave_balance':leave_all - leave_app} ret = {'leave_balance':leave_all - leave_app}
return ret return ret
# ************************************************ utilities *************************************************
# -------------------
def get_holidays(self): def get_holidays(self):
""" """
get total holidays get total holidays
@ -65,10 +55,6 @@ class DocType:
tot_hol = sql("select count(*) from `tabHoliday` h1, `tabHoliday List` h2 where h1.parent = h2.name and h1.holiday_date between '%s' and '%s' and ifnull(h2.is_default,0) = 1 and h2.fiscal_year = %s"% (self.doc.from_date, self.doc.to_date, self.doc.fiscal_year)) tot_hol = sql("select count(*) from `tabHoliday` h1, `tabHoliday List` h2 where h1.parent = h2.name and h1.holiday_date between '%s' and '%s' and ifnull(h2.is_default,0) = 1 and h2.fiscal_year = %s"% (self.doc.from_date, self.doc.to_date, self.doc.fiscal_year))
return tot_hol and flt(tot_hol[0][0]) or 0 return tot_hol and flt(tot_hol[0][0]) or 0
# ---------------------
# get total leave days
# ---------------------
def get_total_leave_days(self): def get_total_leave_days(self):
""" """
Calculates total leave days based on input and holidays Calculates total leave days based on input and holidays
@ -82,27 +68,15 @@ class DocType:
} }
return ret return ret
# ************************************************ validate *************************************************
# -----------------
# validate to date
# -----------------
def validate_to_date(self): def validate_to_date(self):
if self.doc.from_date and self.doc.to_date and (getdate(self.doc.to_date) < getdate(self.doc.from_date)): if self.doc.from_date and self.doc.to_date and (getdate(self.doc.to_date) < getdate(self.doc.from_date)):
msgprint("To date cannot be before from date") msgprint("To date cannot be before from date")
raise Exception raise Exception
# --------------------------------
# check whether leave type is lwp
# --------------------------------
def is_lwp(self): def is_lwp(self):
lwp = sql("select is_lwp from `tabLeave Type` where name = %s", self.doc.leave_type) lwp = sql("select is_lwp from `tabLeave Type` where name = %s", self.doc.leave_type)
return lwp and cint(lwp[0][0]) or 0 return lwp and cint(lwp[0][0]) or 0
# ------------------------
# validate balance leaves
# ------------------------
def validate_balance_leaves(self): def validate_balance_leaves(self):
if self.doc.from_date and self.doc.to_date and not self.is_lwp(): if self.doc.from_date and self.doc.to_date and not self.is_lwp():
bal = self.get_leave_balance() bal = self.get_leave_balance()
@ -111,12 +85,8 @@ class DocType:
set(self.doc,'leave_balance',flt(bal['leave_balance'])) set(self.doc,'leave_balance',flt(bal['leave_balance']))
set(self.doc,'total_leave_days',flt(tot_leaves['total_leave_days'])) set(self.doc,'total_leave_days',flt(tot_leaves['total_leave_days']))
if flt(bal['leave_balance']) < flt(tot_leaves['total_leave_days']): if flt(bal['leave_balance']) < flt(tot_leaves['total_leave_days']):
msgprint("Employee : %s cannot apply for %s of more than %s days" % (self.doc.employee, self.doc.leave_type, flt(bal['leave_balance']))) msgprint("Warning : There is not enough leave balance")
raise Exception
#
# validate overlapping leaves
#
def validate_leave_overlap(self): def validate_leave_overlap(self):
for d in sql("""select name, leave_type, posting_date, from_date, to_date for d in sql("""select name, leave_type, posting_date, from_date, to_date
from `tabLeave Application` from `tabLeave Application`
@ -128,9 +98,6 @@ class DocType:
msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : %s" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name']), raise_exception = 1) msgprint("Employee : %s has already applied for %s between %s and %s on %s. Please refer Leave Application : %s" % (self.doc.employee, cstr(d['leave_type']), formatdate(d['from_date']), formatdate(d['to_date']), formatdate(d['posting_date']), d['name']), raise_exception = 1)
# ---------------------------------------------------------------------
# validate max days for which leave can be applied for particular type
# ---------------------------------------------------------------------
def validate_max_days(self): def validate_max_days(self):
max_days = sql("select max_days_allowed from `tabLeave Type` where name = '%s'" %(self.doc.leave_type)) max_days = sql("select max_days_allowed from `tabLeave Type` where name = '%s'" %(self.doc.leave_type))
max_days = max_days and flt(max_days[0][0]) or 0 max_days = max_days and flt(max_days[0][0]) or 0
@ -138,12 +105,13 @@ class DocType:
msgprint("Sorry ! You cannot apply for %s for more than %s days" % (self.doc.leave_type, max_days)) msgprint("Sorry ! You cannot apply for %s for more than %s days" % (self.doc.leave_type, max_days))
raise Exception raise Exception
# ---------
# validate
# ---------
def validate(self): def validate(self):
self.validate_to_date() self.validate_to_date()
self.validate_balance_leaves() self.validate_balance_leaves()
self.validate_leave_overlap() self.validate_leave_overlap()
self.validate_max_days() self.validate_max_days()
def on_submit(self):
if self.doc.status != "Approved":
webnotes.msgprint("""Only Approved Leave Applications can be Submitted.""",
raise_exception=True)

View File

@ -1,285 +1,239 @@
# DocType, Leave Application
[ [
# These values are common in all dictionaries
{ {
u'creation': '2012-05-15 12:14:45', "owner": "Administrator",
u'docstatus': 0, "docstatus": 0,
u'modified': '2012-10-02 11:19:44', "creation": "2012-11-02 17:16:54",
u'modified_by': u'Administrator', "modified_by": "Administrator",
u'owner': u'Administrator' "modified": "2012-11-30 12:17:27"
}, },
# These values are common for all DocType
{ {
'_last_update': u'1310019491', "is_submittable": 1,
'autoname': u'LAP/.#####', "autoname": "LAP/.#####",
'colour': u'White:FFF', "name": "__common__",
u'doctype': u'DocType', "search_fields": "employee,employee_name,leave_type,from_date,to_date,total_leave_days,fiscal_year",
'document_type': u'Transaction', "module": "HR",
'is_submittable': 1, "doctype": "DocType",
'module': u'HR', "document_type": "Transaction"
u'name': u'__common__',
'search_fields': u'employee,employee_name,leave_type,from_date,to_date,total_leave_days,fiscal_year',
'section_style': u'Simple',
'show_in_menu': 0,
'subject': u'From %(employee_name)s, %(designation)s',
'tag_fields': u'leave_type',
'version': 1
}, },
# These values are common for all DocField
{ {
u'doctype': u'DocField', "name": "__common__",
u'name': u'__common__', "parent": "Leave Application",
'parent': u'Leave Application', "doctype": "DocField",
'parentfield': u'fields', "parenttype": "DocType",
'parenttype': u'DocType' "parentfield": "fields"
}, },
# These values are common for all DocPerm
{ {
u'doctype': u'DocPerm', "name": "__common__",
u'name': u'__common__', "parent": "Leave Application",
'parent': u'Leave Application', "read": 1,
'parentfield': u'permissions', "doctype": "DocPerm",
'parenttype': u'DocType', "parenttype": "DocType",
'read': 1 "parentfield": "permissions"
}, },
# DocType, Leave Application
{ {
u'doctype': u'DocType', "name": "Leave Application",
u'name': u'Leave Application' "doctype": "DocType"
}, },
# DocField
{ {
u'doctype': u'DocField', "default": "Open",
'fieldname': u'column_break0', "colour": "White:FFF",
'fieldtype': u'Column Break', "doctype": "DocField",
'permlevel': 0, "label": "Status",
'width': u'50%' "options": "Open\nApproved\nRejected",
"fieldname": "status",
"fieldtype": "Select",
"permlevel": 3
}, },
# DocField
{ {
u'doctype': u'DocField', "search_index": 1,
'fieldname': u'employee', "doctype": "DocField",
'fieldtype': u'Link', "label": "Leave Type",
'in_filter': 1, "options": "link:Leave Type",
'label': u'Employee', "fieldname": "leave_type",
'options': u'Employee', "fieldtype": "Select",
'permlevel': 0, "reqd": 1,
'reqd': 1, "permlevel": 0,
'search_index': 1 "in_filter": 1
}, },
# DocField
{ {
u'doctype': u'DocField', "search_index": 1,
'fieldname': u'employee_name', "colour": "White:FFF",
'fieldtype': u'Data', "doctype": "DocField",
'in_filter': 1, "label": "From Date",
'label': u'Employee Name', "trigger": "Client",
'permlevel': 1, "fieldname": "from_date",
'search_index': 0 "fieldtype": "Date",
"reqd": 1,
"permlevel": 0
}, },
# DocField
{ {
u'doctype': u'DocField', "search_index": 1,
'fieldname': u'leave_type', "colour": "White:FFF",
'fieldtype': u'Select', "doctype": "DocField",
'in_filter': 1, "label": "To Date",
'label': u'Leave Type', "trigger": "Client",
'options': u'link:Leave Type', "fieldname": "to_date",
'permlevel': 0, "fieldtype": "Date",
'reqd': 1, "reqd": 1,
'search_index': 1 "permlevel": 0
}, },
# DocField
{ {
u'doctype': u'DocField', "colour": "White:FFF",
'fieldname': u'leave_balance', "doctype": "DocField",
'fieldtype': u'Currency', "label": "Half Day",
'label': u'Leave Balance', "trigger": "Client",
'permlevel': 1 "fieldname": "half_day",
"fieldtype": "Check",
"permlevel": 0
}, },
# DocField
{ {
'colour': u'White:FFF', "doctype": "DocField",
'default': u'Today', "width": "50%",
u'doctype': u'DocField', "fieldname": "column_break1",
'fieldname': u'posting_date', "fieldtype": "Column Break",
'fieldtype': u'Date', "permlevel": 0
'label': u'Posting Date',
'no_copy': 1,
'permlevel': 1,
'reqd': 1
}, },
# DocField
{ {
u'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'fiscal_year', "label": "Leave Balance",
'fieldtype': u'Select', "fieldname": "leave_balance",
'in_filter': 1, "fieldtype": "Currency",
'label': u'Fiscal Year', "permlevel": 1
'options': u'link:Fiscal Year',
'permlevel': 0,
'reqd': 1,
'search_index': 0
}, },
# DocField
{ {
u'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'column_break1', "label": "Total Leave Days",
'fieldtype': u'Column Break', "fieldname": "total_leave_days",
'permlevel': 0, "fieldtype": "Currency",
'width': u'50%' "permlevel": 1
}, },
# DocField
{ {
'colour': u'White:FFF', "search_index": 1,
u'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'half_day', "label": "Employee",
'fieldtype': u'Check', "options": "Employee",
'label': u'Half Day', "fieldname": "employee",
'permlevel': 0, "fieldtype": "Link",
'trigger': u'Client' "reqd": 1,
"permlevel": 0,
"in_filter": 1
}, },
# DocField
{ {
'colour': u'White:FFF', "search_index": 0,
u'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'from_date', "label": "Employee Name",
'fieldtype': u'Date', "fieldname": "employee_name",
'label': u'From Date', "fieldtype": "Data",
'permlevel': 0, "permlevel": 1,
'search_index': 1, "in_filter": 1
'trigger': u'Client'
}, },
# DocField
{ {
'colour': u'White:FFF', "doctype": "DocField",
u'doctype': u'DocField', "fieldname": "sb10",
'fieldname': u'to_date', "fieldtype": "Section Break",
'fieldtype': u'Date', "permlevel": 0
'label': u'To Date',
'permlevel': 0,
'search_index': 1,
'trigger': u'Client'
}, },
# DocField
{ {
u'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'total_leave_days', "label": "Reason",
'fieldtype': u'Currency', "width": "300px",
'label': u'Total Leave Days', "fieldname": "description",
'permlevel': 1 "fieldtype": "Text Editor",
"permlevel": 0
}, },
# DocField
{ {
u'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'description', "label": "HR Details",
'fieldtype': u'Small Text', "fieldname": "sb12",
'label': u'Description', "fieldtype": "Section Break",
'permlevel': 0, "permlevel": 2
'width': u'300px'
}, },
# DocField
{ {
u'doctype': u'DocField', "default": "Today",
'fieldname': u'letter_head', "colour": "White:FFF",
'fieldtype': u'Link', "doctype": "DocField",
'label': u'Letter Head', "label": "Posting Date",
'options': u'Letter Head', "no_copy": 1,
'permlevel': 0 "fieldname": "posting_date",
"fieldtype": "Date",
"reqd": 1,
"permlevel": 2
}, },
# DocField
{ {
u'doctype': u'DocField', "search_index": 0,
'fieldname': u'amended_from', "doctype": "DocField",
'fieldtype': u'Data', "label": "Fiscal Year",
'label': u'Amended From', "options": "link:Fiscal Year",
'permlevel': 1 "fieldname": "fiscal_year",
"fieldtype": "Select",
"reqd": 1,
"permlevel": 2,
"in_filter": 1
}, },
# DocField
{ {
u'doctype': u'DocField', "doctype": "DocField",
'fieldname': u'amendment_date', "label": "Letter Head",
'fieldtype': u'Date', "options": "Letter Head",
'label': u'Amendment Date', "fieldname": "letter_head",
'permlevel': 1 "fieldtype": "Link",
"permlevel": 2
}, },
# DocPerm
{ {
'amend': 0, "doctype": "DocField",
'cancel': 0, "label": "Amended From",
'create': 0, "fieldname": "amended_from",
u'doctype': u'DocPerm', "fieldtype": "Data",
'match': u'owner', "permlevel": 2
'permlevel': 0,
'role': u'Employee',
'submit': 0,
'write': 0
}, },
# DocPerm
{ {
'amend': 1, "doctype": "DocField",
'cancel': 1, "label": "Amendment Date",
'create': 1, "fieldname": "amendment_date",
u'doctype': u'DocPerm', "fieldtype": "Date",
'permlevel': 0, "permlevel": 2
'role': u'HR User',
'submit': 1,
'write': 1
}, },
# DocPerm
{ {
'amend': 1, "create": 1,
'cancel': 1, "doctype": "DocPerm",
'create': 1, "write": 1,
u'doctype': u'DocPerm', "role": "Employee",
'permlevel': 0, "permlevel": 0,
'role': u'HR Manager', "match": "employee"
'submit': 1,
'write': 1
}, },
# DocPerm
{ {
u'doctype': u'DocPerm', "doctype": "DocPerm",
'permlevel': 1, "role": "All",
'role': u'HR User' "permlevel": 1
}, },
# DocPerm
{ {
u'doctype': u'DocPerm', "amend": 1,
'permlevel': 1, "create": 1,
'role': u'HR Manager' "doctype": "DocPerm",
"submit": 1,
"write": 1,
"role": "HR User",
"cancel": 1,
"permlevel": 0
}, },
# DocPerm
{ {
u'doctype': u'DocPerm', "amend": 0,
'permlevel': 1, "create": 0,
'role': u'Employee' "doctype": "DocPerm",
"submit": 0,
"write": 1,
"role": "HR User",
"cancel": 0,
"permlevel": 2
},
{
"doctype": "DocPerm",
"role": "All",
"permlevel": 3
},
{
"doctype": "DocPerm",
"write": 1,
"role": "HR User",
"permlevel": 3
} }
] ]

View File

@ -3,6 +3,7 @@ wn.doclistviews['Leave Application'] = wn.views.ListView.extend({
init: function(d) { init: function(d) {
this._super(d) this._super(d)
this.fields = this.fields.concat([ this.fields = this.fields.concat([
"`tabLeave Application`.status",
"`tabLeave Application`.employee_name", "`tabLeave Application`.employee_name",
"`tabLeave Application`.total_leave_days", "`tabLeave Application`.total_leave_days",
"`tabLeave Application`.from_date", "`tabLeave Application`.from_date",
@ -12,8 +13,21 @@ wn.doclistviews['Leave Application'] = wn.views.ListView.extend({
this.stats = this.stats.concat(['company']); this.stats = this.stats.concat(['company']);
}, },
label_style: {
"status": {
"Open": "danger",
"Approved": "success",
"Rejected": "info",
}
},
prepare_data: function(data) { prepare_data: function(data) {
this._super(data); this._super(data);
data.label_style = this.label_style.status[data.status];
data.status_html = repl('<span class="label \
label-%(label_style)s">%(status)s</span>', data);
data.from_date = wn.datetime.str_to_user(data.from_date); data.from_date = wn.datetime.str_to_user(data.from_date);
data.to_date = wn.datetime.str_to_user(data.to_date); data.to_date = wn.datetime.str_to_user(data.to_date);
data.date_range = (data.from_date === data.to_date) data.date_range = (data.from_date === data.to_date)
@ -28,10 +42,10 @@ wn.doclistviews['Leave Application'] = wn.views.ListView.extend({
{width: '3%', content: 'check'}, {width: '3%', content: 'check'},
{width: '5%', content:'avatar'}, {width: '5%', content:'avatar'},
{width: '3%', content:'docstatus'}, {width: '3%', content:'docstatus'},
{width: '15%', content:'status_html'},
{width: '12%', content:'name'}, {width: '12%', content:'name'},
{width: '37%', content:'employee_name+tags'}, {width: '25%', content:'employee_name+tags'},
{width: '10%', content:'total_leave_days', {width: '25%', content:'date_range'},
css: {'color':'#777'}}, {width: '12%', content:'modified'},
{width: '30%', content:'date_range'},
] ]
}); });

View File

@ -0,0 +1,6 @@
import webnotes
def execute():
webnotes.clear_perms("Employee")
webnotes.reload_doc("hr", "doctype", "employee")
webnotes.conn.sql("""update tabEmployee set employee=name""")

View File

@ -0,0 +1,9 @@
import webnotes
def execute():
webnotes.clear_perms("Leave Application")
webnotes.reload_doc("hr", "doctype", "leave_application")
webnotes.conn.sql("""update `tabLeave Application` set status='Approved'
where docstatus=1""")
webnotes.conn.sql("""update `tabLeave Application` set status='Open'
where docstatus=0""")

View File

@ -689,4 +689,12 @@ patch_list = [
'patch_module': 'patches.november_2012', 'patch_module': 'patches.november_2012',
'patch_file': 'add_theme_to_profile', 'patch_file': 'add_theme_to_profile',
}, },
{
'patch_module': 'patches.november_2012',
'patch_file': 'add_employee_field_in_employee',
},
{
'patch_module': 'patches.november_2012',
'patch_file': 'leave_application_cleanup',
},
] ]

View File

@ -15,9 +15,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.require('app/setup/doctype/contact_control/contact_control.js'); wn.require('app/setup/doctype/contact_control/contact_control.js');
wn.require('app/support/doctype/communication/communication.js');
/* ********************************* onload ********************************************* */
cur_frm.cscript.onload = function(doc,dt,dn){ cur_frm.cscript.onload = function(doc,dt,dn){
// history doctypes and scripts // history doctypes and scripts
@ -32,8 +29,6 @@ cur_frm.cscript.onload = function(doc,dt,dn){
//cur_frm.cscript.make_sl_body(); //cur_frm.cscript.make_sl_body();
cur_frm.cscript.load_defaults(doc, dt, dn); cur_frm.cscript.load_defaults(doc, dt, dn);
cur_frm.cscript.make_communication_body();
} }
cur_frm.cscript.load_defaults = function(doc, dt, dn) { cur_frm.cscript.load_defaults = function(doc, dt, dn) {
@ -47,8 +42,6 @@ cur_frm.cscript.load_defaults = function(doc, dt, dn) {
cur_frm.add_fetch('lead_name', 'company_name', 'customer_name'); cur_frm.add_fetch('lead_name', 'company_name', 'customer_name');
cur_frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate'); cur_frm.add_fetch('default_sales_partner','commission_rate','default_commission_rate');
/* ********************************* refresh ********************************************* */
cur_frm.cscript.refresh = function(doc,dt,dn) { cur_frm.cscript.refresh = function(doc,dt,dn) {
if(sys_defaults.cust_master_name == 'Customer Name') if(sys_defaults.cust_master_name == 'Customer Name')
hide_field('naming_series'); hide_field('naming_series');
@ -57,16 +50,18 @@ cur_frm.cscript.refresh = function(doc,dt,dn) {
if(doc.__islocal){ if(doc.__islocal){
hide_field(['address_html','contact_html']); hide_field(['address_html','contact_html']);
//cur_frm.cscript.set_hl_msg(doc);
//cur_frm.cscript.set_sl_msg(doc);
}else{ }else{
unhide_field(['address_html','contact_html']); unhide_field(['address_html','contact_html']);
// make lists // make lists
cur_frm.cscript.make_address(doc,dt,dn); cur_frm.cscript.make_address(doc,dt,dn);
cur_frm.cscript.make_contact(doc,dt,dn); cur_frm.cscript.make_contact(doc,dt,dn);
cur_frm.cscript.make_history(doc,dt,dn); cur_frm.cscript.make_history(doc,dt,dn);
cur_frm.cscript.render_communication_list(doc, cdt, cdn);
//cur_frm.cscript.make_shipping_address(doc,dt,dn); cur_frm.communication_view = new wn.views.CommunicationList({
list: wn.model.get("Communication", {"customer": doc.name}),
parent: cur_frm.fields_dict.communication_html.wrapper,
doc: doc
});
} }
} }
@ -117,11 +112,6 @@ cur_frm.cscript.make_contact = function() {
} }
/* ********************************* client triggers ************************************** */
// ---------------
// customer group
// ---------------
cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) { cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) {
return 'SELECT `tabCustomer Group`.`name`, `tabCustomer Group`.`parent_customer_group` FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "No" AND `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50'; return 'SELECT `tabCustomer Group`.`name`, `tabCustomer Group`.`parent_customer_group` FROM `tabCustomer Group` WHERE `tabCustomer Group`.`is_group` = "No" AND `tabCustomer Group`.`docstatus`!= 2 AND `tabCustomer Group`.%(key)s LIKE "%s" ORDER BY `tabCustomer Group`.`name` ASC LIMIT 50';
} }
@ -130,8 +120,6 @@ cur_frm.fields_dict['customer_group'].get_query = function(doc,dt,dn) {
cur_frm.fields_dict.lead_name.get_query = erpnext.utils.lead_query; cur_frm.fields_dict.lead_name.get_query = erpnext.utils.lead_query;
// Transaction History
// functions called by these functions are defined in communication.js
cur_frm.cscript.make_qtn_list = function(parent, doc) { cur_frm.cscript.make_qtn_list = function(parent, doc) {
cur_frm.cscript.get_common_list_view(parent, doc, 'Quotation'); cur_frm.cscript.get_common_list_view(parent, doc, 'Quotation');
} }
@ -173,7 +161,6 @@ cur_frm.cscript.get_common_list_view = function(parent, doc, doctype) {
cur_frm.cscript.render_list(doc, doctype, parent, ListView); cur_frm.cscript.render_list(doc, doctype, parent, ListView);
} }
cur_frm.cscript.make_si_list = function(parent, doc) { cur_frm.cscript.make_si_list = function(parent, doc) {
var ListView = wn.views.ListView.extend({ var ListView = wn.views.ListView.extend({
init: function(doclistview) { init: function(doclistview) {

View File

@ -18,24 +18,24 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import cstr, date_diff, flt, formatdate, get_defaults, getdate, has_common, now, nowdate, replace_newlines, sendmail, set_default, user_format, validate_email_add from webnotes.utils import cstr, get_defaults
from webnotes.model.doc import Document, make_autoname from webnotes.model.doc import Document, make_autoname
from webnotes.model.code import get_obj from webnotes.model.code import get_obj
from webnotes import msgprint, errprint from webnotes import msgprint, errprint
set = webnotes.conn.set
sql = webnotes.conn.sql sql = webnotes.conn.sql
get_value = webnotes.conn.get_value get_value = webnotes.conn.get_value
convert_to_lists = webnotes.conn.convert_to_lists
# ----------------------------------------------------------------------------------------- from utilities.transaction_base import TransactionBase
class DocType: class DocType(TransactionBase):
def __init__(self, doc, doclist=[]): def __init__(self, doc, doclist=[]):
self.doc = doc self.doc = doc
self.doclist = doclist self.doclist = doclist
# ******************************************************* autoname *********************************************************** def onload(self):
self.add_communication_list()
def autoname(self): def autoname(self):
cust_master_name = get_defaults().get('cust_master_name') cust_master_name = get_defaults().get('cust_master_name')
if cust_master_name == 'Customer Name': if cust_master_name == 'Customer Name':
@ -53,17 +53,9 @@ class DocType:
else: else:
self.doc.name = make_autoname(self.doc.naming_series+'.#####') self.doc.name = make_autoname(self.doc.naming_series+'.#####')
# ******************************************************* triggers ***********************************************************
# ----------------
# get company abbr
# -----------------
def get_company_abbr(self): def get_company_abbr(self):
return get_value('Company', self.doc.company, 'abbr') return get_value('Company', self.doc.company, 'abbr')
# -----------------------------------------------------------------------------------------------------
# get parent account(i.e receivables group from company where default account head need to be created)
# -----------------------------------------------------------------------------------------------------
def get_receivables_group(self): def get_receivables_group(self):
g = sql("select receivables_group from tabCompany where name=%s", self.doc.company) g = sql("select receivables_group from tabCompany where name=%s", self.doc.company)
g = g and g[0][0] or '' g = g and g[0][0] or ''
@ -72,26 +64,15 @@ class DocType:
raise Exception raise Exception
return g return g
# ******************************************************* validate *********************************************************
# ----------------
# validate values
# ----------------
def validate_values(self): def validate_values(self):
# Master name by naming series -> Series field mandatory # Master name by naming series -> Series field mandatory
if get_defaults().get('cust_master_name') == 'Naming Series' and not self.doc.naming_series: if get_defaults().get('cust_master_name') == 'Naming Series' and not self.doc.naming_series:
msgprint("Series is Mandatory.") msgprint("Series is Mandatory.")
raise Exception raise Exception
# ---------
# validate
# ---------
def validate(self): def validate(self):
self.validate_values() self.validate_values()
# ******************************************************* on update *********************************************************
# ------------------------
# create customer address
# ------------------------
def create_customer_address(self): def create_customer_address(self):
addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode] addr_flds = [self.doc.address_line1, self.doc.address_line2, self.doc.city, self.doc.state, self.doc.country, self.doc.pincode]
address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds)) address_line = "\n".join(filter(lambda x : (x!='' and x!=None),addr_flds))
@ -100,15 +81,11 @@ class DocType:
address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1) address_line = address_line + "\n" + "Phone: " + cstr(self.doc.phone_1)
if self.doc.email_id: if self.doc.email_id:
address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id) address_line = address_line + "\n" + "E-mail: " + cstr(self.doc.email_id)
set(self.doc,'address', address_line) webnotes.conn.set(self.doc,'address', address_line)
telephone = "(O): " + cstr(self.doc.phone_1) +"\n"+ cstr(self.doc.phone_2) + "\n" + "(M): " + "\n" + "(fax): " + cstr(self.doc.fax_1) telephone = "(O): " + cstr(self.doc.phone_1) +"\n"+ cstr(self.doc.phone_2) + "\n" + "(M): " + "\n" + "(fax): " + cstr(self.doc.fax_1)
set(self.doc,'telephone',telephone) webnotes.conn.set(self.doc,'telephone',telephone)
# ------------------------------------
# create primary contact for customer
# ------------------------------------
def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr): def create_p_contact(self,nm,phn_no,email_id,mob_no,fax,cont_addr):
c1 = Document('Contact') c1 = Document('Contact')
c1.first_name = nm c1.first_name = nm
@ -126,10 +103,6 @@ class DocType:
c1.customer_group = self.doc.customer_group c1.customer_group = self.doc.customer_group
c1.save(1) c1.save(1)
# ------------------------
# create customer contact
# ------------------------
def create_customer_contact(self): def create_customer_contact(self):
contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name)) contact = sql("select distinct name from `tabContact` where customer_name=%s", (self.doc.customer_name))
contact = contact and contact[0][0] or '' contact = contact and contact[0][0] or ''
@ -143,18 +116,10 @@ class DocType:
c_detail = sql("select lead_name, company_name, contact_no, mobile_no, email_id, fax, address from `tabLead` where name =%s", self.doc.lead_name, as_dict=1) c_detail = sql("select lead_name, company_name, contact_no, mobile_no, email_id, fax, address from `tabLead` where name =%s", self.doc.lead_name, as_dict=1)
self.create_p_contact(c_detail and c_detail[0]['lead_name'] or '', c_detail and c_detail[0]['contact_no'] or '', c_detail and c_detail[0]['email_id'] or '', c_detail and c_detail[0]['mobile_no'] or '', c_detail and c_detail[0]['fax'] or '', c_detail and c_detail[0]['address'] or '') self.create_p_contact(c_detail and c_detail[0]['lead_name'] or '', c_detail and c_detail[0]['contact_no'] or '', c_detail and c_detail[0]['email_id'] or '', c_detail and c_detail[0]['mobile_no'] or '', c_detail and c_detail[0]['fax'] or '', c_detail and c_detail[0]['address'] or '')
# -------------------
# update lead status
# -------------------
def update_lead_status(self): def update_lead_status(self):
if self.doc.lead_name: if self.doc.lead_name:
sql("update `tabLead` set status='Converted' where name = %s", self.doc.lead_name) sql("update `tabLead` set status='Converted' where name = %s", self.doc.lead_name)
# -------------------------------------------------------------------------
# create accont head - in tree under receivables_group of selected company
# -------------------------------------------------------------------------
def create_account_head(self): def create_account_head(self):
if self.doc.company : if self.doc.company :
abbr = self.get_company_abbr() abbr = self.get_company_abbr()
@ -167,15 +132,9 @@ class DocType:
else : else :
msgprint("Please Select Company under which you want to create account head") msgprint("Please Select Company under which you want to create account head")
# ----------------------------------------
# update credit days and limit in account
# ----------------------------------------
def update_credit_days_limit(self): def update_credit_days_limit(self):
sql("update tabAccount set credit_days = '%s', credit_limit = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.credit_limit, self.doc.name + " - " + self.get_company_abbr())) sql("update tabAccount set credit_days = '%s', credit_limit = '%s' where name = '%s'" % (self.doc.credit_days, self.doc.credit_limit, self.doc.name + " - " + self.get_company_abbr()))
#create address and contact from lead
def create_lead_address_contact(self): def create_lead_address_contact(self):
if self.doc.lead_name: if self.doc.lead_name:
details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, phone, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1) details = sql("select name, lead_name, address_line1, address_line2, city, country, state, pincode, phone, mobile_no, fax, email_id from `tabLead` where name = '%s'" %(self.doc.lead_name), as_dict = 1)
@ -211,9 +170,6 @@ class DocType:
except NameError, e: except NameError, e:
pass pass
# ----------
# on update
# ----------
def on_update(self): def on_update(self):
# create customer addr # create customer addr
#self.create_customer_address() #self.create_customer_address()
@ -257,8 +213,6 @@ class DocType:
if self.doc.lead_name: if self.doc.lead_name:
sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name) sql("update `tabLead` set status='Interested' where name=%s",self.doc.lead_name)
# on rename
# ---------
def on_rename(self,newdn,olddn): def on_rename(self,newdn,olddn):
#update customer_name if not naming series #update customer_name if not naming series
if get_defaults().get('cust_master_name') == 'Customer Name': if get_defaults().get('cust_master_name') == 'Customer Name':

View File

@ -2,11 +2,12 @@
{ {
"owner": "Administrator", "owner": "Administrator",
"docstatus": 0, "docstatus": 0,
"creation": "2012-10-02 11:27:30", "creation": "2012-11-02 17:16:46",
"modified_by": "Administrator", "modified_by": "Administrator",
"modified": "2012-09-28 12:31:42" "modified": "2012-11-30 10:54:38"
}, },
{ {
"autoname": "naming_series:",
"name": "__common__", "name": "__common__",
"default_print_format": "Standard", "default_print_format": "Standard",
"allow_print": 0, "allow_print": 0,
@ -34,6 +35,17 @@
"name": "Customer", "name": "Customer",
"doctype": "DocType" "doctype": "DocType"
}, },
{
"description": "Note: You Can Manage Multiple Address or Contacts via Addresses & Contacts",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Basic Info",
"fieldname": "basic_info",
"fieldtype": "Section Break",
"reqd": 0,
"permlevel": 0
},
{ {
"print_hide": 0, "print_hide": 0,
"no_copy": 1, "no_copy": 1,
@ -183,7 +195,6 @@
}, },
{ {
"doctype": "DocField", "doctype": "DocField",
"label": "Communication History",
"fieldname": "communication_history", "fieldname": "communication_history",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"permlevel": 0 "permlevel": 0

View File

@ -73,7 +73,6 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
doc: doc, doc: doc,
email: doc.email_id email: doc.email_id
}) })
} }

View File

@ -15,7 +15,6 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>. // along with this program. If not, see <http://www.gnu.org/licenses/>.
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/support/doctype/communication/communication.js');
cur_frm.cscript.refresh = function(doc, cdt, cdn){ cur_frm.cscript.refresh = function(doc, cdt, cdn){
erpnext.hide_naming_series(); erpnext.hide_naming_series();
@ -26,7 +25,6 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn){
cur_frm.add_custom_button('Opportunity Lost', cur_frm.cscript['Declare Opportunity Lost']); cur_frm.add_custom_button('Opportunity Lost', cur_frm.cscript['Declare Opportunity Lost']);
cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms); cur_frm.add_custom_button('Send SMS', cur_frm.cscript.send_sms);
} }
if(!doc.__islocal) cur_frm.cscript.render_communication_list(doc, cdt, cdn);
} }
// ONLOAD // ONLOAD
@ -48,7 +46,14 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
} }
} }
cur_frm.cscript.make_communication_body(); if(!doc.__islocal) {
cur_frm.communication_view = new wn.views.CommunicationList({
list: wn.model.get("Communication", {"opportunity": doc.name}),
parent: cur_frm.fields_dict.communication_html.wrapper,
doc: doc,
email: doc.contact_email
});
}
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) { if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query; cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;

View File

@ -18,20 +18,14 @@
from __future__ import unicode_literals from __future__ import unicode_literals
import webnotes import webnotes
from webnotes.utils import add_days, add_months, add_years, cint, cstr, date_diff, default_fields, flt, fmt_money, formatdate, 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.utils import add_days, add_years, cint, cstr, date_diff, flt, getdate
from webnotes.model import db_exists from webnotes.model import db_exists
from webnotes.model.doc import Document, addchild, getchildren, make_autoname from webnotes.model.doc import Document, addchild, make_autoname
from webnotes.model.wrapper import getlist, copy_doclist from webnotes.model.wrapper import getlist
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax from webnotes.model.code import get_obj
from webnotes import session, form, msgprint, errprint from webnotes import form, msgprint
set = webnotes.conn.set
sql = webnotes.conn.sql 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 utilities.transaction_base import TransactionBase from utilities.transaction_base import TransactionBase
@ -42,8 +36,8 @@ class DocType(TransactionBase):
self.fname = 'enq_details' self.fname = 'enq_details'
self.tname = 'Opportunity Item' self.tname = 'Opportunity Item'
def autoname(self): def onload(self):
self.doc.name = make_autoname(self.doc.naming_series+'.####') self.add_communication_list()
def get_item_details(self, item_code): def get_item_details(self, item_code):
item = sql("""select item_name, stock_uom, description_html, description, item_group, brand item = sql("""select item_name, stock_uom, description_html, description, item_group, brand
@ -94,8 +88,8 @@ class DocType(TransactionBase):
if self.doc.contact_date and self.doc.contact_date_ref != self.doc.contact_date: if self.doc.contact_date and self.doc.contact_date_ref != self.doc.contact_date:
if self.doc.contact_by: if self.doc.contact_by:
self.add_calendar_event() self.add_calendar_event()
set(self.doc, 'contact_date_ref',self.doc.contact_date) webnotes.conn.set(self.doc, 'contact_date_ref',self.doc.contact_date)
set(self.doc, 'status', 'Draft') webnotes.conn.set(self.doc, 'status', 'Draft')
def add_calendar_event(self): def add_calendar_event(self):
desc='' desc=''
@ -169,7 +163,7 @@ class DocType(TransactionBase):
self.validate_lead_cust() self.validate_lead_cust()
def on_submit(self): def on_submit(self):
set(self.doc, 'status', 'Submitted') webnotes.conn.set(self.doc, 'status', 'Submitted')
def on_cancel(self): def on_cancel(self):
chk = sql("select t1.name from `tabQuotation` t1, `tabQuotation Item` t2 where t2.parent = t1.name and t1.docstatus=1 and (t1.status!='Order Lost' and t1.status!='Cancelled') and t2.prevdoc_docname = %s",self.doc.name) chk = sql("select t1.name from `tabQuotation` t1, `tabQuotation Item` t2 where t2.parent = t1.name and t1.docstatus=1 and (t1.status!='Order Lost' and t1.status!='Cancelled') and t2.prevdoc_docname = %s",self.doc.name)
@ -177,7 +171,7 @@ class DocType(TransactionBase):
msgprint("Quotation No. "+cstr(chk[0][0])+" is submitted against this Opportunity. Thus can not be cancelled.") msgprint("Quotation No. "+cstr(chk[0][0])+" is submitted against this Opportunity. Thus can not be cancelled.")
raise Exception raise Exception
else: else:
set(self.doc, 'status', 'Cancelled') webnotes.conn.set(self.doc, 'status', 'Cancelled')
def declare_enquiry_lost(self,arg): def declare_enquiry_lost(self,arg):
chk = sql("select t1.name from `tabQuotation` t1, `tabQuotation Item` t2 where t2.parent = t1.name and t1.docstatus=1 and (t1.status!='Order Lost' and t1.status!='Cancelled') and t2.prevdoc_docname = %s",self.doc.name) chk = sql("select t1.name from `tabQuotation` t1, `tabQuotation Item` t2 where t2.parent = t1.name and t1.docstatus=1 and (t1.status!='Order Lost' and t1.status!='Cancelled') and t2.prevdoc_docname = %s",self.doc.name)
@ -185,6 +179,6 @@ class DocType(TransactionBase):
msgprint("Quotation No. "+cstr(chk[0][0])+" is submitted against this Opportunity. Thus 'Opportunity Lost' can not be declared against it.") msgprint("Quotation No. "+cstr(chk[0][0])+" is submitted against this Opportunity. Thus 'Opportunity Lost' can not be declared against it.")
raise Exception raise Exception
else: else:
set(self.doc, 'status', 'Opportunity Lost') webnotes.conn.set(self.doc, 'status', 'Opportunity Lost')
set(self.doc, 'order_lost_reason', arg) webnotes.conn.set(self.doc, 'order_lost_reason', arg)
return 'true' return 'true'

View File

@ -2,12 +2,13 @@
{ {
"owner": "Administrator", "owner": "Administrator",
"docstatus": 0, "docstatus": 0,
"creation": "2012-11-28 11:26:19", "creation": "2012-11-24 17:21:44",
"modified_by": "Administrator", "modified_by": "Administrator",
"modified": "2012-11-16 12:27:49" "modified": "2012-11-30 10:54:00"
}, },
{ {
"is_submittable": 1, "is_submittable": 1,
"autoname": "naming_series:",
"name": "__common__", "name": "__common__",
"default_print_format": "Standard", "default_print_format": "Standard",
"search_fields": "status,transaction_date,customer,lead,enquiry_type,territory,company", "search_fields": "status,transaction_date,customer,lead,enquiry_type,territory,company",
@ -34,6 +35,16 @@
"name": "Opportunity", "name": "Opportunity",
"doctype": "DocType" "doctype": "DocType"
}, },
{
"description": "Enter customer enquiry for which you might raise a quotation in future",
"oldfieldtype": "Section Break",
"colour": "White:FFF",
"doctype": "DocField",
"label": "Basic Info",
"fieldname": "basic_info",
"fieldtype": "Section Break",
"permlevel": 0
},
{ {
"description": "To manage multiple series please go to Setup > Manage Series", "description": "To manage multiple series please go to Setup > Manage Series",
"no_copy": 1, "no_copy": 1,
@ -154,15 +165,14 @@
"oldfieldtype": "Section Break", "oldfieldtype": "Section Break",
"colour": "White:FFF", "colour": "White:FFF",
"doctype": "DocField", "doctype": "DocField",
"label": "Communication History",
"fieldname": "communication_history", "fieldname": "communication_history",
"fieldtype": "Section Break", "fieldtype": "Section Break",
"permlevel": 0 "permlevel": 0
}, },
{ {
"allow_on_submit": 1,
"oldfieldtype": "Table", "oldfieldtype": "Table",
"colour": "White:FFF", "colour": "White:FFF",
"allow_on_submit": 1,
"doctype": "DocField", "doctype": "DocField",
"label": "Communication HTML", "label": "Communication HTML",
"oldfieldname": "follow_up", "oldfieldname": "follow_up",

View File

@ -24,8 +24,6 @@ cur_frm.cscript.sales_team_fname = "sales_team";
wn.require('app/selling/doctype/sales_common/sales_common.js'); wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/setup/doctype/notification_control/notification_control.js');
wn.require('app/support/doctype/communication/communication.js');
// ONLOAD // ONLOAD
// =================================================================================== // ===================================================================================
@ -49,7 +47,7 @@ cur_frm.cscript.onload = function(doc, cdt, cdn) {
hide_field(['customer','customer_address','contact_person', 'customer_name','contact_display', 'customer_group']); hide_field(['customer','customer_address','contact_person', 'customer_name','contact_display', 'customer_group']);
} }
} }
cur_frm.cscript.make_communication_body(); //cur_frm.cscript.make_communication_body();
if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) { if(cur_frm.fields_dict.contact_by.df.options.match(/^Profile/)) {
cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query; cur_frm.fields_dict.contact_by.get_query = erpnext.utils.profile_query;
@ -104,7 +102,14 @@ cur_frm.cscript.refresh = function(doc, cdt, cdn) {
if(doc.customer || doc.lead) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true); if(doc.customer || doc.lead) $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(true);
else $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false); else $(cur_frm.fields_dict.contact_section.row.wrapper).toggle(false);
if (!doc.__islocal) cur_frm.cscript.render_communication_list(doc, cdt, cdn); if (!doc.__islocal) {
cur_frm.communication_view = new wn.views.CommunicationList({
list: wn.model.get("Communication", {"quotation": doc.name}),
parent: cur_frm.fields_dict.communication_html.wrapper,
doc: doc,
email: doc.contact_email
});
}
} }
@ -333,9 +338,7 @@ cur_frm.fields_dict['quotation_details'].grid.get_field('item_code').get_query=
} }
cur_frm.cscript.on_submit = function(doc, cdt, cdn) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
var args = { if(cint(wn.boot.notification_settings.quotation)) {
type: 'Quotation', cur_frm.email_doc(wn.boot.notification_settings.quotation_message);
doctype: 'Quotation'
} }
cur_frm.cscript.notify(doc, args);
} }

View File

@ -42,6 +42,9 @@ class DocType(TransactionBase):
self.tname = 'Quotation Item' self.tname = 'Quotation Item'
self.fname = 'quotation_details' self.fname = 'quotation_details'
def onload(self):
self.add_communication_list()
# Pull Opportunity Details # Pull Opportunity Details
# -------------------- # --------------------
def pull_enq_details(self): def pull_enq_details(self):

View File

@ -25,7 +25,6 @@ cur_frm.cscript.sales_team_fname = "sales_team";
wn.require('app/selling/doctype/sales_common/sales_common.js'); wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/setup/doctype/notification_control/notification_control.js');
// ONLOAD // ONLOAD
@ -369,9 +368,7 @@ cur_frm.fields_dict['territory'].get_query = function(doc,cdt,cdn) {
} }
cur_frm.cscript.on_submit = function(doc, cdt, cdn) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
var args = { if(cint(wn.boot.notification_settings.sales_order)) {
type: 'Sales Order', cur_frm.email_doc(wn.boot.notification_settings.sales_order);
doctype: 'Sales Order'
} }
cur_frm.cscript.notify(doc, args);
} }

View File

@ -22,45 +22,5 @@ cur_frm.cscript.select_transaction = function(doc, cdt, cdn) {
refresh_field('custom_message'); refresh_field('custom_message');
} }
$c_obj(make_doclist(cdt, cdn),'get_message',doc.select_transaction, callback) $c_obj(make_doclist(cdt, cdn),'get_message',doc.select_transaction, callback)
} }
}
cur_frm.cscript.notify = function(doc, args) {
var doc = locals[doc.doctype][doc.name];
$c_obj(make_doclist(doc.doctype, doc.name), 'get_formatted_message', {
type: args['type'],
doctype: args['doctype'],
contact_name: args['contact_name'] || doc.contact_display
}, function(r, rt) {
if(!r.exc) {
var res = JSON.parse(r.message);
var send_from = (function() {
if(user!='Administrator') {
return user;
} else {
return (wn.control_panel.auto_email_id ||
'ERPNext Notification<automail@erpnext.com>');
}
})();
if(res.send) {
var print_heading = (doc.select_print_heading || args['type'])
if(validate_email(args['send_to'] || doc.contact_email || '')) {
sendmail(
args['send_to'] || doc.contact_email,
send_from,
send_from,
doc.company + " - " + print_heading + " - " + doc.name,
res.message,
res.print_format
);
msgprint('This ' + print_heading + ' is being sent to <b>'
+ (args['send_to'] || doc.contact_email) + '</b><br />...');
} else {
msgprint('Invalid/Missing Email Address of Contact. Auto notification for '
+ print_heading + ' not sent.');
}
}
}
//console.log(JSON.parse(r.message));
});
} }

View File

@ -25,84 +25,17 @@ from webnotes import msgprint
sql = webnotes.conn.sql sql = webnotes.conn.sql
# -----------------------------------------------------------------------------------------
# Notification control
class DocType: class DocType:
def __init__(self,d,dl): def __init__(self,d,dl):
self.doc, self.doclist = d,dl self.doc, self.doclist = d,dl
# get message to load in custom text
# ----------------------------------
def get_message(self, arg): def get_message(self, arg):
fn = arg.lower().replace(' ', '_') + '_message' fn = arg.lower().replace(' ', '_') + '_message'
v = sql("select value from tabSingles where field=%s and doctype=%s", (fn, 'Notification Control')) v = sql("select value from tabSingles where field=%s and doctype=%s", (fn, 'Notification Control'))
return v and v[0][0] or '' return v and v[0][0] or ''
# set custom text
# ---------------
def set_message(self, arg = ''): def set_message(self, arg = ''):
fn = self.doc.select_transaction.lower().replace(' ', '_') + '_message' fn = self.doc.select_transaction.lower().replace(' ', '_') + '_message'
webnotes.conn.set(self.doc, fn, self.doc.custom_message) webnotes.conn.set(self.doc, fn, self.doc.custom_message)
msgprint("Custom Message for %s updated!" % self.doc.select_transaction) msgprint("Custom Message for %s updated!" % self.doc.select_transaction)
def get_formatted_message(self, args):
"""
args can contain:
* type
* doctype
* contact_name
"""
import json
args = json.loads(args)
res = {
'send': 0,
'message': self.prepare_message(args),
'print_format': self.get_default_print_format(args)
}
dt_small = args.get('doctype').replace(' ', '_').lower()
if cint(self.doc.fields.get(dt_small)):
res['send'] = 1
return json.dumps(res)
def prepare_message(self, args):
"""
Prepares message body
"""
if args.get('type'):
msg_dict = {}
msg_dict['message'] = args.get('message') or self.get_message(args.get('type'))
msg_dict['company'] = Document('Control Panel', 'Control Panel').company_name
msg_dict['salutation'] = "Hi" + (args.get('contact_name') and (" " + args.get('contact_name')) or "")
msg_dict['send_from'] = webnotes.conn.sql("""\
SELECT CONCAT_WS(' ', first_name, last_name)
FROM `tabProfile`
WHERE name = %s""", webnotes.session['user'], as_list=1)[0][0] or ''
return """\
<div>
%(salutation)s,
%(message)s
Thanks,
%(send_from)s
%(company)s
</div>""" % msg_dict
else: return ""
def get_default_print_format(self, args):
"""
Get default print format from doclayer
"""
doclayer = get_obj('Customize Form', 'Customize Form')
doclayer.doc.doc_type = args.get('doctype')
doclayer.get()
if doclayer.doc.default_print_format:
return doclayer.doc.default_print_format
else: return 'Standard'

View File

@ -76,6 +76,8 @@ def boot_session(bootinfo):
import webnotes.model.doctype import webnotes.model.doctype
bootinfo['docs'] += webnotes.model.doctype.get('Event') bootinfo['docs'] += webnotes.model.doctype.get('Event')
bootinfo['docs'] += webnotes.model.doctype.get('Search Criteria') bootinfo['docs'] += webnotes.model.doctype.get('Search Criteria')
bootinfo['notification_settings'] = webnotes.doc("Notification Control",
"Notification Control").get_values()
bootinfo['modules_list'] = webnotes.conn.get_global('modules_list') bootinfo['modules_list'] = webnotes.conn.get_global('modules_list')

View File

@ -23,7 +23,6 @@ cur_frm.cscript.sales_team_fname = "sales_team";
wn.require('app/selling/doctype/sales_common/sales_common.js'); wn.require('app/selling/doctype/sales_common/sales_common.js');
wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/setup/doctype/notification_control/notification_control.js');
// ONLOAD // ONLOAD
// ================================================================================================ // ================================================================================================
@ -327,9 +326,7 @@ cur_frm.pformat.sales_order_no= function(doc, cdt, cdn){
} }
cur_frm.cscript.on_submit = function(doc, cdt, cdn) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
var args = { if(cint(wn.boot.notification_settings.delivery_note)) {
type: 'Delivery Note', cur_frm.email_doc(wn.boot.notification_settings.delivery_note);
doctype: 'Delivery Note'
} }
cur_frm.cscript.notify(doc, args);
} }

View File

@ -21,7 +21,6 @@ cur_frm.cscript.other_fname = "purchase_tax_details";
wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js'); wn.require('app/accounts/doctype/purchase_taxes_and_charges_master/purchase_taxes_and_charges_master.js');
wn.require('app/buying/doctype/purchase_common/purchase_common.js'); wn.require('app/buying/doctype/purchase_common/purchase_common.js');
wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js');
wn.require('app/setup/doctype/notification_control/notification_control.js');
//========================== On Load ================================================================ //========================== On Load ================================================================
cur_frm.cscript.onload = function(doc, cdt, cdn) { cur_frm.cscript.onload = function(doc, cdt, cdn) {
@ -311,9 +310,7 @@ cur_frm.pformat.purchase_order_no = function(doc, cdt, cdn){
} }
cur_frm.cscript.on_submit = function(doc, cdt, cdn) { cur_frm.cscript.on_submit = function(doc, cdt, cdn) {
var args = { if(cint(wn.boot.notification_settings.purchase_receipt)) {
type: 'Purchase Receipt', cur_frm.email_doc(wn.boot.notification_settings.purchase_receipt);
doctype: 'Purchase Receipt'
} }
cur_frm.cscript.notify(doc, args);
} }

View File

@ -238,9 +238,11 @@ class TransactionBase:
return dcc return dcc
def get_formatted_message(self, args): def load_notification_message(self):
""" get formatted message for auto notification""" dt = self.doc.doctype.lower().replace(" ", "_")
return get_obj('Notification Control').get_formatted_message(args) if int(webnotes.conn.get_value("Notification Control", None, dt) or 0):
self.doc.fields["__notification_message"] = \
webnotes.conn.get_value("Notification Control", None, dt + "_message")
def add_communication_list(self): def add_communication_list(self):
# remove communications if present # remove communications if present