Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions odoo/custom/src/18.0/mail_bot_odooclaw/models/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from . import ir_module_module
from . import mail_thread
from . import res_partner
from . import res_users
Expand Down
80 changes: 80 additions & 0 deletions odoo/custom/src/18.0/mail_bot_odooclaw/models/ir_module_module.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import logging
import threading
import requests
from odoo import models

_logger = logging.getLogger(__name__)


class IrModuleModule(models.Model):
_inherit = "ir.module.module"

def button_immediate_install(self):
result = super().button_immediate_install()

webhook_url = (
self.env["ir.config_parameter"]
.sudo()
.get_param("odooclaw.webhook_url")
)
if not webhook_url:
return result

for module in self:
t = threading.Thread(
target=self._notify_odooclaw_module_installed,
args=(module.name, module.shortdesc, webhook_url),
)
t.daemon = True
t.start()
return result

def _notify_odooclaw_module_installed(self, module_name, module_display_name, webhook_url):
try:
payload = {
"is_dm": True,
"body": (
f"System task - no reply needed: The Odoo module '{module_name}' "
f"({module_display_name}) has just been installed. "
f"Use odoo_search on ir.model to discover its models, then "
f"use the write_file tool to append a summary to "
f"/home/odooclaw/.odooclaw/workspace/memory/MODULES.md. "
f"Format: ## {module_name}\\n- model: description\\n. "
f"Do not reply, just write the file."
),
"author_id": 1,
"author_user_id": 1,
"author_name": "Odoo System",
"company_id": 1,
"allowed_company_ids": [1],
"model": "",
"res_id": 0,
"reply_model": "",
"reply_res_id": 0,
"voice_attachments": [],
"invoice_attachments": [],
"attachments": [],
}

def send_webhook(url, data):
try:
requests.post(
url,
json=data,
headers={"Content-Type": "application/json"},
timeout=5,
)
except Exception as e:
_logger.error(
"OdooClaw: failed to send webhook: %s", e
)

threading.Thread(
target=send_webhook, args=(webhook_url, payload)
).start()

except Exception:
_logger.exception(
"OdooClaw: error notifying module installation for %s",
module_name,
)