here I want to send sms from odoo to mobile number. Here I want to create a form and after creating a form a message will sent to selected restaurant number. But sms not sending. please help me.
def get_api_key(self, url='', username='', password=''):
if not url:
url = 'http://bulksms.skill.jobs/getkey'
if not username:
username = 'C2006884'
if not password:
password = ''
r = requests.get(url="{url}/{username}/{password}".format(url=url, username=username, password=password))
api_key = r.text.split(':')[1]
print(api_key)
return api_key
def send_sms(self, mobile, message, api_endpoint='', senderid=''):
if not api_endpoint:
api_endpoint = "http://bulksms.skill.jobs/smsapi"
if not senderid:
senderid = "8809612436715"
params = {
"api_key": self.get_api_key(),
"type": "text",
"contacts": mobile.replace('+', ''),
"senderid": senderid,
"msg": message
}
r = requests.post(url=api_endpoint, data=params)
print(r)
print(params)
@api.model
def create(self, vals):
rec = super(FoodReservation, self).create(vals)
mobile = rec.restaurant_id.mobile
message = "{customer_name} has sent a reservation in {restaurant_name} on {date_and_time}. Please call {customer_mobile} for further info.".format(
customer_name=rec.customer_id.name,
restaurant_name=rec.restaurant_id.name,
date_and_time=rec.time.strftime("%d %B %Y at %I:%M:%S %p"),
customer_mobile=rec.customer_id.mobile,
)
# message = "Hello!!! You\'ve received a reservation from {customer_name}.".format(customer_name=rec.customer_id.name)
if mobile:
mobile = mobile.replace('+', '')
sms_val = {
'sms_type': 'text',
'contacts': mobile,
'message': message,
'auto_delete': True
}
sms_obj = self.env['skill_jobs.sms'].sudo().create(sms_val)
send_sms = sms_obj.send()
self.send_sms(
mobile=mobile.replace('+', ''),
message=message
)
return rec
This question has been flagged
1175
Views
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up