Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FIX][16.0] storage_image: use api.model_create_multi instead of api.mode for create methods #2

Open
wants to merge 1 commit into
base: 16.0-mig-storage_image
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 12 additions & 6 deletions storage_image/models/storage_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,11 @@ def onchange_name(self):
for char in ["-", "_"]:
record.alt_name = record.alt_name.replace(char, " ")

@api.model
def create(self, vals):
vals["file_type"] = self._default_file_type
if "backend_id" not in vals:
vals["backend_id"] = self._get_default_backend_id()
return super().create(vals)
@api.model_create_multi
def create(self, vals_list):
for vals in vals_list:
self._pre_process_create(vals)
return super().create(vals_list)

def _get_default_backend_id(self):
return self.env["storage.backend"]._get_backend_id_from_param(
Expand All @@ -58,3 +57,10 @@ def unlink(self):
files = self.mapped("file_id")
thumbnails = self.mapped("thumbnail_ids")
return super().unlink() and thumbnails.unlink() and files.unlink()

@api.model
def _pre_process_create(self, vals):
vals["file_type"] = self._default_file_type
if "backend_id" not in vals:
vals["backend_id"] = self._get_default_backend_id()
return vals