From 57b12c36df829ab358a68a5356c3549cf9714900 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 16 Feb 2023 13:49:18 +0700 Subject: add wati notification handle --- indoteknik_custom/models/wati.py | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 indoteknik_custom/models/wati.py (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py new file mode 100644 index 00000000..f9ab6df2 --- /dev/null +++ b/indoteknik_custom/models/wati.py @@ -0,0 +1,11 @@ +from odoo import fields, models, api +import logging + +_logger = logging.getLogger(__name__) + + +class WatiNotification(models.Model): + _name = 'wati.notification' + + json_raw = fields.Char(string='JSON Raw Text') + -- cgit v1.2.3 From 5413d6ae243fc2c9dd37930097928d51ef961aaa Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 16 Feb 2023 14:44:57 +0700 Subject: convert wati to leads --- indoteknik_custom/models/wati.py | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index f9ab6df2..57ba9a4a 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -1,5 +1,6 @@ from odoo import fields, models, api import logging +import json _logger = logging.getLogger(__name__) @@ -8,4 +9,39 @@ 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: + 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'] + + if current_lead: + # must append internal notes as a reply here + current_lead.description = current_lead.description + "|" +text + 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 '+phone+' '+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': text + }]) + wati.is_lead = True -- cgit v1.2.3 From aeb50c4ede78b7f101c5ccf7a63a2fb81ec3aae0 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 16 Feb 2023 14:52:01 +0700 Subject: bug fix wati to leads --- indoteknik_custom/models/wati.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index 57ba9a4a..0a4da9e1 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -18,6 +18,7 @@ class WatiNotification(models.Model): watis = self.env['wati.notification'].search(query, order='id') for wati in watis: + _logger.info('Convert Lead ID %s' % wati.id) ticket_id = json.loads(wati.json_raw)['ticketId'] text = json.loads(wati.json_raw)['text'] @@ -27,13 +28,13 @@ class WatiNotification(models.Model): if current_lead: # must append internal notes as a reply here - current_lead.description = current_lead.description + "|" +text + current_lead.description = current_lead.description + "|" +str(text) 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 '+phone+' '+contact_name + name = 'Ada pesan dari WATI '+str(phone)+' '+str(contact_name) self.env['crm.lead'].create([{ 'name': name, -- cgit v1.2.3 From dc44e019784e18f34bb84a86640793efd3daca17 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 16 Feb 2023 15:13:53 +0700 Subject: bug fix wati --- indoteknik_custom/models/wati.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index 0a4da9e1..37c97f59 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -28,7 +28,7 @@ class WatiNotification(models.Model): if current_lead: # must append internal notes as a reply here - current_lead.description = current_lead.description + "|" +str(text) + current_lead.description = str(current_lead.description) + "|" +str(text) wati.is_lead = True else: # create new leads -- cgit v1.2.3 From a400a6b71bdd0ec77c9a053088c0024a2aadfaff Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Thu, 16 Feb 2023 16:51:43 +0700 Subject: add operator and name in wait leads --- indoteknik_custom/models/wati.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index 37c97f59..fbe350a5 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -29,6 +29,8 @@ class WatiNotification(models.Model): if current_lead: # must append internal notes as a reply here current_lead.description = str(current_lead.description) + "|" +str(text) + current_lead.operator_email = operator_email + current_lead.operator_name = operator_name wati.is_lead = True else: # create new leads -- cgit v1.2.3 From 37e33dfc0f0f79f67aa600c13e2e134037005f45 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 17 Feb 2023 09:26:35 +0700 Subject: add message sent in wati leads --- indoteknik_custom/models/wati.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index fbe350a5..170b4245 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -18,17 +18,23 @@ class WatiNotification(models.Model): watis = self.env['wati.notification'].search(query, order='id') for wati in watis: - _logger.info('Convert Lead ID %s' % wati.id) + _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 current_lead: + if event_type == 'sessionMessageSent': + current_lead.description = str(current_lead.description)+ "| i:" + str(text) + current_lead.operator_email = operator_email + current_lead.operator_name = operator_name + wati.is_lead = True + elif current_lead: # must append internal notes as a reply here - current_lead.description = str(current_lead.description) + "|" +str(text) + 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 -- cgit v1.2.3 From 08d34e27298f6c2808f1f11986a8e2aaed4f432e Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 17 Feb 2023 10:35:15 +0700 Subject: mapping sales person in wati leads --- indoteknik_custom/models/wati.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index 170b4245..158a16d7 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -28,9 +28,30 @@ class WatiNotification(models.Model): 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 = 20 #Nabila 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 -- cgit v1.2.3 From 3503d77e6e5a2b5bb2d230bd5098cf03731d88c0 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 17 Feb 2023 10:48:18 +0700 Subject: add customer sign in wati leads --- indoteknik_custom/models/wati.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index 158a16d7..0fe3b02d 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -72,6 +72,6 @@ class WatiNotification(models.Model): 'operator_name': operator_name, 'contact_name': contact_name, 'phone': phone, - 'description': text + 'description': "c:" +str(text) }]) wati.is_lead = True -- cgit v1.2.3 From 1ac814df6fb11614d58df36662c7d8f72951f4c3 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Fri, 17 Feb 2023 17:01:49 +0700 Subject: change else to system instead nabila in lead wati --- indoteknik_custom/models/wati.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index 0fe3b02d..e2e723ef 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -47,7 +47,7 @@ class WatiNotification(models.Model): elif 'Saya *Dwi*' in str(text): sales = 24 else: - sales = 20 #Nabila + 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 -- cgit v1.2.3 From 3ea572e1292eca97b193c971091d7d2f7bbb260b Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Tue, 21 Feb 2023 10:12:39 +0700 Subject: add cleanup wati notification and add some field in manufactures --- indoteknik_custom/models/wati.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'indoteknik_custom/models/wati.py') diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index e2e723ef..df467ea1 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -1,4 +1,5 @@ from odoo import fields, models, api +from datetime import datetime, timedelta import logging import json @@ -11,6 +12,18 @@ class WatiNotification(models.Model): json_raw = fields.Char(string='JSON Raw Text') is_lead = fields.Boolean(string='To Leads', help='apakah sudah ter-convert jadi leads') + def _cleanup(self): + current_time = datetime.now() + delta_time = current_time - timedelta(days=15) + + delta_time = delta_time.strftime('%Y-%m-%d %H:%M:%S') + self.env['wati.notification'].search([ + ('create_date', '<', delta_time), + ('is_lead', '=', True), + ]).unlink() + _logger.info('Success Cleanup WATI Notification') + + def _convert_to_leads(self): query = [ ('is_lead', '=', False) -- cgit v1.2.3