Skip ke Konten
Menu
Pertanyaan ini telah diberikan tanda
2 Replies
47910 Tampilan

Hello, 

  I have a custom module that has a new item in the "More" contextual dropdown menu.  When the item is clicked, it calls an action saved to the ir.action.server.  The action executes python code like it's supposed to.  The python code creates a new record on the sale.order table and is supposed to open the sale.order form with the newly created record.  I have a return statement at the end of the python code which is supposed to open the sale.order form, but for some reason it isn't.  I don't understand why, because the same return statement works on other function calls except this one.  Can anyone help me open the sale.order form after my function has created a new record on the sale.order model?

Here is the code that adds the line to the "More" contextual dropdown:

<record model="ir.values" id="test_more_item">
            <field name="name">New More Item</field>
            <field name="model" eval="'sale.licenses'" />
            <field name="key" >action</field>
            <field name="key2">client_action_multi</field>
            <field name="value" eval="'ir.actions.server,%d'%sale_license_more_item_action" />
            <field name="object" eval="True" />
        </record>

 

This is the action the the "More" item calls.  its from the ir.action.server

<record id="sale_license_more_item_action" model="ir.actions.server">
            <field name="name">Renew Licenses</field>
            <field name="type">ir.actions.server</field>
            <field name="res_model">sale.order</field>
            <field name="model_id" >283</field>
            <field name="view_type">form</field>
            <field name="view_mode">form</field>
            <field name="state">code</field>
            <field name="code">self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>
        </record>

 

This is the function that is called from the server action

def renew_license(self, cr, uid, ids, context=None):

     ...(code that creates new sale.order record)

     return {
            'name': 'Sale Order Form',
            'view_type': 'form',
            'view_mode': 'form',
            'view_id': self.pool.get('ir.ui.view').search(cr, uid, [('name','=','sale.order.form')])[0],
            'res_model': 'sale.order',
            'res_id': new_order_id,
            'type': 'ir.actions.act_window',
        }

Normally the return statement would open the sale.order form, but in this case it isn't.  Does anyone know what I am doing wrong with this?

Avatar
Buang
Penulis Jawaban Terbai

I finally got the answer right.  Thanks to Maniganda's answer found on this link: 

https://www.odoo.com/forum/help-1/question/call-function-from-the-more-dropdown-list-61330

 

All I needed to do was change this line:

<field name="code">self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>

 

To this:

<field name="code">action = self.renew_license(cr, uid, context.get('active_ids', []), context=context)</field>

 

Thank you Maniganda!

Avatar
Buang

Thanks @Eric and @Maniganda your answer save my time.

Jawaban Terbai

This is my guessing (I never do this). I think the problem is that new sale order, new_order_id, record hasn't been commited. As far as I know odoo commit transaction at the end of request. So when the method return an action, odoo makes the action void because new_order_id is not available yet.

Avatar
Buang
Penulis

Hello Ben, I tried testing this by using an ID of another sale order, but it still didn't open the form view. Thanks for your reply

Post Terkait Replies Tampilan Aktivitas
0
Jun 21
2845
1
Okt 24
1509
2
Mei 24
8477
2
Des 23
12551
3
Jul 22
22859