From cf519d27673c8f378d7c8e6472c2986ed5f966e8 Mon Sep 17 00:00:00 2001 From: "Horacio Tellez (hote)" Date: Thu, 24 Aug 2023 13:46:19 +0200 Subject: [PATCH] [IMP] sale: add back button Preparing the sales catalog to odoo 17 release: - some functional additions/improvements: - adding a button "Back to Quotation" to ease the navigation, - make the "empty" help message more friendly and add a button to directly create a product, task-3367295 Part-of: odoo/odoo#126796 --- addons/sale/models/sale_order_line.py | 6 --- .../js/product_catalog/kanban_controller.js | 48 +++++++++++++++++++ .../js/product_catalog/kanban_controller.xml | 8 ++++ .../src/js/product_catalog/kanban_renderer.js | 30 ++++++++++++ .../js/product_catalog/kanban_renderer.xml | 22 +++++++++ .../src/js/product_catalog/kanban_view.js | 18 +++---- 6 files changed, 118 insertions(+), 14 deletions(-) create mode 100644 addons/sale/static/src/js/product_catalog/kanban_controller.js create mode 100644 addons/sale/static/src/js/product_catalog/kanban_controller.xml create mode 100644 addons/sale/static/src/js/product_catalog/kanban_renderer.js create mode 100644 addons/sale/static/src/js/product_catalog/kanban_renderer.xml diff --git a/addons/sale/models/sale_order_line.py b/addons/sale/models/sale_order_line.py index 9fccf03fc82..416a036a85f 100644 --- a/addons/sale/models/sale_order_line.py +++ b/addons/sale/models/sale_order_line.py @@ -1078,12 +1078,6 @@ class SaleOrderLine(models.Model): **self.env.context, **self._get_action_add_from_catalog_extra_context(order), }, - 'help': _("""

- Create a new product -

- You must define a product for everything you sell or purchase, - whether it's a storable product, a consumable or a service. -

"""), } #=== BUSINESS METHODS ===# diff --git a/addons/sale/static/src/js/product_catalog/kanban_controller.js b/addons/sale/static/src/js/product_catalog/kanban_controller.js new file mode 100644 index 00000000000..9a66fcaa5ab --- /dev/null +++ b/addons/sale/static/src/js/product_catalog/kanban_controller.js @@ -0,0 +1,48 @@ +/** @odoo-module **/ + +import { KanbanController } from "@web/views/kanban/kanban_controller"; +import { onWillStart } from "@odoo/owl"; +import { useService } from "@web/core/utils/hooks"; + + +export class ProductCatalogKanbanController extends KanbanController { + static template = "sale.ProductCatalogKanbanController"; + + setup() { + super.setup(); + this.action = useService("action"); + this.orm = useService("orm"); + this.orderId = this.props.context.order_id; + + onWillStart(async () => { + // Define the content of the button. + const orderStateInfo = await this.orm.searchRead( + "sale.order", [["id", "=", this.orderId]], ["state"] + ); + const orderIsQuotation = ["draft", "sent"].includes(orderStateInfo[0].state); + this.buttonString = `Back to ${orderIsQuotation ? "Quotation" : "Order"}` + }) + } + + // Force the slot for the "Back to Quotation" button to always be shown. + get canCreate() { + return true; + } + + async backToQuotation() { + // Restore the last form view from the breadcrumbs if breadcrumbs are available. + // If, for some weird reason, the user reloads the page then the breadcrumbs are + // lost, and we fall back to the form view ourselves. + if (this.env.config.breadcrumbs.length > 1) { + await this.action.restore(); + } else { + await this.action.doAction({ + type: "ir.actions.act_window", + res_model: "sale.order", + views: [[false, "form"]], + view_mode: "form", + res_id: this.orderId, + }); + } + } +} diff --git a/addons/sale/static/src/js/product_catalog/kanban_controller.xml b/addons/sale/static/src/js/product_catalog/kanban_controller.xml new file mode 100644 index 00000000000..3b97e40ed5d --- /dev/null +++ b/addons/sale/static/src/js/product_catalog/kanban_controller.xml @@ -0,0 +1,8 @@ + + + + + +

+

+ You must define a product for everything you sell or purchase, + whether it's a storable product, a consumable or a service. +

+ + +
+ + +
diff --git a/addons/sale/static/src/js/product_catalog/kanban_view.js b/addons/sale/static/src/js/product_catalog/kanban_view.js index 689a7f9266a..8756f7bb4f7 100644 --- a/addons/sale/static/src/js/product_catalog/kanban_view.js +++ b/addons/sale/static/src/js/product_catalog/kanban_view.js @@ -1,18 +1,20 @@ /** @odoo-module **/ -import { registry } from "@web/core/registry"; -import { KanbanRenderer } from "@web/views/kanban/kanban_renderer"; -import { kanbanView } from "@web/views/kanban/kanban_view"; -import { ProductCatalogKanbanModel } from "./kanban_model"; -import { ProductCatalogKanbanRecord } from "./kanban_record"; -export class ProductCatalogKanbanRenderer extends KanbanRenderer { - static components = {...KanbanRenderer.components, KanbanRecord: ProductCatalogKanbanRecord}; -} +import { kanbanView } from "@web/views/kanban/kanban_view"; +import { registry } from "@web/core/registry"; + +import { ProductCatalogKanbanController } from "./kanban_controller"; +import { ProductCatalogKanbanModel } from "./kanban_model"; +import { ProductCatalogKanbanRenderer } from "./kanban_renderer"; +import { ProductCatalogSearchPanel} from "./search_panel"; + export const productCatalogKanbanView = { ...kanbanView, + Controller: ProductCatalogKanbanController, Model: ProductCatalogKanbanModel, Renderer: ProductCatalogKanbanRenderer, + SearchPanel: ProductCatalogSearchPanel, }; registry.category("views").add("sale_product_kanban", productCatalogKanbanView);