Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
1 Trả lời
2631 Lượt xem

In Odoo 15, How can I trigger a webhook data to an external system whenever records are created, updated, or deleted by Odoo's system.

Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

Hello, 


In that case, you need to develop a custom method for the webhook and you need to call that method based on CURD operations.

Eg. code

    @api.model
    def create(self, vals):
        record = super(MyModel, self).create(vals)
        self.send_webhook_notification('create', record)
        return record

    def write(self, vals):
        res = super(MyModel, self).write(vals)
        self.send_webhook_notification('update', self)
        return res

    def unlink(self):
        res = super(MyModel, self).unlink()
        self.send_webhook_notification('delete', self)
        return res

    def send_webhook_notification(self, action, record):
        # Construct webhook payload
        payload = {
            'action': action,
            'record_id': record.id,
            'record_name': record.name,
            # Add more fields as needed
        }

        # Send webhook request
        webhook_url = 'https://your-webhook'
        requests.post(webhook_url, json=payload)

Thanks

Ảnh đại diện
Huỷ bỏ
Bài viết liên quan Trả lời Lượt xem Hoạt động
2
thg 7 24
1241
2
thg 7 24
2774
2
thg 3 24
3452
1
thg 12 22
3247
0
thg 8 21
3060