Odoo Help

Welcome!

This community is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.

0

[V8][SOLVED]Server action syntax: how to correctly write on fields?

By
FEDERICO LEONI
on 7/23/15, 2:20 PM 1,074 views

This is a draft of a server action based on a server action created directly via GUI:

<record id="env2" model="ir.actions.server">
<field name="sequence" eval="5"/>
<field name="name">test2</field>
<field name="model_id" ref="model_rest_order"/>
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
self.write(cr, uid, context=context)
status = 'Pronto'
end_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
to_floor = 2
</field>
</record>

Obviously when I call it raise an error:

ValueError: "old_api() takes at least 4 arguments (3 given)" while evaluating
u'self.write(cr, uid, context=context)\nstatus = \'Pronto\'\nend_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")\nto_floor = \'2\''

And if I add ids, self.write(cr, uid, ids, context=context):

ValueError: "name 'ids' is not defined" while evaluating 
u'self.write(cr, uid, context=context)\nstatus = \'Pronto\'\nend_date = datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")\nto_floor = \'2\''

I admit I'm not understanding how python should be implemented here nor how new api will be triggered. Work directly on python externally is very simple... What is the correct syntax here?
 

Solved with: self.write(cr, uid, context['active_ids'], {'field':'value'})

0
FEDERICO LEONI
On 7/23/15, 3:30 PM

Solved with:

        <record id="rest_order_send" model="ir.actions.server">
<field name="sequence" eval="5"/>
<field name="name">rest_order_send</field>
<field name="model_id" ref="model_rest_order"/>
<field name="condition">True</field>
<field name="type">ir.actions.server</field>
<field name="state">code</field>
<field name="code">
self.write(cr, uid, context['active_ids'], {'status':'Pronto'})
self.write(cr, uid, context['active_ids'], {'to_floor':'2'})
self.write(cr, uid, context['active_ids'], {'end_date':datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")})
</field>
</record>
But I hope it will works on Odoo V9 too, because seems not the new API method...

Is is possible to to display server action button under option More(Action for V9) according to user groups?

Amit Kumar
on 4/16/16, 4:47 PM
0
MEhul
On 2/16/16, 5:20 AM


Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

1 follower(s)

Stats

Asked: 7/23/15, 2:20 PM
Seen: 1074 times
Last updated: 2/16/16, 5:20 AM