mirror of
https://github.com/camptocamp/odoo-cloud-platform.git
synced 2026-06-24 16:48:36 +00:00
base_fileurl_field: Consider test mode and installation of demo data
This commit is contained in:
@@ -3,6 +3,7 @@
|
|||||||
import unicodedata
|
import unicodedata
|
||||||
|
|
||||||
from odoo import fields
|
from odoo import fields
|
||||||
|
from odoo.tools import config
|
||||||
|
|
||||||
|
|
||||||
fields.Field.__doc__ += """
|
fields.Field.__doc__ += """
|
||||||
@@ -63,7 +64,7 @@ class FileURL(fields.Binary):
|
|||||||
storage_key = False
|
storage_key = False
|
||||||
env['ir.attachment'].sudo().with_context(
|
env['ir.attachment'].sudo().with_context(
|
||||||
binary_field_real_user=env.user,
|
binary_field_real_user=env.user,
|
||||||
storage_location=self.storage_location,
|
storage_location=self._storage_location(),
|
||||||
force_storage_key=storage_key,
|
force_storage_key=storage_key,
|
||||||
).create(vals)
|
).create(vals)
|
||||||
|
|
||||||
@@ -76,7 +77,7 @@ class FileURL(fields.Binary):
|
|||||||
storage_key = self._build_storage_key(fname)
|
storage_key = self._build_storage_key(fname)
|
||||||
super().write(
|
super().write(
|
||||||
records.with_context(
|
records.with_context(
|
||||||
storage_location=self.storage_location,
|
storage_location=self._storage_location(),
|
||||||
force_storage_key=storage_key,
|
force_storage_key=storage_key,
|
||||||
),
|
),
|
||||||
value
|
value
|
||||||
@@ -95,5 +96,11 @@ class FileURL(fields.Binary):
|
|||||||
unicodedata.normalize('NFKC', filename)
|
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
|
fields.FileURL = FileURL
|
||||||
|
|||||||
Reference in New Issue
Block a user