mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 02:08:36 +00:00
Merge pull request #246 from grindtildeath/12.0-fix-base_fileurl_field_demo_test
[12.0] base_fileurl_field: Consider test mode and installation of demo data
This commit is contained in:
@@ -3,6 +3,7 @@
|
||||
import unicodedata
|
||||
|
||||
from odoo import fields
|
||||
from odoo.tools import config
|
||||
|
||||
|
||||
fields.Field.__doc__ += """
|
||||
@@ -35,6 +36,7 @@ class FileURL(fields.Binary):
|
||||
'filename': '', # Field to use to store the filename on ir.attachment
|
||||
}
|
||||
|
||||
# pylint: disable=method-required-super
|
||||
def create(self, record_values):
|
||||
assert self.attachment
|
||||
if not record_values:
|
||||
@@ -63,7 +65,7 @@ class FileURL(fields.Binary):
|
||||
storage_key = False
|
||||
env['ir.attachment'].sudo().with_context(
|
||||
binary_field_real_user=env.user,
|
||||
storage_location=self.storage_location,
|
||||
storage_location=self._storage_location(),
|
||||
force_storage_key=storage_key,
|
||||
).create(vals)
|
||||
|
||||
@@ -76,24 +78,34 @@ class FileURL(fields.Binary):
|
||||
storage_key = self._build_storage_key(fname)
|
||||
super().write(
|
||||
records.with_context(
|
||||
storage_location=self.storage_location,
|
||||
storage_location=self._storage_location(),
|
||||
force_storage_key=storage_key,
|
||||
),
|
||||
value
|
||||
value,
|
||||
)
|
||||
return True
|
||||
|
||||
def _setup_regular_base(self, model):
|
||||
super()._setup_regular_base(model)
|
||||
if self.storage_path:
|
||||
assert self.filename is not None, \
|
||||
assert self.filename is not None, (
|
||||
"Field %s defines storage_path without filename" % self
|
||||
)
|
||||
|
||||
def _build_storage_key(self, filename):
|
||||
return '/'.join([
|
||||
self.storage_path.rstrip('/'),
|
||||
unicodedata.normalize('NFKC', filename)
|
||||
])
|
||||
return '/'.join(
|
||||
[
|
||||
self.storage_path.rstrip('/'),
|
||||
unicodedata.normalize('NFKC', filename),
|
||||
]
|
||||
)
|
||||
|
||||
def _storage_location(self):
|
||||
# Avoid pushing to s3 in test mode or installation of demo data
|
||||
force_file_storage = (
|
||||
config['test_enable'] or config['init'] and config['demo']
|
||||
)
|
||||
return 'file' if force_file_storage else self.storage_location
|
||||
|
||||
|
||||
fields.FileURL = FileURL
|
||||
|
||||
Reference in New Issue
Block a user