Skip to Content
Menu
This question has been flagged
2 Replies
2905 Views

Hello dears,


I would appreciate some help on creating an automatic scheduled job to archive tasks which are marked as "ready to archive".

we are using Odoo v14


Some guidance on the setup inside scheduling would be great, including help on the python code if this is required extensively as well...


Thank you

Avatar
Discard
Best Answer

Hi to do this:

  1. Create a new Python module in your Odoo instance. You can name it task_archive_scheduler or anything you like.

  2. In the new module, create a new file named models.py. In this file, define a new class for the task archive scheduler:

    from odoo import models, fields, api
    
    class TaskArchiveScheduler(models.Model):
        _name = 'task.archive.scheduler'
    
        @.model
        def archive_tasks(self):
            Task = self.env['project.task']
            ready_to_archive_tasks = Task.search([('is_ready_to_archive', '=', True)])
            ready_to_archive_tasks.write({'active': False})
    

    In this class, we define a new method archive_tasks which will be called by the scheduled job. This method searches for tasks that are marked as "ready to archive" and archives them by setting the active field to False.

  3. Create a new record for the scheduled job. To do this, navigate to Settings > Technical > Automation > Scheduled Actions in Odoo, and create a new record with the following details:

    • Name: Task Archive Scheduler
    • Model: task.archive.scheduler
    • Method: archive_tasks
    • Interval Number: 1
    • Interval Unit: Hours

    This will create a scheduled job that runs every hour and calls the archive_tasks method in the task.archive.scheduler model.

  4. Finally, you need to set the is_ready_to_archive field to True for the tasks that you want to be archived. You can do this manually for each task, or you can create a custom button or automation rule to set the field automatically based on some criteria.


Avatar
Discard
Best Answer

Hello 

Please check below link will help you

https://www.cybrosys.com/blog/scheduled-actions-in-odoo-14

Avatar
Discard
Related Posts Replies Views Activity
4
Dec 23
19024
1
Jan 21
8615
3
Jul 20
7755
1
Apr 20
12322
3
Jan 20
2461