[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
This commit is contained in:
Horacio Tellez (hote)
2023-08-31 09:04:53 +00:00
committed by Valentin Chevalier
parent 24abddacda
commit cf519d2767
6 changed files with 118 additions and 14 deletions
-6
View File
@@ -1078,12 +1078,6 @@ class SaleOrderLine(models.Model):
**self.env.context,
**self._get_action_add_from_catalog_extra_context(order),
},
'help': _("""<p class="o_view_nocontent_smiling_face">
Create a new product
</p><p>
You must define a product for everything you sell or purchase,
whether it's a storable product, a consumable or a service.
</p>"""),
}
#=== BUSINESS METHODS ===#
@@ -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,
});
}
}
}
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="sale.ProductCatalogKanbanController" t-inherit="web.KanbanView" t-inherit-mode="primary">
<xpath expr="//button[hasclass('o-kanban-button-new')]" position="replace">
<button t-out="this.buttonString" type="button" class="btn btn-secondary o-kanban-button-back" t-on-click="this.backToQuotation"/>
</xpath>
</t>
</templates>
@@ -0,0 +1,30 @@
/** @odoo-module **/
import { KanbanRenderer } from "@web/views/kanban/kanban_renderer";
import { useService } from "@web/core/utils/hooks";
import { ProductCatalogKanbanRecord } from "./kanban_record";
export class ProductCatalogKanbanRenderer extends KanbanRenderer {
static template = "sale.ProductCatalogKanbanRenderer";
static components = {
...KanbanRenderer.components,
KanbanRecord: ProductCatalogKanbanRecord
};
setup() {
super.setup();
this.action = useService("action");
}
async createProduct() {
await this.action.doAction({
type: "ir.actions.act_window",
res_model: "product.product",
target: "new",
views: [[false, "form"]],
view_mode: "form",
});
}
}
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="sale.ProductCatalogKanbanRenderer" t-inherit="web.KanbanRenderer" t-inherit-mode="primary">
<t t-if="showNoContentHelper" position="replace">
<t t-if="showNoContentHelper">
<div class="o_view_nocontent" role="alert">
<div class="o_nocontent_help">
<p class="o_view_nocontent_smiling_face">
No products could be found.<br/>
<button class="mt-2 btn btn-primary" t-on-click="this.createProduct">Create a product</button>
</p>
<p>
You must define a product for everything you sell or purchase,
whether it's a storable product, a consumable or a service.
</p>
</div>
</div>
</t>
</t>
</t>
</templates>
@@ -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);