Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[12.0][IMP] edi_oca: don't consider exchange records if jobs have been created #996

Open
wants to merge 1 commit into
base: 12.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions edi_oca/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
from . import edi_exchange_type
from . import edi_exchange_type_rule
from . import edi_id_mixin
from . import queue_job
4 changes: 4 additions & 0 deletions edi_oca/models/edi_backend.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,7 @@ def _check_output_exchange_sync(
len(new_records),
)
for rec in new_records:
rec.is_queued = True
job1 = rec.delayable().action_exchange_generate()
if not skip_send:
# Chain send job.
Expand Down Expand Up @@ -447,6 +448,7 @@ def _output_new_records_domain(self, record_ids=None):
("type_id.direction", "=", "output"),
("edi_exchange_state", "=", "new"),
("exchange_file", "=", False),
("is_queued", "=", False),
]
if record_ids:
domain.append(("id", "in", record_ids))
Expand Down Expand Up @@ -627,6 +629,7 @@ def _check_input_exchange_sync(self, record_ids=None, **kw):
len(pending_records),
)
for rec in pending_records:
rec.is_queued = True
rec.with_delay().action_exchange_receive()

pending_process_records = self.exchange_record_model.search(
Expand All @@ -645,6 +648,7 @@ def _input_pending_records_domain(self, record_ids=None):
("type_id.direction", "=", "input"),
("edi_exchange_state", "=", "input_pending"),
("exchange_file", "=", False),
("is_queued", "=", False),
]
if record_ids:
domain.append(("id", "in", record_ids))
Expand Down
2 changes: 2 additions & 0 deletions edi_oca/models/edi_exchange_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,8 @@ class EDIExchangeRecord(models.Model):
compute="_compute_retryable",
help="The record state can be rolled back manually in case of failure.",
)
is_queued = fields.Boolean(
help="Technical field to know if a related job has been created already.")

_sql_constraints = [
("identifier_uniq", "unique(identifier)", "The identifier must be unique."),
Expand Down
22 changes: 22 additions & 0 deletions edi_oca/models/queue_job.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2024 ForgeFlow S.L.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html)

import logging

from odoo import models

_logger = logging.getLogger(__name__)


class QueueJob(models.Model):
_inherit = 'queue.job'

def write(self, vals):
for job in self:
records = job.records.exists()
if len(records) != 1 or records._name != "edi.exchange.record":
continue
if (vals.get("state", "") == "failed" and records.is_queued
and job.state != "failed"):
records.is_queued = False
return super().write(vals)
Loading