Skip to content

Commit

Permalink
[IMP] edi_oca: don't consider exchange records if jobs have been created
Browse files Browse the repository at this point in the history
  • Loading branch information
MiquelRForgeFlow committed Jul 26, 2024
1 parent bc5de07 commit 4f2effb
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
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 @@ -415,6 +415,7 @@ def _check_output_exchange_sync(
)
for rec in new_records:
job1 = rec.delayable().action_exchange_generate()
rec.is_fetched = True
if not skip_send:
# Chain send job.
# Raise prio to max to send the record out as fast as possible.
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_fetched", "=", False),
]
if record_ids:
domain.append(("id", "in", record_ids))
Expand Down Expand Up @@ -628,6 +630,7 @@ def _check_input_exchange_sync(self, record_ids=None, **kw):
)
for rec in pending_records:
rec.with_delay().action_exchange_receive()
rec.is_fetched = True

pending_process_records = self.exchange_record_model.search(
self._input_pending_process_records_domain(record_ids=record_ids)
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_fetched", "=", 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_fetched = 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 api, models
from odoo.tools import pycompat

_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_fetched and job.state != "failed":
records.is_fetched = False
return super().write(vals)

0 comments on commit 4f2effb

Please sign in to comment.