Odoo Help


How to check a condition before an act_window calling?

Juan Formoso
on 12/9/14, 12:16 PM 1,644 views

I added an option (named Confirm partners attendance to the meeting) to the menu More of a tree view (event.meeting.registration tree). If I click on this option, it redirects me to the form named mail.compose.message, which is what I want. Here is my code:

<act_window name="Confirm partners attendance to the meeting"

But, I need to check a condition before opening the form of mail.compose.message. If that condition is True, the form will be opened, if the condition is False, I want to raise an ORM exception.

So, my question is: how can I add an option to the menu More, and when clicking on it, check a condition before doing anything?

Note: I tried to check the condition in the default_get function of the res_model (mail.compose.message), but if the condition is False and the ORM exception is being shown, the form of mail.compose.message is being opened anyway, so when I close the ORM exception, the form is still there. And the right behaviour is that when I close the ORM exception, the form of mail.compose.message must be closed too.

Can anyone help me, please?


I'm going to try it through an action server. I don't have any idea of ir.actions.server and the documentation is very poor. I was looking for them in several modules but even so I'm not able to understand them very well.

<record id="my_custom_action" model="ir.actions.server">
    <field name="name">My new option</field>
    <field name="model_id" ref="??????????"/>
    <field name="state">code</field>
    <field name="code">my_condition = self.my_event_meeting_registration_function(cr, uid, ids, context)</field>

<record id="ir_open_mail_compose_message_wizard" model="ir.values">
    <field eval="'client_action_multi'" name="key2"/>
    <field eval="'event.meeting.registration'" name="model"/>
    <field name="name">My new option</field>
    <field eval="'ir.actions.server,%d'%my_custom_action" name="value"/>

Please, correct me if I have anything wrong. What do I have to write in the ref of model_id?




| 5 3 6
Jakarta, Indonesia
On 12/9/14, 11:02 PM

The only way I can think of on top of my head to serve your requirement is to create a method in event.meeting.registration to do the validation, raise an error if the validation did not pass, and return the action.  Then you create a server action that call this method, put this action in the More instead of act_confirm_partners_attendance_to_event_meeting.

Thank you Ivan! How can I create a server action and put it in the More menu?

Juan Formoso
on 12/10/14, 3:56 AM

You can find sample in addons/stock/wizard/stock_partial_move_view.xml.

on 12/10/14, 3:59 AM

Thank you very much for your help @Ivan! I was looking the code you recommended me and more ones, but I hadn't worked with ir.actions.server before and I'm not able to understand them very well. Can you help me a bit, please? I've edited my question.

Juan Formoso
on 12/10/14, 5:19 AM

I'll use the sample that I've provided as an example (please do this while looking at the file as it is very hard to paste the XML here). action_partial_move_server is the action.server. The model_id is model_stock_move, this indicates which model will have the method called in the code field. So, the stock.move model should have action_partial_move method. If you take a look at addons/stock/stock.py indeed there is action_partial_move method for stock.move. Take a look at that method which returns an action.window (the view that you want to display). Before returning that window, it does "something". To put this action into the more button, you need the 2nd record from the XML, which is ir_open_partial_move_wizard, of ir.values. The important part of this record is setting the key2 to 'client_action_multi' and linking it with the action in the value field. So, you need 2 records in the XML, one for the action server, one for the ir.values. Next, you need to develop the method to be called by action server. This method will validate whatever that you need to validate and return the view (action window) upon successful validation.

on 12/10/14, 6:17 AM

I did it as you told me and it works! Thank you very much for your explanations and your patience, @Ivan!

Juan Formoso
on 12/10/14, 7:25 AM

Pleasure to help.

on 12/11/14, 2:40 AM

About This Community

This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.


Odoo Training Center

Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.

Test it now

Question tools

1 follower(s)


Asked: 12/9/14, 12:16 PM
Seen: 1644 times
Last updated: 3/16/15, 8:10 AM