From fec3f783af70589b198610fbc29fb00587adb534 Mon Sep 17 00:00:00 2001 From: Nabin Hait Date: Mon, 21 May 2012 14:40:25 +0530 Subject: [PATCH] custom field included in docfield query --- .../doctype/purchase_order/purchase_order.js | 10 - .../attendance_control_panel.py | 156 ++++---- erpnext/selling/doctype/lead/lead.py | 332 ++++++++---------- 3 files changed, 229 insertions(+), 269 deletions(-) diff --git a/erpnext/buying/doctype/purchase_order/purchase_order.js b/erpnext/buying/doctype/purchase_order/purchase_order.js index 559779e13c..c3c3a38560 100644 --- a/erpnext/buying/doctype/purchase_order/purchase_order.js +++ b/erpnext/buying/doctype/purchase_order/purchase_order.js @@ -130,16 +130,6 @@ cur_frm.fields_dict['indent_no'].get_query = function(doc) { return 'SELECT DISTINCT `tabPurchase Request`.`name` FROM `tabPurchase Request` WHERE `tabPurchase Request`.company = "' + doc.company + '" and `tabPurchase Request`.`docstatus` = 1 and `tabPurchase Request`.`status` != "Stopped" and ifnull(`tabPurchase Request`.`per_ordered`,0) < 100 and `tabPurchase Request`.%(key)s LIKE "%s" ORDER BY `tabPurchase Request`.`name` DESC LIMIT 50'; } -/* -//*********** get approved supplier quotation ******************** -cur_frm.fields_dict['supplier_qtn'].get_query = function(doc) { - var cond=''; - if(doc.supplier) cond = 'ifnull(`tabSupplier Quotation`.supplier, "") = "'+doc.supplier+'" and'; - - return repl('SELECT DISTINCT `tabSupplier Quotation`.`name` FROM `tabSupplier Quotation` WHERE `tabSupplier Quotation`.company = "%(company)s" and`tabSupplier Quotation`.`docstatus` = 1 and `tabSupplier Quotation`.`approval_status` = "Approved" and %(cond)s `tabSupplier Quotation`.%(key)s LIKE "%s" ORDER BY `tabSupplier Quotation`.`name` DESC LIMIT 50', {company:doc.company,cond:cond}); -} -*/ - //========================= Get Last Purhase Rate ===================================== cur_frm.cscript.get_last_purchase_rate = function(doc, cdt, cdn){ diff --git a/erpnext/hr/doctype/attendance_control_panel/attendance_control_panel.py b/erpnext/hr/doctype/attendance_control_panel/attendance_control_panel.py index a2105c36cd..6f519424b1 100644 --- a/erpnext/hr/doctype/attendance_control_panel/attendance_control_panel.py +++ b/erpnext/hr/doctype/attendance_control_panel/attendance_control_panel.py @@ -8,11 +8,11 @@ # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. -# +# # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . # Please edit this list and import only required elements import webnotes @@ -34,89 +34,85 @@ convert_to_lists = webnotes.conn.convert_to_lists class DocType: - def __init__(self,d,dt): - self.doc, self.doclist = d,dt - - #========================================================================== - def get_att_list(self): - - lst = [['Attendance','','','Please fill columns which are Mandatory.',' Please do not modify the structure','',''],['','','','','','',''],['[Mandatory]','','[Mandatory]','[Mandatory]','[Mandatory]','[Mandatory]','[Mandatory]'],['Employee','Employee Name','Attendance Date','Status','Fiscal Year','Company','Naming Series']] - - dt = self.date_diff_list() # get date list inbetween from date and to date - - att_dt = self.get_att_data() # get default attendance data like fiscal yr, company, naming series - - fy, comp, sr = att_dt['fy'], att_dt['comp'], att_dt['sr'] - - res = sql("select name, employee_name from `tabEmployee` where status = 'Active' and docstatus !=2") - - for d in dt: - for r in res: - lst.append([r[0],r[1],d,'',fy,comp,sr]) + def __init__(self,d,dt): + self.doc, self.doclist = d,dt + + #========================================================================== + def get_att_list(self): + lst = [['Attendance','','','Please fill columns which are Mandatory.',' Please do not modify the structure','',''],['','','','','','',''],['[Mandatory]','','[Mandatory]','[Mandatory]','[Mandatory]','[Mandatory]','[Mandatory]'],['Employee','Employee Name','Attendance Date','Status','Fiscal Year','Company','Naming Series']] + + dt = self.date_diff_list() # get date list inbetween from date and to date + att_dt = self.get_att_data() # get default attendance data like fiscal yr, company, naming series + + fy, comp, sr = att_dt['fy'], att_dt['comp'], att_dt['sr'] + res = sql("select name, employee_name from `tabEmployee` where status = 'Active' and docstatus !=2") + + for d in dt: + for r in res: + lst.append([r[0],r[1],d,'',fy,comp,sr]) - return lst - - #------------------------------------------------------------------------------ - # get date list inbetween from date and to date - def date_diff_list(self): - import datetime - #get from date - att_fr_date = self.doc.att_fr_date and self.doc.att_fr_date or '' - - #get to date - att_to_date = self.doc.att_to_date and self.doc.att_to_date or '' + return lst + + #------------------------------------------------------------------------------ + # get date list inbetween from date and to date + def date_diff_list(self): + import datetime + #get from date + att_fr_date = self.doc.att_fr_date and self.doc.att_fr_date or '' + + #get to date + att_to_date = self.doc.att_to_date and self.doc.att_to_date or '' - if att_to_date: - r = (getdate(self.doc.att_to_date)+datetime.timedelta(days=1)-getdate(self.doc.att_fr_date)).days - else: - r = 1 - dateList = [getdate(self.doc.att_fr_date)+datetime.timedelta(days=i) for i in range(0,r)] - dt=([str(date) for date in dateList]) - - return dt + if att_to_date: + r = (getdate(self.doc.att_to_date)+datetime.timedelta(days=1)-getdate(self.doc.att_fr_date)).days + else: + r = 1 + dateList = [getdate(self.doc.att_fr_date)+datetime.timedelta(days=i) for i in range(0,r)] + dt=([str(date) for date in dateList]) + + return dt - #------------------------------------------------------------------------------ - def get_att_data(self): - - fy = get_defaults()['fiscal_year'] #get default fiscal year + #------------------------------------------------------------------------------ + def get_att_data(self): + fy = get_defaults()['fiscal_year'] #get default fiscal year + comp = get_defaults()['company'] #get default company + + #get naming series of attendance + import webnotes.model.doctype + docfield = webnotes.model.doctype.get('Attendance') + series = [d.options for d in docfield if d.doctype == 'DocField' and d.fieldname == 'naming_series'] + if not series: + msgprint("Please create naming series for Attendance.\nGo to Setup--> Numbering Series.") + raise Exception + else: + sr = series[0][0] or '' + + return {'fy':fy,'comp':comp,'sr':sr} - comp = get_defaults()['company'] #get default company - - #get naming series of attendance - #sr = sql("select series_options from `tabNaming Series Options` where doc_type='Attendance'") - sr = sql("select options from `tabDocField` where parent = 'Attendance' and fieldname = 'naming_series'") - if not sr: - msgprint("Please create naming series for Attendance.\nGo to Setup--> Manage Series.") - raise Exception - else: - sr = sr and sr[0][0] - - return {'fy':fy,'comp':comp,'sr':sr} + #================================================================================= + def import_att_data(self): + filename = self.doc.file_list.split(',') - #================================================================================= - def import_att_data(self): - filename = self.doc.file_list.split(',') - - if not filename: - msgprint("Please attach a .CSV File.") - raise Exception - - if filename[0].find('.csv') < 0: - raise Exception - - if not filename and filename[0] and file[1]: - msgprint("Please Attach File. ") - raise Exception - - from webnotes.utils import file_manager - fn, content = file_manager.get_file(filename[1]) + if not filename: + msgprint("Please attach a .CSV File.") + raise Exception + + if filename[0].find('.csv') < 0: + raise Exception + + if not filename and filename[0] and file[1]: + msgprint("Please Attach File. ") + raise Exception + + from webnotes.utils import file_manager + fn, content = file_manager.get_file(filename[1]) # NOTE: Don't know why this condition exists - if not isinstance(content, basestring) and hasattr(content, 'tostring'): - content = content.tostring() + if not isinstance(content, basestring) and hasattr(content, 'tostring'): + content = content.tostring() - import webnotes.model.import_docs - im = webnotes.model.import_docs.CSVImport() - out = im.import_csv(content,self.doc.import_date_format, cint(self.doc.overwrite)) - return out + import webnotes.model.import_docs + im = webnotes.model.import_docs.CSVImport() + out = im.import_csv(content,self.doc.import_date_format, cint(self.doc.overwrite)) + return out diff --git a/erpnext/selling/doctype/lead/lead.py b/erpnext/selling/doctype/lead/lead.py index e097a4cfae..4a17a0353f 100644 --- a/erpnext/selling/doctype/lead/lead.py +++ b/erpnext/selling/doctype/lead/lead.py @@ -8,11 +8,11 @@ # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # GNU General Public License for more details. # # You should have received a copy of the GNU General Public License -# along with this program. If not, see . +# along with this program. If not, see . # Please edit this list and import only required elements import webnotes @@ -34,195 +34,169 @@ convert_to_lists = webnotes.conn.convert_to_lists class DocType: - def __init__(self, doc, doclist): - self.doc = doc - self.doclist = doclist - - # Autoname - # --------- - def autoname(self): - self.doc.name = make_autoname(self.doc.naming_series+'.#####') - - #check status of lead - #------------------------ - def check_status(self): - chk = sql("select status from `tabLead` where name=%s", self.doc.name) - chk = chk and chk[0][0] or '' - return cstr(chk) + def __init__(self, doc, doclist): + self.doc = doc + self.doclist = doclist + + # Autoname + # --------- + def autoname(self): + self.doc.name = make_autoname(self.doc.naming_series+'.#####') + + #check status of lead + #------------------------ + def check_status(self): + chk = sql("select status from `tabLead` where name=%s", self.doc.name) + chk = chk and chk[0][0] or '' + return cstr(chk) - # Gets states belonging cto country selected - # ===================================================================== - #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)]) - - # Get item detail (will be removed later) - #======================================= - def get_item_detail(self,item_code): - it=sql("select item_name,brand,item_group,description,stock_uom from `tabItem` where name='%s'"%item_code) - if it: - ret = { - 'item_name' : it and it[0][0] or '', - 'brand' : it and it[0][1] or '', - 'item_group' : it and it[0][2] or '', - 'description': it and it[0][3] or '', - 'uom' : it and it[0][4] or '' - } - return ret - - def validate(self): - import string - # Get Address - # ====================================================================== - #if (self.doc.address_line1) or (self.doc.address_line2) or (self.doc.city) or (self.doc.state) or (self.doc.country) or (self.doc.pincode): - # address =["address_line1", "address_line2", "city", "state", "country", "pincode"] - # comp_address='' - # for d in address: - # if self.doc.fields[d]: - # comp_address += self.doc.fields[d] + "\n" - # if self.doc.website: - # comp_address += "Website : "+ self.doc.website - # self.doc.address = comp_address - - if self.doc.status == 'Lead Lost' and not self.doc.order_lost_reason: - msgprint("Please Enter Quotation Lost Reason") - raise Exception - - if self.doc.source == 'Campaign' and not self.doc.campaign_name and session['user'] != 'Guest': - msgprint("Please specify campaign name") - raise Exception - - if self.doc.email_id: - if not validate_email_add(self.doc.email_id): - msgprint('Please enter valid email id.') - raise Exception - - if not self.doc.naming_series: - if session['user'] == 'Guest': - so = sql("select options from `tabDocField` where parent = 'Lead' and fieldname = 'naming_series'") - #so = sql("select series_options from `tabNaming Series Options` where doc_type='Lead'") - if so: - sr = so[0][0].split("\n") - set(self.doc, 'naming_series', sr[0]) - else: - msgprint("Please specify naming series") - raise Exception - - def on_update(self): - # Add to calendar - # ======================================================================== - if self.doc.contact_by: - self.add_calendar_event() - - if session['user'] == 'Guest': - if self.doc.email_id: - self.send_email_notification() - - if not self.doc.naming_series: - if session['user'] == 'Guest': - #so = sql("select series_options from `tabNaming Series Options` where doc_type='Lead'") - so = sql("select options from `tabDocField` where parent = 'Lead' and fieldname = 'naming_series'") - if so: - sr = so[0][0].split("\n") - set(self.doc, 'naming_series', sr[0]) - else: - msgprint("Please specify naming series") - raise Exception - - def send_email_notification(self): - if not validate_email_add(self.doc.email_id.strip(' ')): - msgprint('error:%s is not a valid email id' % self.doc.email_id.strip(' ')) - raise Exception - else: - subject = 'Thank you for interest in erpnext' - - sendmail([self.doc.email_id.strip(' ')], sender = sender_email[0][0], subject = subject , parts = [['text/html', self.get_notification_msg()]]) - #sendmail(cc_list, sender = sender_email[0][0], subject = subject , parts = [['text/html', message]],attach=attach_list) - msgprint("Mail Sent") - - def get_notification_msg(self): - t = """ - - -Dear %s,

