alerts: Teams webhook fan-out (contract 0.14.0) + printedparts detail revision column
send_webhook(title,text) posts alerts to an optional webhook (Teams Incoming Webhook / Workflow, or generic JSON) via alert_webhook_url + alert_webhook_format settings; send_alert fans out to it alongside email; exposed on shopdb.api (0.13.0->0.14.0, PLUGIN-HOOKS synced); low-stock posts on its custom-recipient path too. Also: recent-transactions table shows the consumed print-file revision.
This commit is contained in:
@@ -330,26 +330,33 @@ def _send_lowstock_alert(item):
|
||||
Recipients: Setting printedparts_alert_email (comma-separated), falling
|
||||
back to the site's alert_recipients. Never fails the transaction - the
|
||||
ledger write already committed."""
|
||||
from shopdb.api import send_email, send_alert, Setting
|
||||
from shopdb.api import send_email, send_alert, send_webhook, Setting
|
||||
code = item.gagelabtag or item.itemcode
|
||||
subject = (f'Low stock: {item.itemname} ({code}) - '
|
||||
f'{item.quantityonhand} left')
|
||||
# Absolute link to the item page when the site base URL is configured
|
||||
# (e.g. https://<host>/ops). Emails have no request context to derive it.
|
||||
base = (Setting.get('site_base_url') or '').rstrip('/')
|
||||
link_html = (f'<p><a href="{base}/printedparts/{item.printeditemid}">'
|
||||
f'View {code}</a></p>') if base else ''
|
||||
item_url = f'{base}/printedparts/{item.printeditemid}' if base else ''
|
||||
link_html = f'<p><a href="{item_url}">View {code}</a></p>' if item_url else ''
|
||||
html = (f'<p><strong>{item.itemname}</strong> ({code}) is down '
|
||||
f'to <strong>{item.quantityonhand}</strong> '
|
||||
f'(threshold {item.lowstockthreshold}).</p>'
|
||||
f'<p>Bin: {item.binlocation or "-"}</p>'
|
||||
f'{link_html}'
|
||||
f'<p>Time to print more.</p>')
|
||||
webhook_text = (f'**{item.itemname}** ({code}) is down to '
|
||||
f'{item.quantityonhand} (threshold {item.lowstockthreshold}). '
|
||||
f'Bin: {item.binlocation or "-"}.'
|
||||
+ (f' [View]({item_url})' if item_url else ''))
|
||||
try:
|
||||
recipients = _alert_recipients()
|
||||
if recipients:
|
||||
# send_email does not fan to the webhook, so post it explicitly.
|
||||
send_webhook(subject, webhook_text)
|
||||
send_email(recipients, subject, html)
|
||||
else:
|
||||
# send_alert already fans out to email + webhook.
|
||||
send_alert(subject, html)
|
||||
except Exception:
|
||||
import logging
|
||||
|
||||
Reference in New Issue
Block a user