M Tahir Noor
M Tahir Noor

Reputation: 443

Can i set default value by server action in odoo

I want to set default value in many2one field. But i want to set it by python code in server action at on-creation. Problem is that, I don't know what are the rules and regulations of writing python code in server action. Is there any way to to set default value of Many2one field in server action. For example: Same work is there through customized code Set default value of field depends on other field in odoo

I'll be very thankful ...

Upvotes: 2

Views: 1423

Answers (1)

CZoellner
CZoellner

Reputation: 14768

You can use an automatic action for this requirement. Just create one at Settings/Technical/Automation/Automated Actions. Give it a name, the correct model you want to run it on and ofcourse set "When to run" to "On Creation".

On the second tab add a new server action. Following a simple code snippet for the server action (it's for sale.order and you need an ir.config_parameter with the given external id):

object.write({'client_order_ref': 'YourRef'})
if 'A' in object.partner_id.name:
    object.write({'note': 'AAAAAAAAAA'})
else:
    object.write({'note': env.ref('mymodule.mycool_ir_config_parameter').value})

The example is written for Odoo V8+.

Upvotes: 1

Related Questions