-Thank you for contacting us.

+ # Get item detail (will be removed later) + #======================================= + def get_item_detail(self,item_code): + it=sql("select item_name,brand,item_group,description,stock_uom from `tabItem` where name='%s'"%item_code) + if it: + ret = { + 'item_name' : it and it[0][0] or '', + 'brand' : it and it[0][1] or '', + 'item_group' : it and it[0][2] or '', + 'description': it and it[0][3] or '', + 'uom' : it and it[0][4] or '' + } + return ret + + def validate(self): + import string + if self.doc.status == 'Lead Lost' and not self.doc.order_lost_reason: + msgprint("Please Enter Quotation Lost Reason") + raise Exception + + if self.doc.source == 'Campaign' and not self.doc.campaign_name and session['user'] != 'Guest': + msgprint("Please specify campaign name") + raise Exception + + if self.doc.email_id: + if not validate_email_add(self.doc.email_id): + msgprint('Please enter valid email id.') + raise Exception + + + def on_update(self): + # Add to calendar + # ======================================================================== + if self.doc.contact_by: + self.add_calendar_event() + + if session['user'] == 'Guest': + if self.doc.email_id: + self.send_email_notification() + + if not self.doc.naming_series: + if session['user'] == 'Guest': + import webnotes.model.doctype + docfield = webnotes.model.doctype.get('Lead') + series = [d.options for d in docfield if d.doctype == 'DocField' and d.fieldname == 'naming_series'] + if series: + sr = series[0].split("\n") + set(self.doc, 'naming_series', sr[0]) + else: + msgprint("Please specify naming series") + raise Exception + + def send_email_notification(self): + if not validate_email_add(self.doc.email_id.strip(' ')): + msgprint('error:%s is not a valid email id' % self.doc.email_id.strip(' ')) + raise Exception + else: + subject = 'Thank you for interest in erpnext' + + sendmail([self.doc.email_id.strip(' ')], sender = sender_email[0][0], subject = subject , parts = [['text/html', self.get_notification_msg()]]) + msgprint("Mail Sent") + + def get_notification_msg(self): + t = """ + + + Dear %s,

