简体   繁体   中英

Odoo 11 customize wizard function

i want to customize a wizard button to allow the selected items and change the done(Boolean) to True once i click the button. This is the sample view and the wizard button i had created. 在此输入图像描述

And this is my code below in the view file:

<record model="ir.actions.server" id="make_it_done">
    <field name="name">Make it done</field>
    <field name="condition">True</field>
    <field name="model_id" ref="model_todo_task"/>
    <field name="type">ir.actions.server</field>
    <field name="binding_model_id" ref="model_todo_task" />
    <field name="code">
        action = self.make_it_done()
    </field>
</record>

And this is my model file:

from odoo import api,fields, models
from odoo.addons.base.res.res_request import referenceable_models
from odoo.exceptions import ValidationError

class TodoTask(models.Model):

def make_it_done(self):
    print('Success!!')

I wish to create a wizard function that allow to update all of the selected items to "Done" (Just like the build in "Archive" function). But however based on my code, when i select the item and click the wizard function, it just do nothing.

This is the only response i received(The loading shown in picture above). Then all the checkbox would become unchecked. 在此输入图像描述

I don't know what i've missed, but it just don't run the code. Please help me to solve this problem, thank you guys in advance!!

Maybe you can try to add a field named "state"

<field name="state">code</field>

inside the server action, it work for me

You just have to change the server action's code to:

<field name="code">records.make_it_done()</field>

The records will be a recordset of all marked list entries. And then ofcourse change the method:

def make_it_done(self):
    self.done = True

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM