3

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. enter image description here

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. enter image description here

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!!

2 Answers2

3

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

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

inside the server action, it work for me

0

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
CZoellner
  • 13,553
  • 3
  • 25
  • 38
  • Hi Czoellner, thank for your answer, but it still returning the same result. After i checked the checkbox, then i clicked the wizard function, but it just simply showing loading, after that the checkbox i selected directly become unchecked. – Kowa JiaLiang Jul 18 '18 at 08:56
  • Hi, i don't get error, can you please take a look at my question? I put the only response i received at question already. – Kowa JiaLiang Jul 18 '18 at 09:42