From 9083b3f3b1332246ed4df3f544423ee28da49896 Mon Sep 17 00:00:00 2001 From: Christopher Rogos Date: Fri, 3 Jul 2026 09:24:37 +0000 Subject: [PATCH] [IMP] fs_attachment: fix parsing of stored filenames when storing locally --- fs_attachment/models/ir_attachment.py | 14 +++++++++----- fs_attachment/tests/test_fs_attachment.py | 22 ++++++++++++++++++++++ 2 files changed, 31 insertions(+), 5 deletions(-) diff --git a/fs_attachment/models/ir_attachment.py b/fs_attachment/models/ir_attachment.py index 09a46e8cef..9a822fb004 100644 --- a/fs_attachment/models/ir_attachment.py +++ b/fs_attachment/models/ir_attachment.py @@ -518,11 +518,15 @@ def _fs_parse_store_fname( :param fname: the fname to parse :param base: if True, return the base filesystem """ - partition = fname.partition("://") - storage_code = partition[0] - fs = self._get_fs_storage_for_code(storage_code) - fname = partition[2] - return fs, storage_code, fname + storage_code = None + fs = None + file_name = fname + if "://" in fname: + partition = fname.partition("://") + storage_code = partition[0] + fs = self._get_fs_storage_for_code(storage_code) + file_name = partition[2] + return fs, storage_code, file_name @api.model def _parse_fs_filename(self, filename: str) -> tuple[str, int, int, str] | None: diff --git a/fs_attachment/tests/test_fs_attachment.py b/fs_attachment/tests/test_fs_attachment.py index a5116bd0fd..0b69ec8790 100644 --- a/fs_attachment/tests/test_fs_attachment.py +++ b/fs_attachment/tests/test_fs_attachment.py @@ -11,6 +11,28 @@ class TestFSAttachment(TestFSAttachmentCommon): + def test_fs_parse_store_fname(self): + raw_fname = "fc/fcc92eb498d207046dcf79f50badd1041535626c" + fs, storage_code, file_name = self.ir_attachment_model._fs_parse_store_fname( + raw_fname + ) + self.assertFalse(fs) + self.assertFalse(storage_code) + self.assertEqual(file_name, raw_fname) + + @mock.patch( + "odoo.addons.fs_storage.models.fs_storage.FSStorage.get_fs_by_code", + return_value="FS_MOCK", + ) + def test_fs_parse_store_fname_azure(self, mock_fs_storage): + azure_fname = "azure://b1/e9/screenshot-2026-06-30-190529-700499-0.png" + fs, storage_code, file_name = self.ir_attachment_model._fs_parse_store_fname( + azure_fname + ) + self.assertIs(fs, "FS_MOCK") + self.assertEqual(storage_code, "azure") + self.assertEqual(file_name, "b1/e9/screenshot-2026-06-30-190529-700499-0.png") + def test_create_attachment_explicit_location(self): content = b"This is a test attachment" attachment = (