feat: restore compact ticket notification format
This commit is contained in:
@@ -14,6 +14,7 @@ STATE_FILE = "tickets_state.json"
|
||||
DEFAULT_TIMEOUT = 30
|
||||
DEFAULT_TICKET_FIELDS = ["id", "name", "stage_id", "partner_id", "user_id", "write_date"]
|
||||
DEFAULT_MAX_NOTIFIED_TICKETS = 50
|
||||
DEFAULT_TICKET_URL_TEMPLATE = "{odoo_url}/web#id={id}&model={model}&view_type=form"
|
||||
|
||||
|
||||
def get_config_path():
|
||||
@@ -40,6 +41,9 @@ def audit():
|
||||
tickets_updated,
|
||||
previous_tickets_state,
|
||||
get_max_notified_tickets(conf_wapt),
|
||||
get_ticket_url_template(conf_wapt),
|
||||
conf_wapt.get("odoo", "url").rstrip("/"),
|
||||
conf_wapt.get("odoo", "model", fallback="helpdesk.ticket"),
|
||||
)
|
||||
|
||||
send_to_rocket(message, conf_wapt=conf_wapt)
|
||||
@@ -110,6 +114,10 @@ def get_max_notified_tickets(conf_wapt):
|
||||
return conf_wapt.getint("notification", "max_tickets", fallback=DEFAULT_MAX_NOTIFIED_TICKETS)
|
||||
|
||||
|
||||
def get_ticket_url_template(conf_wapt):
|
||||
return conf_wapt.get("notification", "ticket_url_template", fallback=DEFAULT_TICKET_URL_TEMPLATE)
|
||||
|
||||
|
||||
def build_odoo_payload(service, method, args):
|
||||
return {
|
||||
"jsonrpc": "2.0",
|
||||
@@ -235,7 +243,28 @@ def display_odoo_value(value):
|
||||
return str(value)
|
||||
|
||||
|
||||
def format_ticket_line(ticket, previous_tickets_state):
|
||||
def build_ticket_url(ticket, ticket_url_template, odoo_url, model):
|
||||
return ticket_url_template.format(
|
||||
id=ticket["id"],
|
||||
odoo_url=odoo_url,
|
||||
model=model,
|
||||
)
|
||||
|
||||
|
||||
def format_ticket_line(ticket, ticket_url_template, odoo_url, model):
|
||||
assignee = display_odoo_value(ticket.get("user_id"))
|
||||
if assignee == "-":
|
||||
assignee = "Personne"
|
||||
|
||||
return "%s : Sujet : %s gere par %s : [cliquer ici pour ouvrir le ticket](%s)" % (
|
||||
ticket["id"],
|
||||
display_odoo_value(ticket.get("name", "Sans titre")),
|
||||
assignee,
|
||||
build_ticket_url(ticket, ticket_url_template, odoo_url, model),
|
||||
)
|
||||
|
||||
|
||||
def format_detailed_ticket_line(ticket, previous_tickets_state):
|
||||
ticket_id = str(ticket["id"])
|
||||
previous_write_date = previous_tickets_state.get(ticket_id)
|
||||
change_type = "nouveau" if previous_write_date is None else "modifie"
|
||||
@@ -253,25 +282,27 @@ def format_ticket_line(ticket, previous_tickets_state):
|
||||
return "- " + " | ".join(parts)
|
||||
|
||||
|
||||
def build_notification_message(tickets_updated, previous_tickets_state, max_tickets):
|
||||
def build_notification_message(tickets_updated, previous_tickets_state, max_tickets, ticket_url_template, odoo_url, model):
|
||||
if not tickets_updated:
|
||||
return "Aucun ticket n'a ete mis a jour depuis la derniere verification."
|
||||
|
||||
displayed_tickets = tickets_updated[:max_tickets]
|
||||
hidden_count = len(tickets_updated) - len(displayed_tickets)
|
||||
lines = [
|
||||
"Tickets Odoo mis a jour depuis la derniere verification : %s" % len(tickets_updated),
|
||||
"",
|
||||
"Les tickets suivants ont ete mis a jour depuis la derniere verification :",
|
||||
]
|
||||
lines.extend([
|
||||
format_ticket_line(ticket, previous_tickets_state)
|
||||
format_ticket_line(ticket, ticket_url_template, odoo_url, model)
|
||||
for ticket in displayed_tickets
|
||||
])
|
||||
|
||||
if hidden_count > 0:
|
||||
lines.extend([
|
||||
"",
|
||||
"... %s ticket(s) supplementaire(s) non affiche(s)." % hidden_count,
|
||||
"... %s ticket(s) supplementaire(s) non affiche(s) sur %s au total." % (
|
||||
hidden_count,
|
||||
len(tickets_updated),
|
||||
),
|
||||
])
|
||||
|
||||
return "\n".join(lines)
|
||||
|
||||
Reference in New Issue
Block a user