From e3fe2b01f1baa15d6349d3dfbcad1ea3e84add2d Mon Sep 17 00:00:00 2001 From: Valentin Chevalier Date: Mon, 9 Oct 2023 10:39:35 +0200 Subject: [PATCH] [IMP] web,sale: allow selection widget in kanban view Currently, users who want to change the visibility of product's documents need to open their form view and edit it. The selection widget now allows users to quickly edit the way a document is displayed to their customers from the product's documents kanban view. Part-of: odoo/odoo#137975 --- .../product_document_kanban_record.js | 4 +- .../product_document_kanban_view.scss | 3 + .../product/views/product_document_views.xml | 14 +- addons/sale/views/product_document_views.xml | 12 +- .../views/fields/selection/selection_field.js | 20 ++- .../fields/selection/selection_field.xml | 6 +- .../views/fields/selection_field_tests.js | 155 ++++++++++++++++++ 7 files changed, 191 insertions(+), 23 deletions(-) create mode 100644 addons/product/static/src/js/product_document_kanban/product_document_kanban_view.scss diff --git a/addons/product/static/src/js/product_document_kanban/product_document_kanban_record.js b/addons/product/static/src/js/product_document_kanban/product_document_kanban_record.js index e32872a2ce5..bc13c1b6428 100644 --- a/addons/product/static/src/js/product_document_kanban/product_document_kanban_record.js +++ b/addons/product/static/src/js/product_document_kanban/product_document_kanban_record.js @@ -7,7 +7,7 @@ import { useFileViewer } from "@web/core/file_viewer/file_viewer_hook"; export class ProductDocumentKanbanRecord extends KanbanRecord { setup() { super.setup(); - this.attachmentService = useService("mail.attachment"); + this.store = useService("mail.store"); this.fileViewer = useFileViewer(); } /** @@ -19,7 +19,7 @@ export class ProductDocumentKanbanRecord extends KanbanRecord { if (ev.target.closest(CANCEL_GLOBAL_CLICK)) { return; } else if (ev.target.closest(".o_kanban_previewer")) { - const attachment = this.attachmentService.insert({ + const attachment = this.store.Attachment.insert({ id: this.props.record.data.ir_attachment_id[0], filename: this.props.record.data.name, name: this.props.record.data.name, diff --git a/addons/product/static/src/js/product_document_kanban/product_document_kanban_view.scss b/addons/product/static/src/js/product_document_kanban/product_document_kanban_view.scss new file mode 100644 index 00000000000..06450ecc2e4 --- /dev/null +++ b/addons/product/static/src/js/product_document_kanban/product_document_kanban_view.scss @@ -0,0 +1,3 @@ +.o_kanban_previewer:hover { + cursor: pointer; +} diff --git a/addons/product/views/product_document_views.xml b/addons/product/views/product_document_views.xml index ac26b2b480e..8ca09d34b57 100644 --- a/addons/product/views/product_document_views.xml +++ b/addons/product/views/product_document_views.xml @@ -50,7 +50,7 @@ Download -
+
Archived
@@ -69,16 +69,12 @@
-
+
-
- - -
- -
-
+
diff --git a/addons/sale/views/product_document_views.xml b/addons/sale/views/product_document_views.xml index aee080986af..77854a86f60 100644 --- a/addons/sale/views/product_document_views.xml +++ b/addons/sale/views/product_document_views.xml @@ -19,12 +19,12 @@ product.document - - - Visible at - - - +
+
+ Visible at + +
+
diff --git a/addons/web/static/src/views/fields/selection/selection_field.js b/addons/web/static/src/views/fields/selection/selection_field.js index 69d1801728b..8c8f269990c 100644 --- a/addons/web/static/src/views/fields/selection/selection_field.js +++ b/addons/web/static/src/views/fields/selection/selection_field.js @@ -13,6 +13,10 @@ export class SelectionField extends Component { placeholder: { type: String, optional: true }, required: { type: Boolean, optional: true }, domain: { type: Array, optional: true }, + autosave: { type: Boolean, optional: true }, + }; + static defaultProps = { + autosave: false, }; setup() { @@ -68,15 +72,15 @@ export class SelectionField extends Component { switch (this.type) { case "many2one": if (value === false) { - this.props.record.update({ [this.props.name]: false }); + this.props.record.update({ [this.props.name]: false }, { save: this.props.autosave }); } else { this.props.record.update({ [this.props.name]: this.options.find((option) => option[0] === value), - }); + }, { save: this.props.autosave }); } break; case "selection": - this.props.record.update({ [this.props.name]: value }); + this.props.record.update({ [this.props.name]: value }, { save: this.props.autosave }); break; } } @@ -87,13 +91,19 @@ export const selectionField = { displayName: _t("Selection"), supportedTypes: ["many2one", "selection"], isEmpty: (record, fieldName) => record.data[fieldName] === false, - extractProps({ attrs }, dynamicInfo) { - return { + extractProps({ attrs, viewType }, dynamicInfo) { + const props = { + autosave: viewType === "kanban", placeholder: attrs.placeholder, required: dynamicInfo.required, domain: dynamicInfo.domain(), }; + if (viewType === "kanban") { + props.readonly = dynamicInfo.readonly; + }; + return props; }, }; registry.category("fields").add("selection", selectionField); +registry.category("fields").add("kanban.selection", selectionField); diff --git a/addons/web/static/src/views/fields/selection/selection_field.xml b/addons/web/static/src/views/fields/selection/selection_field.xml index a2ab2e9910a..31f81467f41 100644 --- a/addons/web/static/src/views/fields/selection/selection_field.xml +++ b/addons/web/static/src/views/fields/selection/selection_field.xml @@ -6,7 +6,11 @@ -