From 3327fbccee4c6c95df325b515a7a42b6f937d381 Mon Sep 17 00:00:00 2001 From: stephanchrst Date: Wed, 29 Nov 2023 12:10:14 +0700 Subject: add expired date on wati --- indoteknik_custom/models/wati.py | 29 ++++++++++++++++++++++++++++- indoteknik_custom/views/wati_history.xml | 24 +++++++++++++++++++++++- 2 files changed, 51 insertions(+), 2 deletions(-) diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index bb6f2293..1e6ac17f 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -77,6 +77,7 @@ class WatiNotification(models.Model): return new_header def _create_wati_history_line(self, new_header, ticket_id, sender_name, notification_json, date_wati): + text_body = notification_json['text'] or '' param_line = { "wati_history_id": new_header.id, "conversation_id": notification_json['conversationId'], @@ -89,13 +90,22 @@ class WatiNotification(models.Model): "sender_name": sender_name or '', # "source_url": notification_json['sourceUrl'] or '', "status_string": notification_json['statusString'] or '', - "text": notification_json['text'] or '', + "text": text_body, "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]) + new_header.last_reply_by = sender_name + new_header.last_reply_date = date_wati + new_header.last_reply_text = text_body + if sender_name == 'Indoteknik': + current_time = date_wati + # current_time_str = current_time.strftime('%Y-%m-%d %H:%M:%S') + delta_time = current_time + timedelta(days=1) + # delta_time_str = delta_time.strftime('%Y-%m-%d %H:%M:%S') + new_header.expired_date = delta_time return def _convert_to_leads(self): @@ -173,6 +183,23 @@ class WatiHistory(models.Model): 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) + last_reply_by = fields.Char(string='Last Reply by') + last_reply_text = fields.Char(string='Last Reply Text') + last_reply_date = fields.Datetime(string='Last Reply Date') + expired_date = fields.Datetime(string='Expired Date') + + # @api.onchange('last_reply_date') + # def _compute_expired_date(self): + # if self.last_reply_by == 'Indoteknik': + # return + # else: + # print(1) + # current_time = self.last_reply_date + # # current_time_str = current_time.strftime('%Y-%m-%d %H:%M:%S') + # delta_time = current_time + timedelta(days=1) + # # delta_time_str = delta_time.strftime('%Y-%m-%d %H:%M:%S') + # self.expired_date = delta_time + # return class WatiHistoryLine(models.Model): _name = 'wati.history.line' diff --git a/indoteknik_custom/views/wati_history.xml b/indoteknik_custom/views/wati_history.xml index 0b805ac5..1b9acc92 100644 --- a/indoteknik_custom/views/wati_history.xml +++ b/indoteknik_custom/views/wati_history.xml @@ -11,6 +11,10 @@ + + + + @@ -52,10 +56,14 @@ + - + + + + @@ -68,10 +76,24 @@ + + wati.history.list.select + wati.history + + + + + + + + + + Wati History ir.actions.act_window wati.history + tree,form -- cgit v1.2.3