Example #1
0
	def send(self):
		"""
			* Execute get method
			* Send email to recipients
		"""
		if not self.doc.recipient_list: return

		self.sending = True
		result, email_body = self.get()
		
		recipient_list = self.doc.recipient_list.split("\n")

		# before sending, check if user is disabled or not
		# do not send if disabled
		profile_list = webnotes.conn.sql("SELECT name, enabled FROM tabProfile", as_dict=1)
		for profile in profile_list:
			if profile['name'] in recipient_list and profile['enabled'] == 0:
				del recipient_list[recipient_list.index(profile['name'])]

		from webnotes.utils.email_lib import sendmail
		try:
			#webnotes.msgprint('in send')
			sendmail(
				recipients=recipient_list,
				sender='[email protected]',
				reply_to='[email protected]',
				subject=self.doc.frequency + ' Digest',
				msg=email_body,
				from_defs=1
			)
		except Exception, e:
			webnotes.msgprint('There was a problem in sending your email. Please contact [email protected]')
			webnotes.errprint(webnotes.getTraceback())
Example #2
0
	def sql(self, query, values=(), as_dict = 0, as_list = 0, formatted = 0, 
		debug=0, ignore_ddl=0, as_utf8=0, auto_commit=0, update=None):
		"""
		      * Execute a `query`, with given `values`
		      * returns as a dictionary if as_dict = 1
		      * returns as a list of lists (with cleaned up dates) if as_list = 1
		"""
		# in transaction validations
		self.check_transaction_status(query)
		
		# autocommit
		if auto_commit and self.in_transaction: self.commit()
		if auto_commit: self.begin()
			
		# execute
		try:
			if values!=():
				if isinstance(values, dict):
					values = dict(values)
				if debug: webnotes.errprint(query % values)
				self._cursor.execute(query, values)
				
			else:
				if debug: webnotes.errprint(query)
				self._cursor.execute(query)	
		except Exception, e:
			# ignore data definition errors
			if ignore_ddl and e.args[0] in (1146,1054,1091):
				pass
			else:
				raise e
Example #3
0
def getdoc(doctype, name, user=None):
	"""
	Loads a doclist for a given document. This method is called directly from the client.
	Requries "doctype", "name" as form variables.
	Will also call the "onload" method on the document.
	"""

	import webnotes
	
	if not (doctype and name):
		raise Exception, 'doctype and name required!'
	
	if not name: 
		name = doctype

	if not webnotes.conn.exists(doctype, name):
		return []

	try:
		bean = webnotes.bean(doctype, name)
		bean.run_method("onload")

		doclist = bean.doclist

		# add file list
		set_docinfo(doctype, name)
		
	except Exception, e:
		webnotes.errprint(webnotes.utils.getTraceback())
		webnotes.msgprint('Did not load.')
		raise e
