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

[14.0][IMP] edi_oca: Prevent duplication of type code in exchange filenames #1032

Open
wants to merge 1 commit into
base: 14.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
6 changes: 5 additions & 1 deletion edi_oca/models/edi_exchange_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,11 @@ def name_get(self):
rec_name = rec.identifier
if rec.res_id and rec.model:
rec_name = rec.record.display_name
name = "[{}] {}".format(rec.type_id.name, rec_name)
name = (
"[{}] {}".format(rec.type_id.name, rec_name)
if rec._context.get("include_exchange_type_name", True)
else rec_name
)
result.append((rec.id, name))
return result

Expand Down
9 changes: 9 additions & 0 deletions edi_oca/models/edi_exchange_type.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,15 @@ def _make_exchange_filename(self, exchange_record):
ext = self.exchange_file_ext
pattern = pattern + ".{ext}"
dt = self._make_exchange_filename_datetime()
# Avoid duplicating type code in filename if not having related record
if (
"{type.code}" in pattern
and slugify(self.code) == slugify(self.name)
and (not exchange_record.res_id or not exchange_record.model)
):
exchange_record = exchange_record.with_context(
include_exchange_type_name=False
)
record_name = self._get_record_name(exchange_record)
record = exchange_record
if exchange_record.model and exchange_record.res_id:
Expand Down
19 changes: 19 additions & 0 deletions edi_oca/tests/test_record.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from odoo.tools import mute_logger

from odoo.addons.edi_oca.utils import get_checksum
from odoo.addons.http_routing.models.ir_http import slugify
from odoo.addons.queue_job.delay import DelayableRecordset

from .common import EDIBackendCommonTestCase
Expand Down Expand Up @@ -77,6 +78,24 @@ def test_record_exchange_date(self):
fields.Datetime.to_string(record.exchanged_on), "2020-10-21 10:00:00"
)

def test_record_exchange_filename(self):
# Using pattern with `record_name`
self.exchange_type_out.exchange_filename_pattern = (
"{record_name}-{type.code}-{dt}"
)
vals = {
"edi_exchange_state": "new",
}
record = self.backend.create_record("test_csv_output", vals)
self.assertFalse(record.exchanged_on)
with freeze_time("2020-10-21 10:00:00"):
# Should not have a duplicate of exc type code in filename
identifier = slugify(record.identifier)
self.assertEqual(
record.exchange_filename,
f"{identifier}-test_csv_output-2020-10-21-12-00-00.csv",
)

@mute_logger("odoo.models.unlink")
def test_record_relation(self):
# create new one to delete it later
Expand Down
Loading