How to popup success message in odoo?

2024/10/13 14:25:18

I am sending invitation by clicking button after clicking button and successfully sending invitation there is pop up message of successfully invitation send. But the problem is that the main heading of pop up message is Odoo Server Error. That is because I am using

raise osv.except_osv("Success", "Invitation is successfully sent")

Is there any alternative to make it better.

Answer

When I need something like this I have a dummy wizard with message field, and have a simple form view that show the value of that field.

When ever I want to show a message after clicking on a button I do this:

     @api.multidef action_of_button(self):# do what ever login like in your case send an invitation......# don't forget to add translation support to your message _()message_id = self.env['message.wizard'].create({'message': _("Invitation is successfully sent")})return {'name': _('Successfull'),'type': 'ir.actions.act_window','view_mode': 'form','res_model': 'message.wizard',# pass the id'res_id': message_id.id,'target': 'new'}

The form view of message wizard is as simple as this:

<record id="message_wizard_form" model="ir.ui.view"><field name="name">message.wizard.form</field><field name="model">message.wizard</field><field name="arch" type="xml"><form ><p class="text-center"><field name="message"/></p><footer><button name="action_ok" string="Ok" type="object" default_focus="1" class="oe_highlight"/> </footer><form></field>
</record>

Wizard is just simple is this:

class MessageWizard(model.TransientModel):_name = 'message.wizard'message = fields.Text('Message', required=True)@api.multidef action_ok(self):""" close wizard"""return {'type': 'ir.actions.act_window_close'}

Note: Never use exceptions to show Info message because everything run inside a big transaction when you click on button and if there is any exception raised a Odoo will do rollback in the database, and you will lose your data if you don't commit your job first manually before that, witch is not recommended too in Odoo

https://en.xdnf.cn/q/69524.html

Related Q&A

How to make ttk.Scale behave more like tk.Scale?

Several Tk widgets also exist in Ttk versions. Usually they have the same general behaviour, but use "styles" and "themes" rather than per-instance appearance attributes (such as bg…

pandas cut multiple columns

I am looking to apply a bin across a number of columns.a = [1, 2, 9, 1, 5, 3] b = [9, 8, 7, 8, 9, 1]c = [a, b]print(pd.cut(c, 3, labels=False))which works great and creates:[[0 0 2 0 1 0] [2 2 2 2 2 0]…

Tracking the number of recursive calls without using global variables in Python

How to track the number of recursive calls without using global variables in Python. For example, how to modify the following function to keep track the number of calls?def f(n):if n == 1:return 1else…

Match string in python regardless of upper and lower case differences [duplicate]

This question already has answers here:Case insensitive in(12 answers)Closed 9 years ago.Im trying to find a match value from a keyword using python. My values are stored in a list (my_list) and in the…

Can celery celerybeat use a Database Scheduler without Django?

I have a small infrastructure plan that does not include Django. But, because of my experience with Django, I really like Celery. All I really need is Redis + Celery to make my project. Instead of usin…

Django UserCreationForm custom fields

I am trying to create form for user registration and add some custom fields. For doing that, Ive subclassed UserCretionForm and added fields as shown in django documentation. Then Ive created function-…

Why val_loss and val_acc are not displaying?

When the training starts, in the run window only loss and acc are displayed, the val_loss and val_acc are missing. Only at the end, these values are showed. model.add(Flatten()) model.add(Dense(512, ac…

Is there a python module to solve/integrate a system of stochastic differential equations?

I have a system of stochastic differential equations that I would like to solve. I was hoping that this issue was already address. I am a bit concerned about constructing my own solver because I fear m…

How does thread pooling works, and how to implement it in an async/await env like NodeJS?

I need to run a function int f(int i) with 10_000 parameters and it takes around 1sec to execute due to I/O time. In a language like Python, I can use threads (or async/await, I know, but Ill talk abou…

Calculate centroid of entire GeoDataFrame of points

I would like to import some waypoints/markers from a geojson file. Then determine the centroid of all of the points. My code calculates the centroid of each point not the centroid of all points in the …