Skip to Content
Menu
This question has been flagged
3 Replies
4065 Views

I work to add some warning messages (non blocking) in my custom. Any one tell me how can i display a warning message.


Thanks,



Avatar
Discard
Best Answer

Hello Manoj,

You can try this

return {
'warning': {
'title': 'Warning!',
'message': 'Your warning text here.'}
}

Regards

Avatar
Discard
Best Answer

Hi, I have the same problem, and I used the following format in my code, but it does not display any message:

I want to display a warning message on a custom button (btc_approved) in sale.order.

I don't know what the issue is!

I understand this method is typically used under the onchange decorator, but I don’t have a field to use with onchange. Is there any alternative solution?

Here is my method:

def btc_approved(self):
for record in self:
user = record.user_id
if record.b2c_status != 'ready':
raise ValidationError(_("Only B2C Sale Orders with Ready can be Approved"))
elif record.b2c_sales == False:
raise ValidationError(_("Only B2C Sale Orders can be Approved"))
else:
if user.has_group('vatanzarin_security.visitor_group') and record.b2c_status == 'ready':
partner = record.partner_id
if partner.sale_warn and partner.sale_warn_msg != 'no_message':
return {
'warning': {
'title': _("There is a warning note for %s") % partner.name,
'message': partner.sale_warn_msg,
'type': 'notification',
}
}
record.b2c_status = 'approved'
record.financial_status = 'approved'
record.sudo().trigger_picking_atv(True)
Avatar
Discard
Best Answer

Hi

You can use ValidationError or Usererrors  to display warning messages



from odoo.exceptions import ValidationError, UserError


def action_confirm(self):
if (apply the condition):
raise UserError(_('Warning Message'))


<button string="Update" name="action_update"
       id="action_update"
       class="btn-success" type="object"
       confirm="Message?"
     />




Regards

Avatar
Discard
Author

Thanks for the answer Bella James,
But this will block the flow, i want not to stop the flow of code

Check the Updated answer

Related Posts Replies Views Activity
1
Oct 22
2511
2
Aug 24
9275
0
Apr 22
2232
1
Jun 25
1164
3
Jul 25
2898