diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2023-02-20 09:52:42 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2023-02-20 09:52:42 +0700 |
| commit | 1b53c0081b925e54e056c94b355a9b99320e0ea5 (patch) | |
| tree | 74a20d5a5efdeb23a779adc340681718f697d7b9 /indoteknik_custom/models/wati.py | |
| parent | ce3e018ad61808b7e581e416525e6696ed088916 (diff) | |
| parent | 4a7d62d40a47ae894e2e22171105332ada9516ee (diff) | |
Merge branch 'midtrans' into staging
Diffstat (limited to 'indoteknik_custom/models/wati.py')
| -rw-r--r-- | indoteknik_custom/models/wati.py | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py new file mode 100644 index 00000000..e2e723ef --- /dev/null +++ b/indoteknik_custom/models/wati.py @@ -0,0 +1,77 @@ +from odoo import fields, models, api +import logging +import json + +_logger = logging.getLogger(__name__) + + +class WatiNotification(models.Model): + _name = 'wati.notification' + + json_raw = fields.Char(string='JSON Raw Text') + is_lead = fields.Boolean(string='To Leads', help='apakah sudah ter-convert jadi leads') + + def _convert_to_leads(self): + query = [ + ('is_lead', '=', False) + ] + watis = self.env['wati.notification'].search(query, order='id') + + for wati in watis: + _logger.info('Convert to Lead WATI Notification ID %s' % wati.id) + ticket_id = json.loads(wati.json_raw)['ticketId'] + text = json.loads(wati.json_raw)['text'] + + current_lead = self.env['crm.lead'].search([('ticket_id', '=', ticket_id)], limit=1) + operator_email = json.loads(wati.json_raw)['operatorEmail'] + operator_name = json.loads(wati.json_raw)['operatorName'] + event_type = json.loads(wati.json_raw)['eventType'] + + if event_type == 'sessionMessageSent': + if 'Saya *Eko*' in str(text): + sales = 11 + elif 'Saya *Nabila*' in str(text): + sales = 20 + elif 'Saya *Novita*' in str(text): + sales = 377 + elif 'Saya *Putri*' in str(text): + sales = 10 + elif 'Saya *Heriyanto*' in str(text): + sales = 375 + elif 'Saya *Ade*' in str(text): + sales = 9 + elif 'Saya *Adela*' in str(text): + sales = 8 + elif 'Saya *Jananto*' in str(text): + sales = 376 + elif 'Saya *Dwi*' in str(text): + sales = 24 + else: + sales = 25 #System + current_lead.description = str(current_lead.description)+ "| i:" + str(text) + current_lead.operator_email = operator_email + current_lead.operator_name = operator_name + current_lead.user_id = sales + wati.is_lead = True + elif current_lead: + # must append internal notes as a reply here + current_lead.description = str(current_lead.description) + " | c:" +str(text) + current_lead.operator_email = operator_email + current_lead.operator_name = operator_name + wati.is_lead = True + else: + # create new leads + contact_name = json.loads(wati.json_raw)['senderName'] + phone = json.loads(wati.json_raw)['waId'] + name = 'Ada pesan dari WATI '+str(phone)+' '+str(contact_name) + + self.env['crm.lead'].create([{ + 'name': name, + 'ticket_id': ticket_id, + 'operator_email': operator_email, + 'operator_name': operator_name, + 'contact_name': contact_name, + 'phone': phone, + 'description': "c:" +str(text) + }]) + wati.is_lead = True |
