From c9ccb2408ab1450ba23bc31ae8855ba2da7954d2 Mon Sep 17 00:00:00 2001 From: len Date: Thu, 14 Dec 2023 10:14:03 +0100 Subject: [PATCH] [IMP] fs_storage: compute options protocol Before the change, reading the options protocol might not be in sync with the record protocol. This is particularly the case if the record is save in the middle of editing as the value resets, which can be quite confusing. --- fs_storage/models/fs_storage.py | 4 ++-- fs_storage/tests/test_fs_storage.py | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/fs_storage/models/fs_storage.py b/fs_storage/models/fs_storage.py index f0a201c9ae..a04da09c20 100644 --- a/fs_storage/models/fs_storage.py +++ b/fs_storage/models/fs_storage.py @@ -125,14 +125,13 @@ def __init__(self, env, ids=(), prefetch_ids=()): options_protocol = fields.Selection( string="Describes Protocol", selection="_get_options_protocol", - default="odoofs", + compute="_compute_protocol_descr", help="The protocol used to access the content of filesystem.\n" "This list is the one supported by the fsspec library (see " "https://filesystem-spec.readthedocs.io/en/latest). A filesystem protocol" "is added by default and refers to the odoo local filesystem.\n" "Pay attention that according to the protocol, some options must be" "provided through the options field.", - store=False, ) options_properties = fields.Text( string="Available properties", @@ -236,6 +235,7 @@ def _inverse_json_options(self) -> None: def _compute_protocol_descr(self) -> None: for rec in self: rec.protocol_descr = fsspec.get_filesystem_class(rec.protocol).__doc__ + rec.options_protocol = rec.protocol @api.model def _get_options_protocol(self) -> list[tuple[str, str]]: diff --git a/fs_storage/tests/test_fs_storage.py b/fs_storage/tests/test_fs_storage.py index 74dfde8814..18e5d812af 100644 --- a/fs_storage/tests/test_fs_storage.py +++ b/fs_storage/tests/test_fs_storage.py @@ -6,6 +6,7 @@ import warnings from unittest import mock +from odoo.tests import Form from odoo.tests.common import TransactionCase from odoo.tools import mute_logger @@ -151,3 +152,17 @@ def test_recursive_add_odoo_storage_path_to_options(self): .get("target_options") .get("odoo_storage_path"), ) + + def test_interface_values(self): + protocol = "file" # should be available by default in the list of protocols + with Form(self.env["fs.storage"]) as new_storage: + new_storage.name = "Test storage" + new_storage.code = "code" + new_storage.protocol = protocol + self.assertEqual(new_storage.protocol, protocol) + # the options should follow the protocol + self.assertEqual(new_storage.options_protocol, protocol) + description = new_storage.protocol_descr + self.assertTrue("Interface to files on local storage" in description) + # this is still true after saving + self.assertEqual(new_storage.options_protocol, protocol)