diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-12-10 16:24:43 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-12-10 16:24:43 +0700 |
| commit | 72f8f3081d29b100e159f766e1c3483bdef5ce45 (patch) | |
| tree | 1c774306db589e6aff696312f6a1ada89b76e633 | |
| parent | 8e9b91259ecd62eff4e17210678287b844f78132 (diff) | |
fix bug wati
| -rw-r--r-- | indoteknik_custom/models/wati.py | 25 |
1 files changed, 20 insertions, 5 deletions
diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index ec7bd3b9..a0619f83 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -32,28 +32,43 @@ class WatiNotification(models.Model): ]).unlink() _logger.info('Success Cleanup WATI Notification') - def _parse_notification(self, limit = 0): + def _parse_notification(self, limit=0): domain = [('is_parsed', '=', False)] notifications = self.search(domain, order='id', limit=limit) notification_not_parsed_count = self.search_count(domain) i = 0 for notification in notifications: i += 1 - _logger.info('[Parse Notification][%s] Process: %s/%s | Not Parsed: %s' % (notification.id, i, str(limit), str(notification_not_parsed_count))) + _logger.info('[Parse Notification][%s] Process: %s/%s | Not Parsed: %s' % + (notification.id, i, str(limit), str(notification_not_parsed_count))) + notification_json = json.loads(notification.json_raw) sender_name = 'Indoteknik' if 'senderName' in notification_json: sender_name = notification_json['senderName'] - ticket_id = notification_json['ticketId'] - date_wati = float(notification_json['timestamp']) - date_wati = datetime.fromtimestamp(date_wati) + ticket_id = notification_json.get('ticketId') + timestamp = notification_json.get('timestamp') + + if not timestamp: + _logger.warning('[Parse Notification][%s] Missing timestamp in notification JSON: %s' % + (notification.id, notification.json_raw)) + continue # Skip this notification + + try: + date_wati = datetime.fromtimestamp(float(timestamp)) + except ValueError as e: + _logger.error('[Parse Notification][%s] Invalid timestamp format: %s. Error: %s' % + (notification.id, timestamp, str(e))) + continue + 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 return |