def get_events(start, end, doctype,op,filters=None):
        webnotes.errprint(['hello',doctype, op])
        cnd =''
        if op:
                cnd = "and encounter = '%(pros)s'"%{"pros":op}

        from webnotes.widgets.reportview import build_match_conditions
        #if not webnotes.has_permission("Task"):
        #        webnotes.msgprint(_("No Permission"), raise_exception=1)
        conditions = ''
        # conditions = build_match_conditions("Patient Encounter Entry")
        # conditions and (" and " + conditions) or ""
        
        if filters:
                filters = json.loads(filters)
                for key in filters:
                        if filters[key]:
                                conditions += " and " + key + ' = "' + filters[key].replace('"', '\"') + '"'
        
        data = webnotes.conn.sql("""select name, start_time, end_time, 
                study, status,encounter from `tabPatient Encounter Entry`
                where  ((start_time between '%(start)s' and '%(end)s') \
                        or (end_time between '%(start)s' and '%(end)s')) %(cnd)s 
                %(conditions)s""" % {
                        "start": start,
                        "end": end,
                        "conditions": conditions,
                        "cnd":cnd
                }, as_dict=True, update={"allDay": 0},debug=1)

        return data
        def on_update(self):
                patient_id = None
                from datetime import datetime

                if self.doc.status == 'Canceled':
                        webnotes.conn.sql("update `tabPatient Encounter Entry` set docstatus = '1' where name = '%s'"%(self.doc.name))

                s1=(self.doc.start_time).split(':')
                s2=(self.doc.end_time).split(':')
                # date_a=cstr(datetime.combine(datetime.strptime(self.doc.encounter_date,'%Y-%m-%d').date(),datetime.strptime(s1[0]+":"+s1[1],'%H:%M').time()))
                # date_b=cstr(datetime.combine(datetime.strptime(self.doc.encounter_date,'%Y-%m-%d').date(),datetime.strptime(s2[0]+":"+s2[1],'%H:%M').time()))
                #webnotes.errprint(self.doc.entry_in_child)
                if self.doc.new_user == 1 and not self.doc.new_patient:
                        patient_id = self.make_patient()
                        self.doc.new_patient=patient_id
                        self.create_new_contact()
                        self.create_customer(patient_id)
                        self.create_account_head(patient_id)
                        self.doc.save()
                if self.doc.entry_in_child == 'False':
                        self.make_child_entry(patient_id)
                        #self.make_event()

                if not self.doc.eventid:
                        self.create_child()
                else:
                        webnotes.conn.sql("update `tabSlot Child` set slot='"+self.doc.appointment_slot+"', start_time='"+cstr(datetime.strptime(date_a,'%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M'))+"', end_time='"+cstr(datetime.strptime(date_b,'%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M'))+"' where encounter='"+self.doc.name+"'")
                        webnotes.errprint(date_a)
                        webnotes.conn.sql("update `tabEvent` set starts_on='"+cstr(datetime.strptime(date_a,'%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M'))+"', ends_on='"+cstr(datetime.strptime(date_b,'%Y-%m-%d %H:%M:%S').strftime('%Y-%m-%d %H:%M'))+"' where name='"+self.doc.eventid+"'",debug=1)

                if cint(self.doc.checked_in)==1: pass
Example #6
0
 def create_receiver_list(self):
   rec, where_clause = '', ''   
   if self.doc.cus == 'All Customer Contact':
     where_clause = self.doc.customer and " and customer = '%s'" % self.doc.customer or " and ifnull(is_customer, 0) = 1"
   if self.doc.cus == 'All Supplier Contact':
     where_clause = self.doc.supplier and "  and supplier = '%s'" % self.doc.supplier or " and ifnull(is_supplier, 0) = 1"
   if self.doc.cus == 'All Sales Partner Contact':
     where_clause = self.doc.sales_partner and "  and sales_partner = '%s'" % self.doc.sales_partner or " and ifnull(is_sales_partner, 0) = 1"
   if self.doc.cus in ['All Customer Contact', 'All Supplier Contact', 'All Sales Partner Contact']:
     rec = sql("select CONCAT(ifnull(first_name,''),' ',ifnull(last_name,'')), mobile_no from `tabContact` where ifnull(mobile_no,'')!='' and docstatus != 2 %s" % where_clause)
   elif self.doc.cus == 'All Lead (Open)':
     rec = sql("select lead_name, mobile_no from tabLead where ifnull(mobile_no,'')!='' and docstatus != 2 and status = 'Open'")
   elif self.doc.cus == 'All Employee (Active)':
     where_clause = self.doc.department and " and department = '%s'" % self.doc.department or ""
     where_clause += self.doc.branch and " and branch = '%s'" % self.doc.branch or ""
     rec = sql("select employee_name, cell_number from `tabEmployee` where status = 'Active' and docstatus < 2 and ifnull(cell_number,'')!='' %s" % where_clause)
   elif self.doc.cus == 'All Sales Person':
     rec = sql("select sales_person_name, mobile_no from `tabSales Person` where docstatus != 2 and ifnull(mobile_no,'')!=''")
   elif self.doc.cus == 'All Contact':
     rec = sql("select first_name,mobile_no from `tabContact` where ifnull(mobile_no,'')!=''")
   else:
     rec=sql("select cont_name,ph_no from `tabSub Contact` where parent='"+self.doc.cus+"'")
   rec_list = ''
   for d in rec:
     rec_list += d[0] + ' - ' + d[1] + '\n'
   self.doc.receiver_list = rec_list
   webnotes.errprint(rec_list)