Another example of using Automated Actions to setup data in other Models (database tables).
The requirement is to add a new applicant to a mailing list when the appreciation is changed to Very Good (2 stars) or Excellent (3 stars).
Automated Action
Start by enabling Developer Mode and navigating to Settings / Technical / (Automation) / Automated Actions:
Create a new Automated Action as shown:

- Model = Applicant
- Action To Do = Execute Python Code
- Model (to write records) = Mailing Contact
- Trigger Condition = On Update
- Before Update Domain
- Email is set and Appreciation is Normal or Good
["&",["email_from","!=",""],"|",["priority","=","0"],["priority","=","1"]]
- Apply on
- Email is set and Appreciation is Very Good or Excellent
["&",["email_from","!=",""],"|",["priority","=","2"],["priority","=","3"]]
Python Code
env['mail.mass_mailing.contact'].create({
'name':record.name,
'email':record.email_from,
'list_ids':[1,2]
})
Note that you will need to replace the list ids with the IDs of the mailing list(s), as explained here
This could create multiple records on the Mailing List in certain circumstances
Thanks a lot for sharing, this post help me to solve a similar issue I have been facing.
LikeLike