Skip to content
Merged
Show file tree
Hide file tree
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
20 changes: 12 additions & 8 deletions dms/controllers/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import unicodedata

from odoo import http
from odoo.exceptions import AccessError
from odoo.exceptions import AccessError, ValidationError
from odoo.http import request

from odoo.addons.web.controllers.binary import clean
Expand Down Expand Up @@ -42,13 +42,15 @@ def upload_dms_file(self, ufile, directory_id, callback=None):
# we need to send it the same stuff, otherwise it'll fail
filename = unicodedata.normalize("NFD", ufile.filename)
try:
dms_file = Model.create(
{
"directory_id": directory_id,
"name": filename,
"content": base64.b64encode(ufile.read()),
}
)
with request.env.cr.savepoint():
dms_file = Model.create(
{
"directory_id": directory_id,
"name": filename,
"content": base64.b64encode(ufile.read()),
}
)
dms_file.flush_recordset()
except AccessError:
args.append(
{
Expand All @@ -57,6 +59,8 @@ def upload_dms_file(self, ufile, directory_id, callback=None):
)
}
)
except ValidationError as error:
args.append({"error": error.args[0]})
except Exception:
args.append({"error": request.env._("Something horrible happened")})
else:
Expand Down
9 changes: 7 additions & 2 deletions dms/static/src/js/views/dms_file_upload.esm.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,13 @@ export function createFileUploadExtension() {
"text"
);
const result = JSON.parse(fileData);
if (result.error) {
throw new Error(result.error);
for (const result_item of result) {
if (result_item.error) {
this.notification.add(result_item.error, {
type: "danger",
sticky: true,
});
}
}
self.actionService.restore(controllerID);
},
Expand Down
Loading