So I read I can do this to create a popup at the top right of the screen:
def action(self):
return { 'warning': {'title': 'Success', 'message': 'Warning works'}}
But it does not work for me... Do I need anything else or I'm doing something wrong, or is this functionality discontinued?
I'm calling the action with a button, and it actualy triggers, it is just the popup that does not work.
I'm on CE Odoo 15 currently, but would like to know from Odoo 14 till Odoo 17 (last version).
Thanks.
Places I checked:
https://www.odoo.com/forum/help-1/how-to-display-a-warning-popup-when-select-customer-150137
https://www.odoo.com/forum/help-1/how-can-i-make-a-popup-warning-message-93419
Plus other sources...
I want to add a popup that shows up when I use the "write" methode, the methode is called when the status of the status bar is changed:
from odoo import models, fields,api
from odoo.exceptions import ValidationError
import json
class labSample(models.Model):
_name = 'lab.sample'
_description = 'lab Sample (Base)'
name = fields.Char(string="Name", required=True)
sample_request_id = fields.Many2one('sample.request', string="Sample Request")
sample_request_line_id = fields.Many2one('sample.request.line', string="Sample Request Line", ondelete='cascade')
state= fields.Selection([
('draft', 'Draft'),
('progress', 'In progress'),
('done', 'Done'),
], string='Status', default='draft', required=True)
datum_test = fields.Date(string='Datum test')
uitvoerder = fields.Many2one('hr.employee', string='Uitvoerder')
required_for_done_fields = []
@api.constrains('state')
def _check_required_fields_on_done(self):
for record in self:
if record.state == 'done' and record.required_for_done_fields:
missing_fields = [
field for field in record.required_for_done_fields
if not getattr(record, field)
]
if missing_fields:
field_labels = ', '.join(self._fields[f].string for f in missing_fields)
raise ValidationError(
f"Je kan deze staal niet op 'Done' zetten zonder volgende ingevulde velden: {field_labels}."
)
def write(self, vals):
result = super().write(vals)
if 'state' in vals:
self._notify_success_message()
return result