Skip to content

Commit

Permalink
Merge PR #341 into 16.0
Browse files Browse the repository at this point in the history
Signed-off-by lmignon
  • Loading branch information
OCA-git-bot committed Feb 23, 2024
2 parents fa95079 + 939119a commit a238204
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 5 deletions.
2 changes: 1 addition & 1 deletion fs_file/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Fs File
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e85a98065914bf2696dd3d083e4b5eab6b9d91d8c3ce69ba63cb5abef93587f7
!! source digest: sha256:ba969b14fbeee8a8a16e0297d2468467a7140cb7a51b84281269f8ee5137ae2b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand Down
5 changes: 4 additions & 1 deletion fs_file/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ def __init__(
self._buffer.name = name
else:
raise ValueError("value must be bytes or io.BytesIO")
elif name:
self._buffer = BytesIO(b"")
self._buffer.name = name

@property
def write_buffer(self) -> BytesIO:
Expand Down Expand Up @@ -164,7 +167,7 @@ def read_buffer(self) -> BytesIO:
content = b""
name = None
if self._attachment:
content = self._attachment.raw
content = self._attachment.raw or b""
name = self._attachment.name
self._buffer = BytesIO(content)
self._buffer.name = name
Expand Down
7 changes: 7 additions & 0 deletions fs_file/readme/newsfragments/341.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
Fixes the creation of empty files.

Before this change, the creation of empty files resulted in a constraint
violation error. This was due to the fact that even if a name was given
to the file it was not preserved into the FSFileValue object if no content
was given. As result, when the corresponding ir.attachment was created in
the database, the name was not set and the 'required' constraint was violated.
2 changes: 1 addition & 1 deletion fs_file/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Fs File</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:e85a98065914bf2696dd3d083e4b5eab6b9d91d8c3ce69ba63cb5abef93587f7
!! source digest: sha256:ba969b14fbeee8a8a16e0297d2468467a7140cb7a51b84281269f8ee5137ae2b
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/storage/tree/16.0/fs_file"><img alt="OCA/storage" src="https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_file"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/storage&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon defines a new field type <cite>FSFile</cite> which is a file field that stores
Expand Down
15 changes: 15 additions & 0 deletions fs_file/tests/test_fs_file.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,21 @@ def test_write_with_io(self):
self.assertTrue(isinstance(instance.fs_file, FSFileValue))
self.assertEqual(instance.fs_file.getvalue(), b"test3")

def test_create_with_empty_value(self):
instance = self.env["test.model"].create(
{"fs_file": FSFileValue(name=self.filename, value=b"")}
)
self.assertEqual(instance.fs_file.getvalue(), b"")
self.assertEqual(instance.fs_file.name, self.filename)

def test_write_with_empty_value(self):
instance = self.env["test.model"].create(
{"fs_file": FSFileValue(name=self.filename, value=self.create_content)}
)
instance.write({"fs_file": FSFileValue(name=self.filename, value=b"")})
self.assertEqual(instance.fs_file.getvalue(), b"")
self.assertEqual(instance.fs_file.name, self.filename)

def test_modify_fsfilebytesio(self):
"""If you modify the content of the FSFileValue,
the changes will be directly applied
Expand Down
2 changes: 1 addition & 1 deletion fs_image/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Fs Image
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:12aa6d80ddfd410f208443e5310a2f25fff947aa627b08d582649dd2187fa471
!! source digest: sha256:73f0f6a521e4fb7c934a122c5ed688cfe01b0113eb11d560b9440b1eb7b7b58c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.. |badge1| image:: https://img.shields.io/badge/maturity-Alpha-red.png
Expand Down
Empty file.
2 changes: 1 addition & 1 deletion fs_image/static/description/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ <h1 class="title">Fs Image</h1>
!! This file is generated by oca-gen-addon-readme !!
!! changes will be overwritten. !!
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
!! source digest: sha256:12aa6d80ddfd410f208443e5310a2f25fff947aa627b08d582649dd2187fa471
!! source digest: sha256:73f0f6a521e4fb7c934a122c5ed688cfe01b0113eb11d560b9440b1eb7b7b58c
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! -->
<p><a class="reference external image-reference" href="https://odoo-community.org/page/development-status"><img alt="Alpha" src="https://img.shields.io/badge/maturity-Alpha-red.png" /></a> <a class="reference external image-reference" href="http://www.gnu.org/licenses/agpl-3.0-standalone.html"><img alt="License: AGPL-3" src="https://img.shields.io/badge/licence-AGPL--3-blue.png" /></a> <a class="reference external image-reference" href="https://github.com/OCA/storage/tree/16.0/fs_image"><img alt="OCA/storage" src="https://img.shields.io/badge/github-OCA%2Fstorage-lightgray.png?logo=github" /></a> <a class="reference external image-reference" href="https://translation.odoo-community.org/projects/storage-16-0/storage-16-0-fs_image"><img alt="Translate me on Weblate" src="https://img.shields.io/badge/weblate-Translate%20me-F47D42.png" /></a> <a class="reference external image-reference" href="https://runboat.odoo-community.org/builds?repo=OCA/storage&amp;target_branch=16.0"><img alt="Try me on Runboat" src="https://img.shields.io/badge/runboat-Try%20me-875A7B.png" /></a></p>
<p>This addon defines a new field <strong>FSImage</strong> to use in your models. It is a
Expand Down

0 comments on commit a238204

Please sign in to comment.