summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-02-16 14:44:57 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-02-16 14:44:57 +0700
commit5413d6ae243fc2c9dd37930097928d51ef961aaa (patch)
tree3185d2c5266d4ad3b9d31a34ab8f87e513164979
parent895a2e9ae261a6e11ae5673f0694165919edc6e7 (diff)
convert wati to leads
-rwxr-xr-xindoteknik_custom/models/crm_lead.py4
-rw-r--r--indoteknik_custom/models/wati.py36
2 files changed, 40 insertions, 0 deletions
diff --git a/indoteknik_custom/models/crm_lead.py b/indoteknik_custom/models/crm_lead.py
index 3c8b842b..0534eb2f 100755
--- a/indoteknik_custom/models/crm_lead.py
+++ b/indoteknik_custom/models/crm_lead.py
@@ -10,6 +10,10 @@ class CrmLead(models.Model):
file_tdp = fields.Binary(string="Tanda Daftar Perusahaan")
file_siup = fields.Binary(string="Surat Izin Usaha Perdagangan")
body_html_lead = fields.Text('Body HTML', compute='compute_body_leads')
+ # for wati only
+ ticket_id = fields.Char('Ticket ID', help='Ticket ID yang ada di WATI')
+ operator_email = fields.Char('Operator Email', help='Operator yang membalas')
+ operator_name = fields.Char('Operator Name', help='Operator yang membalas')
def revert_to_leads(self):
opportunities = self.env['crm.lead'].search([
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