Skip to content

Commit fcbbd32

Browse files
committed
[19.0][MIG] fs_storage Migration 19.0
1 parent ab67d11 commit fcbbd32

10 files changed

Lines changed: 26 additions & 25 deletions

‎.pre-commit-config.yaml‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
exclude: |
22
(?x)
33
# NOT INSTALLABLE ADDONS
4-
^fs_attachment/|
54
^fs_attachment_s3/|
65
^fs_file/|
76
^fs_folder/|

‎fs_attachment/__manifest__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"views/fs_storage.xml",
1818
],
1919
"external_dependencies": {"python": ["python_slugify", "fsspec>=2025.3.0"]},
20-
"installable": False,
20+
"installable": True,
2121
"auto_install": False,
2222
"maintainers": ["lmignon"],
2323
"pre_init_hook": "pre_init_hook",

‎fs_attachment/models/fs_file_gc.py‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,10 @@ class FsFileGC(models.Model):
1717
store_fname = fields.Char("Stored Filename")
1818
fs_storage_code = fields.Char("Storage Code")
1919

20-
_sql_constraints = [
21-
(
22-
"store_fname_uniq",
23-
"unique (store_fname)",
24-
"The stored filename must be unique!",
25-
),
26-
]
20+
_store_fname_uniq = models.Constraint(
21+
'unique (store_fname)',
22+
'The stored filename must be unique!',
23+
)
2724

2825
def _is_test_mode(self) -> bool:
2926
"""Return True if we are running the tests, so we do not mark files for
@@ -101,7 +98,7 @@ def _gc_files(self) -> None:
10198
# the LOCK statement will wait until those concurrent transactions end.
10299
# But this transaction will not see the new attachements if it has done
103100
# other requests before the LOCK (like the method _storage() above).
104-
cr = self._cr
101+
cr = self.env.cr
105102
cr.commit() # pylint: disable=invalid-commit
106103

107104
# prevent all concurrent updates on ir_attachment and fs_file_gc
@@ -125,7 +122,7 @@ def _gc_files_unsafe(self) -> None:
125122
if not codes:
126123
return
127124
# we process by batch of storage codes.
128-
self._cr.execute(
125+
self.env.cr.execute(
129126
"""
130127
SELECT
131128
fs_storage_code,
@@ -145,7 +142,7 @@ def _gc_files_unsafe(self) -> None:
145142
""",
146143
(tuple(codes),),
147144
)
148-
for code, store_fnames in self._cr.fetchall():
145+
for code, store_fnames in self.env.cr.fetchall():
149146
self.env["fs.storage"].get_by_code(code)
150147
fs = self.env["fs.storage"].get_fs_by_code(code)
151148
for store_fname in store_fnames:
@@ -156,7 +153,7 @@ def _gc_files_unsafe(self) -> None:
156153
_logger.debug("Failed to remove file %s", store_fname)
157154

158155
# delete the records from the table fs_file_gc
159-
self._cr.execute(
156+
self.env.cr.execute(
160157
"""
161158
DELETE FROM
162159
fs_file_gc

‎fs_attachment/models/fs_storage.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ def write(self, vals):
132132
if not vals["use_as_default_for_attachments"]:
133133
vals["force_db_for_default_attachment_rules"] = None
134134
res = super().write(vals)
135-
self._create_write_check_constraints(vals)
135+
self.env.create_write_check_constraints(vals)
136136
return res
137137

138138
def _create_write_check_constraints(self, vals):

‎fs_attachment/models/ir_attachment.py‎

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import odoo
2121
from odoo import _, api, fields, models
2222
from odoo.exceptions import AccessError, UserError
23-
from odoo.osv.expression import AND, OR, normalize_domain
23+
from odoo.fields import Domain
2424

2525
from .strtobool import strtobool
2626

