콘텐츠로 건너뛰기
메뉴
커뮤니티에 참여하려면 회원 가입을 하시기 바랍니다.
신고된 질문입니다
2 답글
8701 화면

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>
아바타
취소

What the error which you got?

베스트 답변

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>
아바타
취소