Skip to content

[IMP] Add FS Storage Dynamic Routing Rules - #662

Open
baimont wants to merge 1 commit into
OCA:18.0from
acsone:bai_dynamic_storage
Open

[IMP] Add FS Storage Dynamic Routing Rules#662
baimont wants to merge 1 commit into
OCA:18.0from
acsone:bai_dynamic_storage

Conversation

@baimont

@baimont baimont commented Aug 27, 2026

Copy link
Copy Markdown

No description provided.

@OCA-git-bot

Copy link
Copy Markdown
Contributor

Hi @lmignon,
some modules you are maintaining are being modified, check this out!

@OCA-git-bot OCA-git-bot added mod:fs_storage Module fs_storage mod:fs_attachment Module fs_attachment series:18.0 labels Aug 27, 2026
@baimont
baimont force-pushed the bai_dynamic_storage branch from 0d0bdee to 26e70a2 Compare August 27, 2026 14:38
@baimont

baimont commented Aug 27, 2026

Copy link
Copy Markdown
Author

take a look @sbidoul and @AnizR

@AnizR

AnizR commented Aug 31, 2026

Copy link
Copy Markdown

take a look @sbidoul and @AnizR

Can you give some context?

@lmignon lmignon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@baimont Could you add some user-oriented documentation explaining this new feature in the usage section?

I think this is particularly important here, as without this explanation it is quite difficult to understand what the code is doing, and someone discovering the module would otherwise have no way of knowing that this feature exists.

@baimont
baimont force-pushed the bai_dynamic_storage branch from 26e70a2 to a70e6cc Compare September 1, 2026 08:19
@baimont

baimont commented Sep 1, 2026

Copy link
Copy Markdown
Author

@baimont Could you add some user-oriented documentation explaining this new feature in the usage section?

I think this is particularly important here, as without this explanation it is quite difficult to understand what the code is doing, and someone discovering the module would otherwise have no way of knowing that this feature exists.

hey @lmignon, done

Note

A rule's domain is only evaluated when the attachment is created or when its
content is rewritten (e.g. via `open(..., new_version=True)`). It is **not**

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new_version=True is the default. IMO, it's important to be precise here so that users don't think that a regular call to open() without this parameter will behave differently.

@lmignon lmignon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some little comments regarding the way you design your cache....

Comment on lines +415 to +425
@api.model
@tools.ormcache("model_name")
def _get_storage_rule_ids_for_model(self, model_name):
"""Static/cacheable part: which rules exist for this model."""
return tuple(
self.env["fs.storage.rule"]
.sudo()
.search([("model_id.model", "=", model_name)])
.ids
)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you create a cache of rule ids for a given model_name, you should query the database only once for all the model_name and keep a dictionary of ids by model_name into the cache

Comment on lines +434 to +441
rule_ids = self._get_storage_rule_ids_for_model(model_name)
if rule_ids:
record = self.env[model_name].sudo().browse(res_id).exists()
if record:
for rule in self.env["fs.storage.rule"].sudo().browse(rule_ids):
if rule.field_id and rule.field_id.name != field_name:
continue
if record.filtered_domain(safe_eval(rule.domain or "[]")):

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cache of ids for a model_name is useless if you need to browse the records to get the field name and the domain. Why not a cache of [(field_name, storage_code, domain) by model_name?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

mod:fs_attachment Module fs_attachment mod:fs_storage Module fs_storage series:18.0

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants