Examples of Button Action

Attention

The information provided in this section has been created by assuming that the user is familiar with the Python language and knows the CloudOffix structure. 


Changing the state of the current object
CloudOffix - Examples of Button Action

"object": Record on which the action is triggered if there is one, otherwise None.

Here, there must exist a State with the technical name "done" on the related model. When this button is clicked, the action will run and change the State of the related record.

 Assigning current object user field to the current user

When assigning a field in the button action, the field that will be assigned to it must be in the related model. In this example, "user_id" field exists in the model and the active User ID is assigned to "user_id" field.

object.write({'user_id':env.uid})
Call an action on the current model

You can write code yourself, or you can also call a function available in the system. 

action = object.action_set_won_rainbowman()

Adding a note to the model's chatter

When after many successful processes , the user may want to write a message into the model's chatter. This piece of code will help you.

object.message_post(message_type='comment',body="Something happened successfully!")
Send a direct notification to a specific partner
object.message_post(body="Example mail body", message_type='email', partner_ids=env['res.partner'].search([('name','ilike','John Cumberbatch')]).ids)