Skip to content

[ADD] odoo_self_order_details: Added a pop-up in pos_self_order #837

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 2 commits into
base: 18.0
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions odoo_self_order_details/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from . import models
17 changes: 17 additions & 0 deletions odoo_self_order_details/__manifest__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
'name': "Sale Order POS",
'category': 'pos_restaurant',
'version': '0.1',
'depends': ['pos_restaurant', 'pos_self_order'],
'sequence': 1,
'application': True,
'installable': True,
'data': [
"views/product_views.xml",
],
"assets": {
"pos_self_order.assets":
["odoo_self_order_details/static/src/**/*"],
},
'license': 'AGPL-3'
}
2 changes: 2 additions & 0 deletions odoo_self_order_details/models/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from . import product_template
from . import product
10 changes: 10 additions & 0 deletions odoo_self_order_details/models/product.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
from odoo import models


class ProductProduct(models.Model):
_inherit = "product.product"

def _load_pos_data_fields(self, config_id):
params = super()._load_pos_data_fields(config_id)
params.append('self_order_description')
return params
7 changes: 7 additions & 0 deletions odoo_self_order_details/models/product_template.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
from odoo import fields, models


class ProductTemplate(models.Model):
_inherit = 'product.template'

self_order_description = fields.Html(string='Self Product Description')
37 changes: 37 additions & 0 deletions odoo_self_order_details/static/src/product_card/product_card.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import { patch } from "@web/core/utils/patch";
import { ProductCard } from '@pos_self_order/app/components/product_card/product_card';
import { ProductPopDetails } from '../product_pop_details/product_pop_details';

patch(ProductCard.prototype,{
async selectProduct(qty = 1) {
const product = this.props.product;
if (!product.self_order_available || !this.isAvailable) {
return;
}

if (product.isCombo()) {
this.router.navigate("combo_selection", { id: product.id });
} else if (product.isConfigurable()) {
this.router.navigate("product", { id: product.id });
} else {
this.dialog.add(ProductPopDetails, {
product: product,
addToCart: (qty) => {
this.flyToCart();
this.scaleUpPrice();

const isProductInCart = this.selfOrder.currentOrder.lines.find(
(line) => line.product_id === product.id
);

if (isProductInCart) {
isProductInCart.qty += qty;
} else {
this.selfOrder.addToCart(product, qty);
}
},
close: () => this.dialog.close(),
});
}
}
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { Component,useState,useExternalListener,markup } from "@odoo/owl";

export class ProductPopDetails extends Component {
static template = "odoo_self_order_details.ProductPopDetails";
static props = ["product", "addToCart", "close"];

setup() {
this.self_order_description = markup(this.props.product.self_order_description || '');
useExternalListener(window, "click", this.props.close);
this.state = useState({
qty: 1,
});
}

addToCartAndClose() {
this.props.addToCart(this.state.qty);
this.props.close();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<templates id="template" xml:space="preserve">
<t t-name="odoo_self_order_details.ProductPopDetails">
<div class="modal d-block">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button class="btn-close" t-on-click="props.close"/>
</div>
<div class="modal-body text-center">
<img t-if="props.product.id"
t-attf-src="/web/image/product.product/{{props.product.id}}/image_1024?unique={{props.product.write_date}}"
alt="Product Image"
class="img-fluid rounded w-75 mb-3"
onerror="this.style.display='none'"/>
<h5 class="modal-title fw-bold" t-esc="props.product.display_name"/>
<h5 t-out="self_order_description"/>
</div>
<div class="modal-footer d-flex justify-content-between">
<button class="btn btn-success flex-fill me-2" t-on-click="addToCartAndClose">Order</button>
<button class="btn btn-danger flex-fill ms-2" t-on-click="props.close">Cancel</button>
</div>
</div>
</div>
</div>
</t>
</templates>
15 changes: 15 additions & 0 deletions odoo_self_order_details/views/product_views.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<odoo>
<record id="product_template_pos_inherit_view" model="ir.ui.view">
<field name="name">product.template.pos.inherit.view</field>
<field name="inherit_id" ref="product.product_template_only_form_view"/>
<field name="model">product.template</field>
<field name="arch" type="xml">
<xpath expr="//page//group[@name='public_description']" position="after">
<group name="self_product_description" string="Self Product Description">
<field name="self_order_description" nolabel="1"/>
</group>
</xpath>
</field>
</record>
</odoo>