-You have left following message for us,
-%s -

+ Thank you for contacting us.

-You will receive reply on this shortly.

+ You have left following message for us,
+ %s +

-Cheers! - - -""" % (self.doc.lead_name, self.doc.remark) + You will receive reply on this shortly.

- return t + Cheers! + + + """ % (self.doc.lead_name, self.doc.remark) - # Add to Calendar - # =========================================================================== - def add_calendar_event(self): - # delete any earlier event by this lead - sql("delete from tabEvent where ref_type='Lead' and ref_name=%s", self.doc.name) - - in_calendar_of = self.doc.lead_owner - - # get profile (id) if exists for contact_by - email_id = webnotes.conn.get_value('Sales Person', self.doc.contact_by, 'email_id') - if webnotes.conn.exists('Profile', email_id): - in_calendar_of = email_id - - ev = Document('Event') - ev.owner = in_calendar_of - ev.description = 'Contact ' + cstr(self.doc.lead_name) + '.By : ' + cstr(self.doc.contact_by) + '.To Discuss : ' + cstr(self.doc.remark) - ev.event_date = self.doc.contact_date - ev.event_hour = '10:00' - ev.event_type = 'Private' - ev.ref_type = 'Lead' - ev.ref_name = self.doc.name - ev.save(1) + return t + + # Add to Calendar + # =========================================================================== + def add_calendar_event(self): + # delete any earlier event by this lead + sql("delete from tabEvent where ref_type='Lead' and ref_name=%s", self.doc.name) + + in_calendar_of = self.doc.lead_owner + + # get profile (id) if exists for contact_by + email_id = webnotes.conn.get_value('Sales Person', self.doc.contact_by, 'email_id') + if webnotes.conn.exists('Profile', email_id): + in_calendar_of = email_id + + ev = Document('Event') + ev.owner = in_calendar_of + ev.description = 'Contact ' + cstr(self.doc.lead_name) + '.By : ' + cstr(self.doc.contact_by) + '.To Discuss : ' + cstr(self.doc.remark) + ev.event_date = self.doc.contact_date + ev.event_hour = '10:00' + ev.event_type = 'Private' + ev.ref_type = 'Lead' + ev.ref_name = self.doc.name + ev.save(1) #-----------------Email-------------------------------------------- - def send_emails(self, email=[], subject='', message=''): - if email: - sendmail(email, sender = webnotes.user.name, subject = subject , parts = [['text/html', message]]) - msgprint("Mail Sent") - self.add_in_follow_up(message,'Email') + def send_emails(self, email=[], subject='', message=''): + if email: + sendmail(email, sender = webnotes.user.name, subject = subject , parts = [['text/html', message]]) + msgprint("Mail Sent") + self.add_in_follow_up(message,'Email') -#-------------------------Checking Sent Mails Details---------------------------------------------- - def send_mail(self): - if not self.doc.subject or not self.doc.message: - msgprint("Please enter subject & message in their respective fields.") - elif not self.doc.email_id: - msgprint("Recipient not specified. Please add email id of lead in 'Email id' field provided in 'Contact Info' section.") - raise Exception - else : - self.send_emails([self.doc.email_id.strip(' ')], subject = self.doc.subject ,message = self.doc.message) +#-------------------------Checking Sent Mails Details---------------------------------------------- + def send_mail(self): + if not self.doc.subject or not self.doc.message: + msgprint("Please enter subject & message in their respective fields.") + elif not self.doc.email_id: + msgprint("Recipient not specified. Please add email id of lead in 'Email id' field provided in 'Contact Info' section.") + raise Exception + else : + self.send_emails([self.doc.email_id.strip(' ')], subject = self.doc.subject ,message = self.doc.message) #---------------------- Add details in follow up table---------------- - def add_in_follow_up(self,message,type): - import datetime - child = addchild( self.doc, 'follow_up', 'Communication Log', 1, self.doclist) - child.date = datetime.datetime.now().date().strftime('%Y-%m-%d') - child.notes = message - child.follow_up_type = type - child.save() + def add_in_follow_up(self,message,type): + import datetime + child = addchild( self.doc, 'follow_up', 'Communication Log', 1, self.doclist) + child.date = datetime.datetime.now().date().strftime('%Y-%m-%d') + child.notes = message + child.follow_up_type = type + child.save() #-------------------SMS---------------------------------------------- - def send_sms(self): - if not self.doc.sms_message or not self.doc.mobile_no: - msgprint("Please enter mobile number in Basic Info Section and message in SMS Section ") - raise Exception - else: - receiver_list = [] - if self.doc.mobile_no: - receiver_list.append(self.doc.mobile_no) - for d in getlist(self.doclist,'lead_sms_detail'): - if d.other_mobile_no: - receiver_list.append(d.other_mobile_no) - - if receiver_list: - msgprint(get_obj('SMS Control', 'SMS Control').send_sms(receiver_list, self.doc.sms_message)) - self.add_in_follow_up(self.doc.sms_message,'SMS') + def send_sms(self): + if not self.doc.sms_message or not self.doc.mobile_no: + msgprint("Please enter mobile number in Basic Info Section and message in SMS Section ") + raise Exception + else: + receiver_list = [] + if self.doc.mobile_no: + receiver_list.append(self.doc.mobile_no) + for d in getlist(self.doclist,'lead_sms_detail'): + if d.other_mobile_no: + receiver_list.append(d.other_mobile_no) + + if receiver_list: + msgprint(get_obj('SMS Control', 'SMS Control').send_sms(receiver_list, self.doc.sms_message)) + self.add_in_follow_up(self.doc.sms_message,'SMS')