@@ -169,9 +169,9 @@ def _store_in_db_instead_of_object_storage_domain(self):
169169
for mimetype_key, limit in storage_config.items():
170170
part = [("mimetype", "=like", f"{mimetype_key}%")]
171171
if limit:
172-
part = AND([part, [("file_size", "<=", limit)]])
172+
part = Domain.AND([part, [("file_size", "<=", limit)]])
173173
# OR simplifies to [(1, '=', 1)] if a domain being OR'ed is empty
174-
domain = OR([domain, part]) if domain else part
174+
domain = Domain.OR([domain, part]) if domain else part
175175
return domain
176176

177177
def _store_in_db_instead_of_object_storage(self, data, mimetype):
@@ -762,9 +762,9 @@ def force_storage_to_db_for_special_fields(
762762
)
763763
return
764764

765-
domain = AND(
765+
domain = Domain.AND(
766766
(
767-
normalize_domain(
767+
Domain.normalize_domain(
768768
[
769769
("store_fname", "=like", f"{storage}://%"),
770770
# for res_field, see comment in
@@ -774,7 +774,7 @@ def force_storage_to_db_for_special_fields(
774774
("res_field", "!=", False),
775775
]
776776
),
777-
normalize_domain(self._store_in_db_instead_of_object_storage_domain()),
777+
Domain.normalize_domain(self._store_in_db_instead_of_object_storage_domain()),
778778
)
779779
)
780780

‎fs_attachment/tests/test_fs_attachment.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -396,7 +396,7 @@ def test_create_attachments_basic_user(self):
396396
group_user = self.env.ref("base.group_user")
397397
group_partner_manager = self.env.ref("base.group_partner_manager")
398398
demo_user.write(
399-
{"groups_id": [(6, 0, [group_user.id, group_partner_manager.id])]}
399+
{"groups_ids": [(6, 0, [group_user.id, group_partner_manager.id])]}
400400
)
401401
# Create basic attachment
402402
self.ir_attachment_model.with_user(demo_user).create(

‎fs_attachment/tests/test_fs_attachment_file_like_adapter.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def prepareClass(cls):
1616
cls.new_content = b"This is a new test attachment"
1717

1818
def prepare(self):
19-
self.attachment = self._create_attachment()
19+
self.attachment = self.env.create_attachment()
2020

2121
def open(self, attachment=None, mode="rb", new_version=False, **kwargs):
2222
return AttachmentFileLikeAdapter(

‎fs_attachment/tests/test_stream.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ def test_serving_field_image(self):
170170
demo_partner = self.env.ref("base.partner_demo")
171171
demo_partner.with_context(
172172
storage_location=self.temp_backend.code,
173-
).write({"image_128": base64.encodebytes(self._create_image(128, 128))})
173+
).write({"image_128": base64.encodebytes(self.env.create_image(128, 128))})
174174
url = f"/web/image/{demo_partner._name}/{demo_partner.id}/image_128"
175175
res = self.assertDownload(
176176
url,

‎fs_storage/__manifest__.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
{
66
"name": "Filesystem Storage Backend",
77
"summary": "Implement the concept of Storage with amazon S3, sftp...",
8-
"version": "18.0.2.0.1",
8+
"version": "19.0.1.0.0",
99
"category": "FS Storage",
1010
"website": "https://github.com/OCA/storage",
1111
"author": " ACSONE SA/NV, Odoo Community Association (OCA)",

‎fs_storage/tests/test_fs_storage.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,12 @@ def test_ensure_one_fs_by_record(self):
8282
for i in range(4):
8383
backend_ids.append(
8484
self.backend.create(
85-
{"name": f"name{i}", "directory_path": f"{i}", "code": f"code{i}"}
85+
{
86+
"name": f"name{i}",
87+
"directory_path": f"{i}",
88+
"code": f"code{i}",
89+
"protocol": "odoofs",
90+
}
8691
).id
8792
)
8893
records = self.backend.browse(backend_ids)

0 commit comments

Comments
 (0)