def validate(self): cs = frappe.get_doc("Class Schedule", self.class_slot) if self.booked == "No": if self.status == "Seat Reserved": cs.occupancy = cs.occupancy - 1 self.booked = "Yes" if self.booked == "Yes": if self.status == "Cancel": cs.occupancy = cs.occupancy + 1 self.booked = "No" cs.title = str(cs.from_time) + ' / R: ' + str(cs.occupancy) cs.class_title = str(cs.from_time) + '/' + str( cs.session_type) + '/' + str(cs.language) + '/ R: ' + str( cs.occupancy) cs.save() if self.registration: reg = frappe.get_doc("Registration", self.registration) reg.status = "Appointed" rlist = [] rlist.append(reg.telephone_no) send_sms( rlist, "Appointment fixed for " + self.schedule_date + " at " + self.time, "Cambridge") reg.appointment_status = self.status reg.save()
def send_message(self): from frappe.core.doctype.sms_settings.sms_settings import send_sms if not self.lr_no: frappe.msgprint(_("Please update LR No and then try sending sms")) self.send_message = 0 self.save() frappe.db.commit() return if not self.contact_mobile: frappe.msgprint(_("No mobile number found, so message not sent")) return message = """Snehraj Notebook Industries {customer} {city_name} Challan Number: {name} LR Number: {lr_no} """.format(customer=self.customer, city_name=self.city_name or '', name=self.name, lr_no=self.lr_no) numbers = self.contact_mobile.split(",") send_sms(numbers, message)
def send_followup_sms(opportunity, method): def validate_number(number_list): validated_number_list = [] for n in number_list: if '03' == n[:2]: n = '92' + n[1:] if '923' != n[:3] or len(n) != 12: frappe.throw( _("Phone Number is not Valid to Send SMS in Follow Up Table. Please Check number again." )) validated_number_list.append(n) return validated_number_list for d in opportunity.followup: if d.send_message and not d.message_sent and len(d.sms_message) > 10: if not d.sms_message and d.send_message: frappe.throw( _("Please set SMS Message Row no {0}").format(d.idx)) number_list = [] if d.owner_sms_cell: number_list.append(d.owner_sms_cell) if d.architect_sms_cell: number_list.append(d.architect_sms_cell) if d.contractor_cell_no: number_list.append(d.contractor_cell_no) if number_list: if len(d.sms_message) > 305: frappe.throw( _("Message Length should be less than 2 Messages (305 characters) ." )) number_list = validate_number(set(number_list)) send_sms(number_list, cstr(d.sms_message), opportunity.company) d.message_sent = 1 d.db_update()
def sms_for_morning_delay(self): from frappe.core.doctype.sms_settings.sms_settings import send_sms sending_sms_for_morning_delay = frappe.db.get_value( "HR Settings", None, "sending_sms_for_morning_delay") if sending_sms_for_morning_delay and sending_sms_for_morning_delay == '1': mobile = frappe.db.get_value("HR Settings", None, "manager_phone_number") if mobile and mobile != '0': if len(mobile) < 14: frappe.msgprint(_("Mobile number is not valid")) else: context = {"doc": self, "alert": self, "comments": None} #if self.get("_comments"): # context["comments"] = json.loads(self.get("_comments")) messages = self.employee_name + _( " has a late attendance today. His attendance is at {0}, and the delay for about {1}" ).format(self.from_date, self.late_diff) messages = frappe.render_template(messages, context) number = [mobile] send_sms(number, messages) else: frappe.msgprint( _("No mobile number to send SMS, PLZ check it from HR Settings" ))
def send_sms_for_appointment(self): receiver_list = [] receiver_list.append(self.phone) if receiver_list: message=f"Your Appointment is booked {self.clinic_address} at {getdate(self.schedule_date).strftime('%d-%m-%Y %H:%M:%S')}. For Navigation {self.clinic_map} " send_sms(receiver_list, cstr(message)) create_communication(self)
def send_feedback(self): amazon_mws_feedback_settings = frappe.get_doc( 'Amazon MWS Feedback Settings') feedback_base_url = amazon_mws_feedback_settings.feedback_base_url number_of_reminders = amazon_mws_feedback_settings.number_of_reminders customer_name = self.customer_name delivery_date = self.delivery_date todays_date = datetime.date.today() date_difference = (todays_date - delivery_date).days if date_difference < 1: return phone = self.phone order_id = self.order_id is_send_sms = self.send_sms number_of_sent_sms = self.number_of_sent_sms final_url = feedback_base_url + order_id if not feedback_base_url: frappe.throw('Base Url is Empty') if number_of_sent_sms < number_of_reminders and is_send_sms == 'Yes': from frappe.core.doctype.sms_settings.sms_settings import send_sms message_sms = """Hi {0},\n\nThanks for Shopping with Everyday Kitchen on Amazon.\n\nPlease share your feedback by clicking on {1}\n\nTeam Everyday Kitchen""".format( customer_name, final_url) try: send_sms([phone], message_sms) self.number_of_sent_sms = number_of_sent_sms + 1 self.save() except: pass
def process(doc, method): sms_template = frappe.db.exists( "SMS Template", {"disabled": 0, "ref_doctype": doc.doctype, "event": method, "auto_trigger": 1}, ) if not sms_template: return template = frappe.get_doc("SMS Template", sms_template) if not _allowed(template.condition, doc): return try: number = _get_number(template.num_field, doc) text = _get_content(template.content, doc) # fix for json.loads casting to int during number validation send_sms('"{}"'.format(number), text) if template.save_com: _make_communication( { "subject": "SMS: {} to {}".format(template.template_name, number), "reference_doctype": doc.doctype, "reference_name": doc.name, "phone_no": number, "content": text, } ) except Exception: frappe.log_error(frappe.get_traceback())
def send_payment_sms(self): sms_settings = frappe.get_doc('SMS Settings') if sms_settings.sms_gateway_url: msg = 'Dear ' msg += self.guest_name msg += ''',\nWe are delighted that you have selected our hotel. The entire team at the Hotel PakHeritage welcomes you and trust your stay with us will be both enjoyable and comfortable.\nRegards,\nHotel Management''' send_sms([self.contact_no], msg=msg)
def send_sms(self): receiver_list = [] if not self.message: msgprint(_("Please enter message before sending")) else: receiver_list = self.get_receiver_nos() if receiver_list: send_sms(receiver_list, cstr(self.message))
def send_pos_sms(doc, method): if doc.is_pos and doc.contact_mobile: prime_settings = frappe.get_doc('Prime Settings') pos_sms_msg = prime_settings.pos_sms_text context = {"doc": doc} message = frappe.render_template(pos_sms_msg, context) numbers = [doc.contact_mobile] send_sms(numbers, message)
def send_sms_msg(self, doc, context): space = "\n" message= frappe.render_template(self.subject, context) +space message= message + frappe.render_template(self.message, context) recipients_no_list = self.get_recipients_no_list() send_sms( receiver_list = recipients_no_list, msg = message, )
def send_payment_sms(self): sms_settings = frappe.get_doc('SMS Settings') if sms_settings.sms_gateway_url: msg = 'Dear ' msg += self.guest_name msg += ',\nThank you for your payment. Amount received PKR ' msg += str(self.amount_paid) msg += ' on ' msg += str(self.posting_date) send_sms([self.contact_no], msg=msg)
def send_message(doc, message): patient = frappe.get_doc("Patient", doc.patient) if (patient.mobile): context = {"doc": doc, "alert": doc, "comments": None} if doc.get("_comments"): context["comments"] = json.loads(doc.get("_comments")) #jinja to string convertion happens here message = frappe.render_template(message, context) number = [patient.mobile] send_sms(number, message)
def send_referrer_sms(doc, method): referrer_name = doc.referrer_name referrer_phone_no = doc.referrer_phone_no if referrer_name and referrer_phone_no: oralcare_settings = frappe.get_doc('Oralcare Settings') referrer_sms_message = oralcare_settings.referrer_sms context = {"doc": doc} message = frappe.render_template(referrer_sms_message, context) numbers = [referrer_phone_no] send_sms(numbers, message)
def customer_sms(doc, method): customer = doc.customer contact_mobile = doc.contact_mobile if customer and contact_mobile and doc.is_pos == 1: prime_sms = frappe.get_doc('SMS Prime') customer_sms_message = prime_sms.customer_sms context = {"doc": doc} msg = frappe.render_template(customer_sms_message, context) mobno = [contact_mobile] send_sms(mobno, msg)
def send_sms_msg(self, doc, context): space = "\n" message = frappe.render_template(self.subject, context) + space message = message + frappe.render_template(self.message, context) recipients_no_list = self.get_recipients_no_list() recipients_no_list.extend(self.get_dynamic_recipients(doc)) if validate_sms_settings(): send_sms( receiver_list=recipients_no_list, msg=message, )
def send_message(doc, message): patient = frappe.get_doc("Patient", doc.patient) if patient.mobile: context = {"doc": doc, "alert": doc, "comments": None} if doc.get("_comments"): context["comments"] = json.loads(doc.get("_comments")) # jinja to string convertion happens here message = frappe.render_template(message, context) number = [patient.mobile] send_sms(number, message)
def send_doctors_sms(doc, method): practitioner = doc.practitioner if practitioner: doctor = frappe.get_doc('Healthcare Practitioner', practitioner) if doctor and doctor.mobile_phone: oralcare_settings = frappe.get_doc('Oralcare Settings') doc_sms_message = oralcare_settings.doc_appointment_sms context = {"doc": doc} message = frappe.render_template(doc_sms_message, context) numbers = [doctor.mobile_phone] send_sms(numbers, message)
def send_message(self): receiver_list = [] if not self.message: msgprint(_("Please enter message before sending")) else: receiver_list = self.get_receiver_nos() if not receiver_list: return if self.type == "SMS": send_sms(receiver_list, cstr(self.message)) elif self.type == "Whatsapp": send_whatsapp(receiver_list, cstr(self.message))
def send_registration_sms(doc): if (frappe.db.get_value("Healthcare Settings", None, "reg_sms")=='1'): if doc.mobile: context = {"doc": doc, "alert": doc, "comments": None} if doc.get("_comments"): context["comments"] = json.loads(doc.get("_comments")) messages = frappe.db.get_value("Healthcare Settings", None, "reg_msg") messages = frappe.render_template(messages, context) number = [doc.mobile] send_sms(number,messages) else: frappe.msgprint(doc.name + " Has no mobile number to send registration SMS", alert=True)
def after_insert(self): from frappe.core.doctype.sms_settings.sms_settings import send_sms try: name = self.customer min_people = self.min_people date = self.date booking_type = self.booking_type message = 'Hi, {0}. Your booking for {1} at Cafe 1730, Kharadi on {2} is confirmed for minimum {3} people'.format( name, booking_type, date, min_people) contact = frappe.get_doc('Contact', name) send_sms([contact.phone, contact.mobile_no], message, 'ALERTS') except: pass
def send_message(doc, message): patient_mobile = frappe.db.get_value('Patient', doc.patient, 'mobile') if patient_mobile: context = {'doc': doc, 'alert': doc, 'comments': None} if doc.get('_comments'): context['comments'] = json.loads(doc.get('_comments')) # jinja to string convertion happens here message = frappe.render_template(message, context) number = [patient_mobile] try: send_sms(number, message) except Exception as e: frappe.msgprint(_('SMS not sent, please check SMS Settings'), alert=True)
def send_message(doc, message): patient_mobile = frappe.db.get_value("Patient", doc.patient, "mobile") if patient_mobile: context = {"doc": doc, "alert": doc, "comments": None} if doc.get("_comments"): context["comments"] = json.loads(doc.get("_comments")) # jinja to string convertion happens here message = frappe.render_template(message, context) number = [patient_mobile] try: send_sms(number, message) except Exception as e: frappe.msgprint(_("SMS not sent, please check SMS Settings"), alert=True)
def send_contractorwise_att(): get_numbers = frappe.db.get_single_value("Starbox settings", "sms_numbers") numbers = [] for n in get_numbers.split('\n'): numbers.append(n) day = add_days(today(), -1) query = """select contractor as Contractor,count(*) as Count from `tabAttendance` where attendance_date = '%s' and employment_type="Contract" group by contractor""" % day att = frappe.db.sql(query, as_dict=1) # if att: message = "CONTRACTORWISE EMPLOYEES PRESENT COUNT - %s\n " % frappe.utils.formatdate( day) for at in att: message += "%(Contractor)s : %(Count)s\n" % at number = numbers send_sms(number, message)
def send_registration_sms(doc): if frappe.db.get_single_value('Healthcare Settings', 'send_registration_msg'): if doc.mobile: context = {'doc': doc, 'alert': doc, 'comments': None} if doc.get('_comments'): context['comments'] = json.loads(doc.get('_comments')) messages = frappe.db.get_single_value('Healthcare Settings', 'registration_msg') messages = frappe.render_template(messages, context) number = [doc.mobile] send_sms(number, messages) else: frappe.msgprint(doc.name + ' has no mobile number to send registration SMS', alert=True)
def send_user_otp(mobile=None, user=None): try: '''Authenticate using otp.''' from frappe.twofactor import (should_run_2fa, authenticate_for_2factor,get_otpsecret_for_, confirm_otp_token, send_token_via_sms, send_token_via_email) import pyotp, os if mobile: user = frappe.db.get_value('User', {"mobile_no":mobile},'name') recipients = [] recipients = recipients + mobile.split("\n") recipients = list(set(recipients)) otp_secret = get_otpsecret_for_(user) token = int(pyotp.TOTP(otp_secret).now()) hotp = pyotp.HOTP(otp_secret) otp = hotp.at(int(token)) frappe.log_error(otp, "userverification") # otp_issuer="INGC" message = 'Your verification code is {otp}'.format(otp=otp) status = send_sms(recipients, message) verification_obj = { 'token_delivery': status, 'prompt': status and 'Enter verification code sent to {}'.format(mobile[:4] + '******' + mobile[-3:]), "user": user, "tmp_id":token } return verification_obj except Exception as e: frappe.log_error(frappe.get_traceback(), "myjobpro.api.send_user_otp")
def send_present_alert(employee, name, in_time,date,out_time): recipients = frappe.get_value("Employee", employee, "cell_number") if recipients: if not in_time: in_time ="NIL" if not out_time: out_time = "NIL" message="""Attendance Alert for %s Dear %s, Info: In Time:%s Out Time:%s ESE ERP""" % (formatdate(date),name, in_time,out_time) rcv = [] rcv.append(recipients) sender = 'ESE ERP SYS' send_sms(rcv, message,sender_name=sender)
def after_insert(self): from frappe.core.doctype.sms_settings.sms_settings import send_sms if self.book_done_by == 'Backend': booking = self recepient = [booking.email] subject = "Cafe 1730, New Year Booking Confirmation" message = "Thanks for Booking" message_sms = "" booking_for = booking.booking_for name = booking.name1 phone = booking.mobile people = booking.people kids = booking.kids couple = booking.couple male_stag = booking.male_stag female_stag = booking.female_stag booking_code = booking.name total = booking.total_amount total_advance = booking.total_advance subject = 'Cafe 1730, {0} Confirmation'.format(booking_for) if booking_for == "New Year 2019 Party on 31st December": message = """<p>Hi {0},</p><p>Thanks for Booking {1} at Cafe 1730, Kharadi. Details of your booking is as follows.</p> Name: {2}<br>Phone: {3}<br>Number of Couple: {4}<br>Number of Female Stag: {5}<br>Number of Male Stag: {6}<br>Number of Kids: {7}<br>Total Amount: {8}<br>Advance Received: {9}<p>Your booking code is {10}, please show this to the staff when you reach at the Cafe.</p><p>Thanks,<br>Team Cafe 1730<br>7410000195.</p>""".format( name, booking_for, name, phone, couple, female_stag, male_stag, kids, total, total_advance, booking_code) message_sms = """Hi {0}\n\nThanks for Booking {1} at Cafe 1730, Kharadi.\n\nDetails of your booking is as follows.\n\nName: {2}\nPhone: {3}\nNumber of Couple: {4}\nNumber of Female Stag: {5}\nNumber of Male Stag: {6}\nNumber of Kids: {7}\nTotal Amount: {8}\nAdvance Received: {9}\n\nYour booking code is {10}\n\nPlease show this to the staff when you reach at the Cafe.\n\nThanks,\nTeam Cafe 1730,\n+91-7410000195.""".format( name, booking_for, name, phone, couple, female_stag, male_stag, kids, total, total_advance, booking_code) else: message = """<p>Hi {0},</p><p>Thanks for Booking {1} at Cafe 1730, Kharadi. Details of your booking is as follows.</p> Name: {2}<br>Phone: {3}<br>Number of People: {4}<br>Total Amount: {5}<br>Advance Received: {6}<p>Your booking code is {7}, please show this to the staff when you reach at the Cafe.</p><p>Thanks,<br>Team Cafe 1730<br>7410000195.</p>""".format( name, booking_for, name, phone, people, total, total_advance, booking_code) message_sms = """Hi {0},\n\nThanks for Booking {1} at Cafe 1730, Kharadi.\n\nDetails of your booking is as follows.\n\nName: {2}\nPhone: {3}\nNumber of People: {4}\nTotal Amount: {5}\nAdvance Received: {6}\n\nYour booking code is {7}\n\nPlease show this to the staff when you reach at the Cafe.\n\nThanks,\nTeam Cafe 1730,\n+91-7410000195.""".format( name, booking_for, name, phone, people, total, total_advance, booking_code) frappe.sendmail(recipients=recepient, subject=subject, message=message) try: send_sms([phone], message_sms, 'ALERTS') except: pass
def initiate_pwd_reset(): email = frappe.form_dict.get('email') if email and frappe.db.exists('User', email): authenticate_for_2factor(email) phone = get_phone_no(email) if phone: tmp_id = frappe.local.response['tmp_id'] otp_secret = frappe.cache().get(tmp_id + '_otp_secret') token = frappe.cache().get(tmp_id + '_token') # Surprisingly following 2FA method is not working # status = send_token_via_sms(otp_secret, token=token, phone_no=phone) from frappe.core.doctype.sms_settings.sms_settings import send_sms hotp = pyotp.HOTP(otp_secret) msg = 'Your verification code is {}'.format(hotp.at(int(token))) send_sms([cstr(phone)], msg) frappe.db.commit() else: raise frappe.PermissionError("User does not exist")
def send_membership_creation_renewal_sms(self,notification_name,args=None): if frappe.db.exists('SMS Notification',notification_name): alert = frappe.get_doc('SMS Notification',notification_name) if alert.enabled==1: doc=frappe.get_doc(self.doctype,self.name) context = get_context(doc) context = {"doc": doc, "alert": alert, "comments": None} msg=frappe.render_template(alert.message,context) if args !=None: msg=frappe.render_template(msg, args) print(alert.get_receiver_list(doc, context),len(alert.get_receiver_list(doc, context))) receiver_list=list(filter(None,alert.get_receiver_list(doc, context))) if len(receiver_list)>0: send_sms( receiver_list=receiver_list, msg=msg ) print('msg sent',alert.get_receiver_list(doc, context),msg)
def send_sms_for_appointment(self): receiver_list = [] receiver_list.append( frappe.db.get_value("Lead", self.party_name, "phone")) if receiver_list: # if self.schedule_date: address = self.clinic_address[12:] address = address.replace("</strong></h1>", "") if self.schedule_date: message = f"Your Appointment is booked {address} at {self.schedule_date}. For Navigation {self.clinic_map} " self.create_appointment() subject = "Appointment Booked" else: message = f"Clinic Address is {address} . For Navigation {self.clinic_map} " subject = "Clinic Address" send_sms(receiver_list, cstr(message)) for i in receiver_list: self.create_communication(subject, i, message)