Skip to content

Commit 091d58a

Browse files
[MIG] attachment_preview: Migration to 19.0
1 parent 6abfa09 commit 091d58a

9 files changed

Lines changed: 22 additions & 23 deletions

File tree

attachment_preview/__manifest__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
{
55
"name": "Preview attachments",
6-
"version": "18.0.1.0.0",
7-
"author": "Therp BV," "Onestein," "Odoo Community Association (OCA)",
6+
"version": "19.0.1.0.0",
7+
"author": "Therp BV,Onestein,Odoo Community Association (OCA)",
88
"website": "https://github.com/OCA/knowledge",
99
"license": "AGPL-3",
1010
"summary": "Preview attachments supported by Viewer.js",

attachment_preview/models/ir_attachment.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,13 @@ def get_binary_extension(self, model, ids, binary_field, filename_field=None):
7676
def get_attachment_extension(self, ids):
7777
return self.get_binary_extension(self._name, ids, "datas", "name")
7878

79-
def _to_store(self, store: Store, /, *, fields=None, extra_fields=None):
80-
"""Adds extension in Store for attachments"""
81-
res = super()._to_store(store=store, fields=fields, extra_fields=extra_fields)
82-
attachment_extension = self.get_attachment_extension(self.ids)
83-
for attachment in store.data.get("ir.attachment"):
84-
store.data["ir.attachment"][attachment]["extension"] = (
85-
attachment_extension.get(attachment[0], "")
79+
def _to_store_defaults(self, target):
80+
"""Adds extension in Store defaults for attachments"""
81+
defaults = super()._to_store_defaults(target)
82+
defaults.append(
83+
Store.Attr(
84+
"extension",
85+
lambda a: a.get_attachment_extension(a.id),
8686
)
87-
return res
87+
)
88+
return defaults

attachment_preview/static/src/js/attachmentPreviewWidget.esm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ export class AttachmentPreviewWidget extends Component {
3535

3636
_onPopoutClick() {
3737
if (!this.attachments[this.state.activeIndex]) return;
38-
// eslint-disable-next-line no-undef
3938
window.open(this.attachments[this.state.activeIndex].previewUrl);
4039
}
4140

attachment_preview/static/src/js/mail_core/attachment_list.esm.js

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import {patch} from "@web/core/utils/patch";
44

55
patch(AttachmentList.prototype, {
66
_onPreviewAttachment(attachment) {
7-
// eslint-disable-next-line no-undef
87
var $target = $(event.currentTarget);
98
var split_screen = $target.attr("data-target") !== "new";
109
showPreview(

attachment_preview/static/src/js/utils.esm.js

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,9 @@ export function getUrl(
2525
var url = "";
2626
if (attachment_url) {
2727
if (attachment_url.slice(0, 21) === "/web/static/lib/pdfjs") {
28-
// eslint-disable-next-line no-undef
2928
url = (window.location.origin || "") + attachment_url;
3029
} else {
3130
url =
32-
// eslint-disable-next-line no-undef
3331
(window.location.origin || "") +
3432
"/attachment_preview/static/lib/ViewerJS/index.html" +
3533
"?type=" +
@@ -38,13 +36,11 @@ export function getUrl(
3836
encodeURIComponent(attachment_title) +
3937
"&zoom=automatic" +
4038
"#" +
41-
// eslint-disable-next-line no-undef
4239
attachment_url.replace(window.location.origin, "");
4340
}
4441
return url;
4542
}
4643
url =
47-
// eslint-disable-next-line no-undef
4844
(window.location.origin || "") +
4945
"/attachment_preview/static/lib/ViewerJS/index.html" +
5046
"?type=" +
@@ -74,7 +70,6 @@ export function showPreview(
7470
attachment_info_list,
7571
});
7672
} else {
77-
// eslint-disable-next-line no-undef
7873
window.open(
7974
getUrl(
8075
attachment_id,

attachment_preview/static/src/js/viewerjs_tweaks.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,11 @@
55
// OpenERP's context
66
(function (original_Viewer) {
77
"use strict";
8-
// eslint-disable-next-line no-undef
98
window.Viewer = function (plugin, parameters) {
109
if (!plugin) {
11-
// eslint-disable-next-line no-undef, no-alert
10+
// eslint-disable-next-line no-alert
1211
alert("Unsupported file type");
1312
}
1413
return original_Viewer(plugin, parameters);
1514
};
16-
// eslint-disable-next-line no-undef
1715
})(window.Viewer);

attachment_preview/static/src/scss/attachment_preview.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
background-color: #fff;
66
border-left: 1px solid $gray-800;
77
}
8-
@include media-breakpoint-up(xxl, $o-extra-grid-breakpoints) {
8+
@include media-breakpoint-up(xxl) {
99
.attachment_preview_widget {
1010
position: absolute;
1111
left: 65.3%;
@@ -20,7 +20,7 @@
2020
border-left: 1px solid $gray-800;
2121
}
2222
}
23-
@include media-breakpoint-down(xxl, $o-extra-grid-breakpoints) {
23+
@include media-breakpoint-down(xxl) {
2424
.attachment_preview_iframe {
2525
width: 100%;
2626
}

attachment_preview/tests/test_attachment_preview.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def test_get_extension(self):
3030
res = self.env["ir.attachment"].get_attachment_extension(attachment.id)
3131
self.assertEqual(res, "txt")
3232
store = Store()
33-
attachment._to_store(store)
33+
store.add(attachment)
3434
store_data = store.get_result()
3535
self.assertIn("extension", store_data["ir.attachment"][0])
3636
res = self.env["ir.attachment"].get_attachment_extension(
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
[project]
2+
name = "odoo-addon-attachment_preview"
3+
dynamic = ["version"]
4+
5+
[build-system]
6+
requires = ["whool"]
7+
build-backend = "whool.buildapi"

0 commit comments

Comments
 (0)