Skip to content

Commit

Permalink
Merge pull request #30 from PinoutLTD/development
Browse files Browse the repository at this point in the history
fix bug for ticket-done. add last occurred field
  • Loading branch information
tubleronchik authored Sep 19, 2024
2 parents 649bbbe + 8a5d64f commit 89d8e48
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 4 deletions.
24 changes: 21 additions & 3 deletions rrs_operator/src/odoo.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import base64
import typing as tp

from tenacity import *
from datetime import datetime

from helpers.logger import Logger
from helpers.odoo import OdooHelper
Expand All @@ -12,6 +12,7 @@
load_dotenv()
ODOO_HELPDESK_NEW_STAGE_ID = os.getenv("ODOO_HELPDESK_NEW_STAGE_ID")
ODOO_HELPDESK_INPROGRESS_STAGE_ID = os.getenv("ODOO_HELPDESK_INPROGRESS_STAGE_ID")
ODOO_LOGS_LINK_FORMAT = os.getenv("ODOO_LOGS_LINK_FORMAT")


class Odoo:
Expand Down Expand Up @@ -141,11 +142,12 @@ def find_ticket_with_source(self, source: str, email: str) -> int:
return ticket_ids[0]
self._logger.debug(f"No ticket found")

@retry(wait=wait_fixed(5))
def get_hashes_from_ticket(self, ticket_id: int) -> list:
self._logger.debug(f"Looking for ipfs hashes in ticket {ticket_id}")
message_ids = self.helper.search(model="mail.message", search_domains=[("model", "=", "helpdesk.ticket"), ("res_id", "=", ticket_id)])
messages = self.helper.read(model="mail.message", record_ids=[message_ids], fields=["id", "body"])
hashes = [msg["body"] for msg in messages if msg["body"].startswith("<p>Qm")]
hashes = [msg["body"] for msg in messages if msg["body"].startswith(f"<p>{ODOO_LOGS_LINK_FORMAT}Qm")]
hashes = [format_hash(hash) for hash in hashes]
return hashes

Expand Down Expand Up @@ -184,4 +186,20 @@ def get_and_update_description(self, ticket_id: int, new_description: str) -> bo
@retry(wait=wait_fixed(5))
def get_description_from_ticket(self, ticket_id: int) -> str:
description = self.helper.read("helpdesk.ticket", [ticket_id], ["description"])[0]["description"]
return description
return description

@retry(wait=wait_fixed(5))
def set_last_occurred(self, ticket_id: int) -> bool:
current_datetime = datetime.now().strftime('%Y-%m-%d %H:%M:%S')
self._logger.debug(f"Updating last occurred for ticket {ticket_id}... Current date: {current_datetime}")
try:
return self.helper.update(
"helpdesk.ticket",
ticket_id,
{
"last_occurred": f"{current_datetime}",
},
)
except Exception as e:
self._logger.error(f"Couldn't update last occurred {e}")
raise Exception("Failed to update last occurred")
1 change: 1 addition & 0 deletions rrs_operator/src/ws_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ def _on_message(self, ws, message):
ticket_id = self.odoo.find_ticket_with_source(source, email)
if ticket_id:
self.odoo.get_and_increase_problem_counter(ticket_id)
self.odoo.set_last_occurred(ticket_id)
current_description = self.odoo.get_description_from_ticket(ticket_id)
self._logger.debug(f"Current description: {current_description}")
if description in current_description:
Expand Down
3 changes: 2 additions & 1 deletion template.env
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ ODOO_RRS_STATUS_PAID_ID=
ODOO_HELPDESK_DONE_STAGE_ID=
FLASK_PORT=5000
ODOO_HELPDESK_NEW_STAGE_ID=
ODOO_HELPDESK_INPROGRESS_STAGE_ID=
ODOO_HELPDESK_INPROGRESS_STAGE_ID=
ODOO_LOGS_LINK_FORMAT=

0 comments on commit 89d8e48

Please sign in to comment.