summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorstephanchrst <stephanchrst@gmail.com>2023-11-29 09:12:10 +0700
committerstephanchrst <stephanchrst@gmail.com>2023-11-29 09:12:10 +0700
commit5d4cfcb05b85add3bc08a0e161257a69e10550e2 (patch)
treec08f0975a735ee7f91b16a08fb89022cf6d46340
parent693e78afa8b9b4df99f417392b42bff12ea41f9e (diff)
history of wati
-rwxr-xr-xindoteknik_custom/__manifest__.py1
-rw-r--r--indoteknik_custom/models/wati.py96
-rwxr-xr-xindoteknik_custom/security/ir.model.access.csv4
-rw-r--r--indoteknik_custom/views/wati_history.xml85
4 files changed, 176 insertions, 10 deletions
diff --git a/indoteknik_custom/__manifest__.py b/indoteknik_custom/__manifest__.py
index bc11b346..39e5cdd9 100755
--- a/indoteknik_custom/__manifest__.py
+++ b/indoteknik_custom/__manifest__.py
@@ -103,6 +103,7 @@
'views/account_bank_statement.xml',
'views/stock_warehouse_orderpoint.xml',
'views/customer_commision.xml',
+ 'views/wati_history.xml',
'report/report.xml',
'report/report_banner_banner.xml',
'report/report_banner_banner2.xml',
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py
index 1f694380..bb6f2293 100644
--- a/indoteknik_custom/models/wati.py
+++ b/indoteknik_custom/models/wati.py
@@ -17,7 +17,7 @@ class WatiNotification(models.Model):
text_time = fields.Datetime(string='Text Time')
text_type = fields.Char(string='Text Type')
json_raw = fields.Char(string='JSON Raw Text')
- is_parsed = fields.Boolean(string='Is Parsed')
+ is_parsed = fields.Boolean(string='Is Parsed', default=False)
is_lead = fields.Boolean(string='To Leads', help='apakah sudah ter-convert jadi leads')
def _cleanup(self):
@@ -33,7 +33,7 @@ class WatiNotification(models.Model):
def _parse_notification(self, limit = 0):
domain = [('is_parsed', '=', False)]
- notifications = self.search(domain, order='id desc', limit=limit)
+ notifications = self.search(domain, order='id', limit=limit)
notification_not_parsed_count = self.search_count(domain)
i = 0
for notification in notifications:
@@ -43,14 +43,59 @@ class WatiNotification(models.Model):
sender_name = 'Indoteknik'
if 'senderName' in notification_json:
sender_name = notification_json['senderName']
-
- notification.ticket_id = notification_json['ticketId']
- notification.mobile = notification_json['waId']
- notification.sender_name = sender_name
- notification.text = notification_json['text']
- notification.text_time = datetime.fromtimestamp(float(notification_json['timestamp']))
- notification.text_type = notification_json['type']
+
+ ticket_id = notification_json['ticketId']
+ date_wati = float(notification_json['timestamp'])
+ date_wati = datetime.fromtimestamp(date_wati)
+ wati_history = self.env['wati.history'].search([('ticket_id', '=', ticket_id)], limit=1)
+ if wati_history:
+ self._create_wati_history_line(wati_history, ticket_id, sender_name, notification_json, date_wati)
+ else:
+ new_header = self._create_wati_history_header(ticket_id, sender_name, notification_json, date_wati)
+ self._create_wati_history_line(new_header, ticket_id, sender_name, notification_json, date_wati)
notification.is_parsed = True
+
+ # notification.ticket_id = notification_json['ticketId']
+ # notification.mobile = notification_json['waId']
+ # notification.sender_name = sender_name
+ # notification.text = notification_json['text']
+ # notification.text_time = datetime.fromtimestamp(float(notification_json['timestamp']))
+ # notification.text_type = notification_json['type']
+ # notification.is_parsed = True
+ # return
+
+ def _create_wati_history_header(self, ticket_id, sender_name, notification_json, date_wati):
+ param_header = {
+ 'ticket_id': ticket_id,
+ 'conversation_id': notification_json['conversationId'],
+ 'sender_name': sender_name,
+ 'wa_id': notification_json['waId'],
+ 'text': notification_json['text'],
+ 'date_wati': date_wati or '',
+ }
+ new_header = self.env['wati.history'].create([param_header])
+ return new_header
+
+ def _create_wati_history_line(self, new_header, ticket_id, sender_name, notification_json, date_wati):
+ param_line = {
+ "wati_history_id": new_header.id,
+ "conversation_id": notification_json['conversationId'],
+ "data": notification_json['data'] or '',
+ "event_type": notification_json['eventType'] or '',
+ # "list_reply": notification_json['listReply'] or '',
+ # "message_contact": notification_json['messageContact'] or '',
+ "operator_email": notification_json['operatorEmail'] or '',
+ "operator_name": notification_json['operatorName'] or '',
+ "sender_name": sender_name or '',
+ # "source_url": notification_json['sourceUrl'] or '',
+ "status_string": notification_json['statusString'] or '',
+ "text": notification_json['text'] or '',
+ "ticket_id": ticket_id,
+ "type": notification_json['type'] or '',
+ "wa_id": notification_json['waId'] or '',
+ "date_wati": date_wati or '',
+ }
+ self.env['wati.history.line'].create([param_line])
return
def _convert_to_leads(self):
@@ -116,3 +161,36 @@ class WatiNotification(models.Model):
}])
wati.is_lead = True
wati.lead_id = current_lead.id
+
+
+class WatiHistory(models.Model):
+ _name = 'wati.history'
+
+ ticket_id = fields.Char(string='Ticket ID')
+ conversation_id = fields.Char(string='Conversation ID')
+ sender_name = fields.Char(string='Sender Name')
+ wa_id = fields.Char(string='WA ID')
+ text = fields.Char(string='Text')
+ date_wati = fields.Datetime(string='Date WATI')
+ wati_lines = fields.One2many('wati.history.line', 'wati_history_id', string='Lines', auto_join=True)
+
+class WatiHistoryLine(models.Model):
+ _name = 'wati.history.line'
+
+ #sender
+ wati_history_id = fields.Many2one('ref', required=True, ondelete='cascade', index=True, copy=False)
+ conversation_id = fields.Char(string='Conversation ID')
+ data = fields.Char(string='data')
+ event_type = fields.Char(string='Event Type')
+ list_reply = fields.Char(string='List Reply')
+ message_contact = fields.Char(string='Message Contact')
+ operator_email = fields.Char(string='Operator Email')
+ operator_name = fields.Char(string='Operator Name')
+ sender_name = fields.Char(string='Sender Name')
+ source_url = fields.Char(string='Source URL')
+ status_string = fields.Char(string='Status String')
+ text = fields.Char(string='Text')
+ ticket_id = fields.Char(string='Ticket ID')
+ type = fields.Char(string='Type')
+ wa_id = fields.Char(string='WA ID')
+ date_wati = fields.Datetime(string='Date WATI')
diff --git a/indoteknik_custom/security/ir.model.access.csv b/indoteknik_custom/security/ir.model.access.csv
index ff467204..56d00b3e 100755
--- a/indoteknik_custom/security/ir.model.access.csv
+++ b/indoteknik_custom/security/ir.model.access.csv
@@ -81,4 +81,6 @@ access_quotation_so_multi_update,access.quotation.so.multi_update,model_quotatio
access_product_monitoring,access.product.monitoring,model_product_monitoring,,1,1,1,1
access_customer_commision,access.customer.commision,model_customer_commision,,1,1,1,1
access_customer_commision_line,access.customer.commision.line,model_customer_commision_line,,1,1,1,1
-access_customer_rebate,access.customer.rebate,model_customer_rebate,,1,1,1,1 \ No newline at end of file
+access_customer_rebate,access.customer.rebate,model_customer_rebate,,1,1,1,1
+access_wati_history,access.wati.history,model_wati_history,,1,1,1,1
+access_wati_history_line,access.wati.history.line,model_wati_history_line,,1,1,1,1 \ No newline at end of file
diff --git a/indoteknik_custom/views/wati_history.xml b/indoteknik_custom/views/wati_history.xml
new file mode 100644
index 00000000..6636b960
--- /dev/null
+++ b/indoteknik_custom/views/wati_history.xml
@@ -0,0 +1,85 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+<odoo>
+ <record id="wati_history_tree" model="ir.ui.view">
+ <field name="name">wati.history.tree</field>
+ <field name="model">wati.history</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="date_wati" readonly="1"/>
+ <field name="ticket_id" readonly="1"/>
+ <field name="conversation_id" readonly="1"/>
+ <field name="sender_name" readonly="1"/>
+ <field name="wa_id" readonly="1"/>
+ <field name="text" readonly="1"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="wati_history_line_tree" model="ir.ui.view">
+ <field name="name">wati.history.line.tree</field>
+ <field name="model">wati.history.line</field>
+ <field name="arch" type="xml">
+ <tree>
+ <field name="date_wati" readonly="1"/>
+ <field name="conversation_id" readonly="1" optional="hide"/>
+ <field name="data" readonly="1" optional="hide"/>
+ <field name="event_type" readonly="1" optional="hide"/>
+ <field name="list_reply" readonly="1" optional="hide"/>
+ <field name="message_contact" readonly="1" optional="hide"/>
+ <field name="operator_email" readonly="1"/>
+ <field name="operator_name" readonly="1"/>
+ <field name="sender_name" readonly="1"/>
+ <field name="source_url" readonly="1" optional="hide"/>
+ <field name="status_string" readonly="1"/>
+ <field name="text" readonly="1"/>
+ <field name="ticket_id" readonly="1" optional="hide"/>
+ <field name="type" readonly="1" optional="hide"/>
+ <field name="wa_id" readonly="1" optional="hide"/>
+ </tree>
+ </field>
+ </record>
+
+ <record id="wati_history_form" model="ir.ui.view">
+ <field name="name">wati.history.form</field>
+ <field name="model">wati.history</field>
+ <field name="arch" type="xml">
+ <form>
+ <sheet string="Wati">
+ <div class="oe_button_box" name="button_box"/>
+ <group>
+ <group>
+ <field name="date_wati" readonly="1"/>
+ <field name="ticket_id" readonly="1"/>
+ <field name="sender_name" readonly="1"/>
+ <field name="text" readonly="1"/>
+ </group>
+ <group>
+ <field name="conversation_id" readonly="1"/>
+ <field name="wa_id" readonly="1"/>
+ </group>
+ </group>
+ <notebook>
+ <page string="Lines">
+ <field name="wati_lines"/>
+ </page>
+ </notebook>
+ </sheet>
+ </form>
+ </field>
+ </record>
+
+ <record id="wati_history_action" model="ir.actions.act_window">
+ <field name="name">Wati History</field>
+ <field name="type">ir.actions.act_window</field>
+ <field name="res_model">wati.history</field>
+ <field name="view_mode">tree,form</field>
+ </record>
+
+ <menuitem id="menu_wati_history"
+ name="Wati History"
+ action="wati_history_action"
+ parent="sale.product_menu_catalog"
+ sequence="103"
+ />
+
+</odoo> \ No newline at end of file