Initial commit: Odoo 18.0-20251222 extra-addons
This commit is contained in:
2
sale_automatic_workflow_periodicity/models/__init__.py
Executable file
2
sale_automatic_workflow_periodicity/models/__init__.py
Executable file
@@ -0,0 +1,2 @@
|
||||
from . import automatic_workflow_job
|
||||
from . import sale_workflow_process
|
||||
42
sale_automatic_workflow_periodicity/models/automatic_workflow_job.py
Executable file
42
sale_automatic_workflow_periodicity/models/automatic_workflow_job.py
Executable file
@@ -0,0 +1,42 @@
|
||||
# Copyright 2023 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo import api, fields, models
|
||||
|
||||
|
||||
class AutomaticWorkflowJob(models.Model):
|
||||
_inherit = "automatic.workflow.job"
|
||||
|
||||
def run_with_workflow(self, sale_workflow):
|
||||
res = super().run_with_workflow(sale_workflow)
|
||||
if sale_workflow.periodicity:
|
||||
sale_workflow.next_execution = fields.Datetime.add(
|
||||
fields.Datetime.now(), seconds=sale_workflow.periodicity
|
||||
)
|
||||
return res
|
||||
|
||||
@api.model
|
||||
def _workflow_process_to_run_domain(self):
|
||||
return [
|
||||
"|",
|
||||
("periodicity", "=", 0),
|
||||
"|",
|
||||
"&",
|
||||
("periodicity", ">", 0),
|
||||
("next_execution", "<=", fields.Datetime.now()),
|
||||
("next_execution", "=", False),
|
||||
]
|
||||
|
||||
def _sale_workflow_domain(self, workflow):
|
||||
domain = super()._sale_workflow_domain(workflow)
|
||||
if workflow.periodicity_check_create_date:
|
||||
domain.append(
|
||||
(
|
||||
"create_date",
|
||||
"<",
|
||||
fields.Datetime.subtract(
|
||||
fields.Datetime.now(), seconds=workflow.periodicity
|
||||
),
|
||||
)
|
||||
)
|
||||
return domain
|
||||
29
sale_automatic_workflow_periodicity/models/sale_workflow_process.py
Executable file
29
sale_automatic_workflow_periodicity/models/sale_workflow_process.py
Executable file
@@ -0,0 +1,29 @@
|
||||
# Copyright 2023 Camptocamp SA
|
||||
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html)
|
||||
|
||||
from odoo import fields, models
|
||||
|
||||
|
||||
class SaleWorkflowProcess(models.Model):
|
||||
_inherit = "sale.workflow.process"
|
||||
|
||||
periodicity = fields.Integer(
|
||||
string="Run every (in seconds)",
|
||||
help="Sets a periodicity for this workflow to be executed (in seconds)",
|
||||
)
|
||||
next_execution = fields.Datetime()
|
||||
periodicity_check_create_date = fields.Boolean(
|
||||
string="Enforce on creation time",
|
||||
help="When checked only sales created before the last execution "
|
||||
"will be processed.",
|
||||
)
|
||||
|
||||
def write(self, vals):
|
||||
if "periodicity" in vals.keys():
|
||||
periodicity = vals["periodicity"]
|
||||
if periodicity == 0:
|
||||
vals["next_execution"] = False
|
||||
else:
|
||||
now = fields.Datetime.now()
|
||||
vals["next_execution"] = fields.Datetime.add(now, seconds=periodicity)
|
||||
return super().write(vals)
|
||||
Reference in New Issue
Block a user