diff --git a/odoo_self_order_details/__init__.py b/odoo_self_order_details/__init__.py new file mode 100644 index 00000000000..0650744f6bc --- /dev/null +++ b/odoo_self_order_details/__init__.py @@ -0,0 +1 @@ +from . import models diff --git a/odoo_self_order_details/__manifest__.py b/odoo_self_order_details/__manifest__.py new file mode 100644 index 00000000000..029dc21dc7e --- /dev/null +++ b/odoo_self_order_details/__manifest__.py @@ -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' +} diff --git a/odoo_self_order_details/models/__init__.py b/odoo_self_order_details/models/__init__.py new file mode 100644 index 00000000000..b194f4906c9 --- /dev/null +++ b/odoo_self_order_details/models/__init__.py @@ -0,0 +1,2 @@ +from . import product_template +from . import product diff --git a/odoo_self_order_details/models/product.py b/odoo_self_order_details/models/product.py new file mode 100644 index 00000000000..7d22ba14475 --- /dev/null +++ b/odoo_self_order_details/models/product.py @@ -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 diff --git a/odoo_self_order_details/models/product_template.py b/odoo_self_order_details/models/product_template.py new file mode 100644 index 00000000000..bb3b99e86d4 --- /dev/null +++ b/odoo_self_order_details/models/product_template.py @@ -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') diff --git a/odoo_self_order_details/static/src/product_card/product_card.js b/odoo_self_order_details/static/src/product_card/product_card.js new file mode 100644 index 00000000000..cecc7b0f332 --- /dev/null +++ b/odoo_self_order_details/static/src/product_card/product_card.js @@ -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(), + }); + } + } +}); diff --git a/odoo_self_order_details/static/src/product_pop_details/product_pop_details.js b/odoo_self_order_details/static/src/product_pop_details/product_pop_details.js new file mode 100644 index 00000000000..c5d66ad4266 --- /dev/null +++ b/odoo_self_order_details/static/src/product_pop_details/product_pop_details.js @@ -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(); + } +} diff --git a/odoo_self_order_details/static/src/product_pop_details/product_pop_details.xml b/odoo_self_order_details/static/src/product_pop_details/product_pop_details.xml new file mode 100644 index 00000000000..58eeff9ce46 --- /dev/null +++ b/odoo_self_order_details/static/src/product_pop_details/product_pop_details.xml @@ -0,0 +1,27 @@ + + + + + + diff --git a/odoo_self_order_details/views/product_views.xml b/odoo_self_order_details/views/product_views.xml new file mode 100644 index 00000000000..25b129c9668 --- /dev/null +++ b/odoo_self_order_details/views/product_views.xml @@ -0,0 +1,15 @@ + + + + product.template.pos.inherit.view + + product.template + + + + + + + + + \ No newline at end of file