Skip to content

Commit 3aa1ee1

Browse files
committed
[ADD] odoo_self_order_details: new module to improve ux during self order
This commit introduces a ux change and more information in the Self-Order functionality. It changes its default functionality of directly adding product into order when clicking to opening a view to show large image and detailed product description so that users can see more details about product whole view page will be scroll-able allowing to configure product depending on their options available Addition of cancel button in footer for better mobile experience
1 parent eb10d6e commit 3aa1ee1

File tree

7 files changed

+135
-0
lines changed

7 files changed

+135
-0
lines changed

odoo_self_order_details/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import models
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
"name": "Self Order Details",
3+
"description": """
4+
Self order details for products in POS
5+
""",
6+
"author": "Ayush Patel",
7+
"version": "0.1",
8+
"application": True,
9+
"installable": True,
10+
"depends": ["pos_self_order"],
11+
"license": "LGPL-3",
12+
"assets": {
13+
"pos_self_order.assets": [
14+
"odoo_self_order_details/static/src/**/*",
15+
],
16+
},
17+
"data": [
18+
"views/product_template_view.xml",
19+
],
20+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import product_template
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from odoo import fields, models
2+
3+
4+
class ProductTemplate(models.Model):
5+
_inherit = "product.template"
6+
7+
self_order_description = fields.Html(string="Self-Order Description")
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
import { patch } from "@web/core/utils/patch";
2+
import { ProductCard } from "@pos_self_order/app/components/product_card/product_card";
3+
import { ProductPage } from "@pos_self_order/app/pages/product_page/product_page";
4+
import { markup } from "@odoo/owl";
5+
6+
// Patch ProductCard to always navigate to the product page on selection,
7+
// enabling display of self_order_description and large image for all products.
8+
patch(ProductCard.prototype, {
9+
async selectProduct(qty = 1) {
10+
const product = this.props.product;
11+
12+
if (!product.self_order_available || !this.isAvailable) {
13+
return;
14+
}
15+
16+
// For combo products, we use the default behavior
17+
if (product.isCombo()) {
18+
return super.selectProduct(qty);
19+
}
20+
21+
// For other products, navigate to the product page
22+
this.router.navigate("product", { id: product.id });
23+
}
24+
});
25+
26+
// Patch ProductPage component to fetch and display self_order_description
27+
patch(ProductPage.prototype, {
28+
async setup() {
29+
// call the original setup method to ensure the component is initialized properly
30+
super.setup();
31+
32+
// This ensures that the product's self_order_description is fetched
33+
const product = this.props.product;
34+
if (product && !product.self_order_description) {
35+
try {
36+
const orm = this.env.services.orm;
37+
// orm.read() returns all fields of product.product, including those added by other modules via _inherit = "product.product".
38+
const [record] = await orm.read("product.product",[product.id]);
39+
if (record && record.self_order_description) {
40+
// markup is used to safely render HTML content
41+
product.self_order_description = markup(record.self_order_description);
42+
}
43+
} catch (err) {
44+
console.error("Failed to fetch self_order_description via ORM:", err);
45+
}
46+
}
47+
},
48+
});
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<templates xml:space="preserve">
3+
<!--Inheriting ProductPage and defining our changes-->
4+
<t t-inherit="pos_self_order.ProductPage" t-inherit-mode="extension">
5+
<!--'options' string after product name only when Product is Configurable -->
6+
<xpath expr="//h1[@class='mb-0 text-nowrap']" position="replace">
7+
<h1 class="mb-0 text-nowrap"><strong t-out="product.name"/> <span t-if="product.isConfigurable()">options</span></h1>
8+
</xpath>
9+
<!-- changes in product details section to have a new layout with a large image and description -->
10+
<xpath expr="//div[hasclass('o-so-product-details')]" position="replace">
11+
<div class="o-so-product-details d-flex flex-column align-items-center p-3 gap-3">
12+
<!-- Large Product Image -->
13+
<div class="o-so-product-details-image text-center mb-3" style="max-width: 300px;">
14+
<img
15+
class="img-fluid rounded shadow-sm"
16+
t-attf-src="/web/image/product.product/{{ product.id }}/image_512"
17+
alt="Product image"
18+
loading="lazy"/>
19+
</div>
20+
21+
<!-- Product related Information -->
22+
<div class="o-so-product-details-description text-center w-100">
23+
<h2 t-out="product.name"/>
24+
<span class="fs-3 d-block my-3" t-out="selfOrder.formatMonetary(selfOrder.getProductDisplayPrice(product))"/>
25+
</div>
26+
27+
<!-- Product Description -->
28+
<div class="o-so-product-details-description text-center w-100">
29+
<t t-if="product.self_order_description">
30+
<div t-out="product.self_order_description"/>
31+
</t>
32+
</div>
33+
</div>
34+
</xpath>
35+
36+
<!--Cancel button next to the Add to cart button -->
37+
<xpath expr="//div[hasclass('page-buttons')]/button[hasclass('btn-primary')]" position="before">
38+
<button class="btn btn-secondary btn-lg" t-on-click="() => router.back()">
39+
Cancel
40+
</button>
41+
</xpath>
42+
</t>
43+
</templates>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<odoo>
3+
<!--Configures self order description field in 'point of sale' page of product form view-->
4+
<record id="product_template_form_view_inherit_self_order" model="ir.ui.view">
5+
<field name="name">product.template.form.inherit.self.order</field>
6+
<field name="model">product.template</field>
7+
<field name="inherit_id" ref="product.product_template_form_view"/>
8+
<field name="arch" type="xml">
9+
<!-- This XPath targets the 'Point of Sale' page and the 'Point of Sale' group inside it -->
10+
<xpath expr="//page[@name='pos']//group[@name='pos']" position="inside">
11+
<field name="self_order_description"/>
12+
</xpath>
13+
</field>
14+
</record>
15+
</odoo>

0 commit comments

Comments
 (0)