diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2024-11-14 16:08:42 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2024-11-14 16:08:42 +0700 |
| commit | 7b60204cb96af3d180fa21570c7540722184ab4e (patch) | |
| tree | 407017a4addad6a544ee05ef1e7b941c6745fe8a | |
| parent | 95810d47b28ec503aee6753ffa4ac3d0ca9877e8 (diff) | |
fix bug wati
| -rwxr-xr-x | indoteknik_custom/models/sale_order.py | 4 | ||||
| -rw-r--r-- | indoteknik_custom/models/wati.py | 57 |
2 files changed, 38 insertions, 23 deletions
diff --git a/indoteknik_custom/models/sale_order.py b/indoteknik_custom/models/sale_order.py index e90ca995..80e111a8 100755 --- a/indoteknik_custom/models/sale_order.py +++ b/indoteknik_custom/models/sale_order.py @@ -973,8 +973,8 @@ class SaleOrder(models.Model): note.append(line.name) if order.picking_ids: - # Sort picking_ids by date and get the most recent one - latest_picking = order.picking_ids.sorted(key=lambda p: p.scheduled_date, reverse=True)[0] + # Sort picking_ids by creation date to get the most recent one + latest_picking = order.picking_ids.sorted(key=lambda p: p.create_date, reverse=True)[0] latest_picking.notee = '\n'.join(note) return res diff --git a/indoteknik_custom/models/wati.py b/indoteknik_custom/models/wati.py index eed5413e..f3632334 100644 --- a/indoteknik_custom/models/wati.py +++ b/indoteknik_custom/models/wati.py @@ -58,41 +58,56 @@ class WatiNotification(models.Model): return def _create_wati_history_header(self, ticket_id, sender_name, notification_json, date_wati): + # Helper function to remove NUL characters + def remove_null_characters(value): + if isinstance(value, str): + return value.replace('\0', '') + return value + + # Sanitize the input data 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 '', + 'conversation_id': remove_null_characters(notification_json.get('conversationId', '')), + 'sender_name': remove_null_characters(sender_name), + 'wa_id': remove_null_characters(notification_json.get('waId', '')), + 'text': remove_null_characters(notification_json.get('text', '')), + 'date_wati': remove_null_characters(date_wati or ''), } + + # Create the record 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): - text_body = notification_json['text'] or '' + # Helper function to remove NUL characters + def remove_null_characters(value): + if isinstance(value, str): + return value.replace('\0', '') + return value + + # Sanitize the input data 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": text_body, + "conversation_id": remove_null_characters(notification_json.get('conversationId', '')), + "data": remove_null_characters(notification_json.get('data', '')), + "event_type": remove_null_characters(notification_json.get('eventType', '')), + "operator_email": remove_null_characters(notification_json.get('operatorEmail', '')), + "operator_name": remove_null_characters(notification_json.get('operatorName', '')), + "sender_name": remove_null_characters(sender_name or ''), + "status_string": remove_null_characters(notification_json.get('statusString', '')), + "text": remove_null_characters(notification_json.get('text', '')), "ticket_id": ticket_id, - "type": notification_json['type'] or '', - "wa_id": notification_json['waId'] or '', - "date_wati": date_wati or '', + "type": remove_null_characters(notification_json.get('type', '')), + "wa_id": remove_null_characters(notification_json.get('waId', '')), + "date_wati": remove_null_characters(date_wati or ''), } + + # Create the record safely without NUL characters self.env['wati.history.line'].create([param_line]) - self._update_header_after_create_line(new_header, sender_name, date_wati, text_body) + self._update_header_after_create_line(new_header, sender_name, date_wati, param_line['text']) return + def _update_header_after_create_line(self, new_header, sender_name, date_wati, text_body): new_header.last_reply_by = sender_name new_header.last_reply_date = date_wati |
