diff --git a/addons/purchase/__manifest__.py b/addons/purchase/__manifest__.py index 973d7917853..bcf698316fb 100644 --- a/addons/purchase/__manifest__.py +++ b/addons/purchase/__manifest__.py @@ -38,6 +38,7 @@ 'application': True, 'assets': { 'web.assets_backend': [ + 'purchase/static/src/toaster_button/*', 'purchase/static/src/scss/purchase.scss', 'purchase/static/src/js/purchase_dashboard.js', 'purchase/static/src/js/purchase_toaster_button.js', @@ -49,6 +50,7 @@ 'purchase/static/src/js/purchase_portal_sidebar.js', ], 'web.assets_qweb': [ + 'purchase/static/src/toaster_button/*.xml', 'purchase/static/src/xml/**/*', ], }, diff --git a/addons/purchase/static/src/toaster_button/toaster_button_widget.js b/addons/purchase/static/src/toaster_button/toaster_button_widget.js new file mode 100644 index 00000000000..ed13748fdfd --- /dev/null +++ b/addons/purchase/static/src/toaster_button/toaster_button_widget.js @@ -0,0 +1,27 @@ +/** @odoo-module */ +import { registry } from "@web/core/registry"; +import { useService } from "@web/core/utils/hooks"; + +const { Component } = owl; + +class ButtonWithNotification extends Component { + setup() { + this.orm = useService("orm"); + this.notification = useService("notification"); + } + + async onClick() { + const result = await this.orm.call(this.props.record.resModel, this.props.method, [this.props.record.resId]); + const message = result.toast_message; + this.notification.add(message, { type: "success" }); + } +} +ButtonWithNotification.template = "purchase.ButtonWithNotification"; +ButtonWithNotification.extractProps = ({ attrs }) => { + return { + method: attrs.button_name, + title: attrs.title, + }; +}; + +registry.category("view_widgets").add("toaster_button", ButtonWithNotification); diff --git a/addons/purchase/static/src/toaster_button/toaster_button_widget.xml b/addons/purchase/static/src/toaster_button/toaster_button_widget.xml new file mode 100644 index 00000000000..f63fbeb7b71 --- /dev/null +++ b/addons/purchase/static/src/toaster_button/toaster_button_widget.xml @@ -0,0 +1,10 @@ + +