Skip to Content
Menu
This question has been flagged
2 Replies
7957 Views

I have button method that works to change the state of all records by clicking on it.

But here I have called this method by adding server action in action menu but it is showing error, while similar method works on button finely.

Here Is my Method which use to change the state in my case:

---------------------------------------------------------------------------------------------------------------------------------------------------------

@api.multi
def action_publish_appraisal(self):
        print("Method called sucessfully from xml")
        state = self.env['hr.appraisal'].search([])
        rec = self.env['hr.appraisal.stages'].search([('sequence', '=', 6)])
        for record in state:
        record.state = rec
        return True

Here is My view that add a extra option to Action menu in tree view :

----------------------------------------------------------------------------------------------

<record id="publish_appraisal_action" model="ir.actions.server">
<field name="name">Publish Appraisal</field>
 <field name="type">ir.actions.server</field>
 <field name="model_id" ref="kw_appraisal.model_hr_appraisal"/>
 <field name="binding_model_id" ref="kw_appraisal.model_hr_appraisal" />
 <field name="state">code</field>
 <field name="code">action = model.action_publish_appraisal()</field>
 </record>
Avatar
Discard

What the error which you got?

Best Answer

As per your method code, you want to update state for all records (Not the only selected record in list view) so you will change the below in action view :

action = model.action_publish_appraisal()
To:

model.action_publish_appraisal()

But to call action server for the selected records in list view and update the state you have to follow the below:

@api.multi
def action_publish_appraisal(self):
print("Method called sucessfully from xml")
rec = self.env['hr.appraisal.stages'].search([('sequence', '=', 6)])
for record in self:

         record.state = rec 

 return True

View:
<record id="publish_appraisal_action" model="ir.actions.server">
<field name="name">Publish Appraisal</field>
<field name="type">ir.actions.server</field>
<field name="model_id" ref="kw_appraisal.model_hr_appraisal"/>
<field name="binding_model_id" ref="kw_appraisal.model_hr_appraisal" />
<field name="state">code</field>
<field name="code">records.action_publish_appraisal()</field>
</record>
Avatar
Discard