Passa al contenuto
Menu
È necessario essere registrati per interagire con la community.
La domanda è stata contrassegnata
2 Risposte
6774 Visualizzazioni

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...

Avatar
Abbandona

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



Risposta migliore

Hi,

To generate a sticky notification on the right side of the screen in Odoo, please try with below code:

def action(self):

    return {

                'type': 'ir.actions.client',

                'tag': 'display_notification',

                'params': {

                    'message': _("Warning works"),

                    'type': 'success',

                },

            }


Hope it helps



Avatar
Abbandona
Autore

Works like a charm!
Does this mean that the other way I was trying is deprecated?

Risposta migliore

Need to return something like this, i copy this from mrp module in v15

return {

'type': 'ir.actions.client',

'tag': 'display_notification',

'params': {

'title': _("Note that archived work center(s): '%s' is/are still linked to active Bill of Materials, which means that operations can still be planned on it/them. "

"To prevent this, deletion of the work center is recommended instead.", filtered_workcenters),

'type': 'warning',

'sticky': True, #True/False will display for few seconds if false

'next': {'type': 'ir.actions.act_window_close'},

},

}

Avatar
Abbandona
Post correlati Risposte Visualizzazioni Attività
0
nov 23
1373
1
set 23
2333
1
lug 22
1125
2
giu 20
3289
2
apr 20
9848