|
7 | 7 | from collections import namedtuple |
8 | 8 |
|
9 | 9 | from odoo import _, api, exceptions, fields, models, tools |
| 10 | +from odoo.tools import str2bool |
10 | 11 |
|
11 | 12 | from ..fields import JobSerialized |
12 | 13 |
|
@@ -81,6 +82,7 @@ def _default_channel(self): |
81 | 82 | "See the module description for details.", |
82 | 83 | ) |
83 | 84 | allow_commit = fields.Boolean( |
| 85 | + default=lambda self: self._default_allow_commit_by_default(), |
84 | 86 | help="Allows the job to commit transactions during execution. " |
85 | 87 | "Under the hood, this executes the job in a new database cursor, " |
86 | 88 | "which incurs a slight overhead.", |
@@ -155,7 +157,19 @@ def job_default_config(self): |
155 | 157 | related_action_func_name=None, |
156 | 158 | related_action_kwargs={}, |
157 | 159 | job_function_id=None, |
158 | | - allow_commit=False, |
| 160 | + allow_commit=self._default_allow_commit_by_default(), |
| 161 | + ) |
| 162 | + |
| 163 | + @api.model |
| 164 | + def _default_allow_commit_by_default(self): |
| 165 | + # We shoud not allow commit by default on job functions, this parameter |
| 166 | + # is here for backward compatibility, a migration sets it by default on |
| 167 | + # existing databases, but new databases will have it set to False by |
| 168 | + # default. |
| 169 | + return str2bool( |
| 170 | + self.env["ir.config_parameter"] |
| 171 | + .sudo() |
| 172 | + .get_param("queue_job.allow_commit_by_default") |
159 | 173 | ) |
160 | 174 |
|
161 | 175 | def _parse_retry_pattern(self): |
|
0 commit comments