Hello,I want to create a only one (1) planning activity with an automated action but Odoo creates 6.
if record.stage_id.id is 2:
env['mail.activity'].create({
'display_name': 'text',
'summary':'text',
'date_deadline':datetime.datetime.now(),
'user_id':record.user_id.id,
'res_id':record.id,
'res_model_id':828,
'activity_type_id':4})
Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:
- CRM
- e-Commerce
- Accounting
- Inventory
- PoS
- Project
- MRP
This question has been flagged
It looks like you are using the env['mail.activity'] model to create a new activity each time the if condition is met. This will create a new activity each time the if condition is met, resulting in multiple activities being created.
To create only one activity, you can use the write() method to update the existing activity instead of creating a new one. You can do this by first checking if the activity already exists using the search() method, and then using the write() method to update the existing activity.
Here is an example of how you can do this:
# check if the activity already exists activity = env['mail.activity'].search([('res_id', '=', record.id), ('activity_type_id', '=', 4)]) # if the activity exists, update it if activity: activity.write({ 'display_name': 'text', 'summary': 'text', 'date_deadline': datetime.datetime.now(), 'user_id': record.user_id.id, }) # if the activity does not exist, create it else: env['mail.activity'].create({ 'display_name': 'text', 'summary': 'text', 'date_deadline': datetime.datetime.now(), 'user_id': record.user_id.id, 'res_id': record.id, 'res_model_id': 828, 'activity_type_id': 4 })
This code will first check if an activity with the specified res_id and activity_type_id already exists. If it exists, it will update the existing activity with the new values. If it does not exist, it will create a new activity. This will ensure that only one activity is created for each res_id and activity_type_id.
Hi, you can try this :
todos = {
'res_id': record.id,
'res_model_id': self.env['ir.model'].search([('model', '=', 'your.model')]).id,
'user_id': user_id,
'summary': 'your task title'),
'note': 'your task message'),
'activity_type_id': 4,
'date_deadline': datetime.date.today(),
}
self.env['mail.activity'].create(todos)
Best regards,
Altela (altelasoftware.com)
Enjoying the discussion? Don't just read, join in!
Create an account today to enjoy exclusive features and engage with our awesome community!
Sign up
Too little info.. Where is this code called? Is it in a for loop?