diff options
| author | Azka Nathan <darizkyfaz@gmail.com> | 2026-01-06 13:01:13 +0700 |
|---|---|---|
| committer | Azka Nathan <darizkyfaz@gmail.com> | 2026-01-06 13:01:13 +0700 |
| commit | 3c885bec3b51b35c77c983444a949783cb53e198 (patch) | |
| tree | 43f482e653a223d7625c32026d949ac7819511f5 /fixco_custom/models/queue_job.py | |
| parent | 0d60d1c77f39859754e6f1cb46efe19d3ec1df38 (diff) | |
queuing job
Diffstat (limited to 'fixco_custom/models/queue_job.py')
| -rw-r--r-- | fixco_custom/models/queue_job.py | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/fixco_custom/models/queue_job.py b/fixco_custom/models/queue_job.py new file mode 100644 index 0000000..68ddf8c --- /dev/null +++ b/fixco_custom/models/queue_job.py @@ -0,0 +1,46 @@ +from odoo import models, fields, api +from odoo.exceptions import UserError +import traceback + +class QueueJob(models.Model): + _name = 'queue.job' + _description = 'Queueing Job Runner' + _order = 'create_date desc' + + name = fields.Char(required=True) + model_name = fields.Char(required=True) + method_name = fields.Char(required=True) + res_id = fields.Integer(string='Record ID') + state = fields.Selection([ + ('draft', 'Draft'), + ('running', 'Running'), + ('done', 'Done'), + ('error', 'Error'), + ], default='draft') + + error_message = fields.Text() + + def action_run_selected(self): + for job in self: + job.action_run() + + def action_run(self, limit=10): + jobs = self.search([('state', '=', 'draft')], order='create_date desc', limit=limit) + for job in jobs: + job.state = 'running' + try: + + record = self.env[job.model_name].browse(job.res_id) + if not record.exists(): + raise UserError('Target record not found') + + method = getattr(record, job.method_name, None) + if not method: + raise UserError('Method not found') + + method() # 🔥 EXECUTE + job.state = 'done' + + except Exception as e: + job.state = 'error' + job.error_message = traceback.format_exc() |
