From 45f4272ae22b1f8dbba3df3a34ea5abe1fb77dc9 Mon Sep 17 00:00:00 2001 From: Wolfgang Pichler Date: Thu, 5 Oct 2023 15:20:41 +0200 Subject: [PATCH] [FIX] Fixed the stored filename to include the path. Without this you are not able to store files in custom sub directories [FIX] Do take nested rooted fs paths into account in computation of store_fname. Code by @lmignon - Laurent Mignon (ACSONE) --- fs_attachment/models/ir_attachment.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/fs_attachment/models/ir_attachment.py b/fs_attachment/models/ir_attachment.py index 8b34a6b9c3..63cffd5e8f 100644 --- a/fs_attachment/models/ir_attachment.py +++ b/fs_attachment/models/ir_attachment.py @@ -458,6 +458,19 @@ def _enforce_meaningful_storage_filename(self) -> None: # we need to update the store_fname with the new filename by # calling the write method of the field since the write method # of ir_attachment prevent normal write on store_fname + + # rooted_dir path computation... + # done by @lmignon - Laurent Mignon (ACSONE) + # there could be a nested rooted dir in the fs path - we do compute it here + # and remove it from the new_filename if it does exists + rooted_paths = [] + rooted_dir_fs = fs + while rooted_dir_fs and hasattr(rooted_dir_fs, "path"): + rooted_paths.append(rooted_dir_fs.path) + rooted_dir_fs = getattr(rooted_dir_fs, "fs", None) + rooted_paths.reverse() + rooted_path = "/".join(rooted_paths) + new_filename = new_filename_with_path.replace(rooted_path, "") attachment._force_write_store_fname(f"{storage}://{new_filename}") self._fs_mark_for_gc(attachment.store_fname)