14 changed files with 362 additions and 238 deletions
@ -1,75 +1,57 @@ |
|||||
odoo.define('pos_multi_variant.ProductsPopup', function(require) { |
/** @odoo-module **/ |
||||
'use strict'; |
|
||||
/* This JavaScript code defines the ProductsPopup component, which extends |
|
||||
* the ProductItem class from the point_of_sale module. It represents a popup |
|
||||
* for selecting product variants. |
|
||||
*/ |
|
||||
const Registries = require('point_of_sale.Registries'); |
|
||||
const { useListener } = require("@web/core/utils/hooks"); |
|
||||
const ProductItem = require('point_of_sale.ProductItem'); |
|
||||
|
|
||||
class ProductsPopup extends ProductItem { |
import Registries from 'point_of_sale.Registries'; |
||||
|
import { useListener } from "@web/core/utils/hooks"; |
||||
|
const ProductItem = require('point_of_sale.ProductItem'); |
||||
|
const { useState } = owl; |
||||
|
|
||||
|
|
||||
|
class ProductsPopup extends ProductItem { |
||||
setup() { |
setup() { |
||||
super.setup(); |
super.setup(); |
||||
useListener('click','.confirm', this.click_confirm); |
this.state = useState({ |
||||
useListener('click','.product', this.select_variant); |
variant_details: this.props.variant_details, |
||||
useListener('click','.cancel', this.click_cancel); |
selected_variants: {}, |
||||
|
price_total: {}, |
||||
|
}) |
||||
} |
} |
||||
select_variant(e) { |
|
||||
var order = this.env.pos.get_order() |
SelectVariant(product,variant) { |
||||
var self = e.composedPath ? e.composedPath()[2] : e.path[2]; |
if (this.state.selected_variants[product.attribute_id[1]] === variant.id){ |
||||
var action = $(self).find('.action').text(); |
this.state.selected_variants[product.attribute_id[1]] = false |
||||
var category = $(self).find('.action').data('category'); |
this.state.price_total[product.attribute_id[1]] = 0.0 |
||||
$('.product-img').find('.variant-selected').each(function () |
} |
||||
{ if($(this).data('category') == category) |
else{ |
||||
{ $(this).text("").removeClass('variant-selected'); |
this.state.selected_variants[product.attribute_id[1]] = variant.id |
||||
$(self).find('.action').text("Selected").addClass('variant-selected'); |
this.state.price_total[product.attribute_id[1]] = product.extra_price |
||||
} |
} |
||||
}); |
|
||||
$(self).find('.action').text("Selected").addClass('variant-selected'); |
|
||||
var add = $(self).find('.extra-price').text().substr(1).slice(0, -2); |
|
||||
var type = $(self).find('.variants').text(); |
|
||||
$(self).find('.variant-selected').attr('data-price', add); |
|
||||
$(self).find('.variant-selected').attr('data-type', type); |
|
||||
} |
} |
||||
click_confirm(e){ |
|
||||
var price = 0.00 |
clickConfirm(e){ |
||||
|
const total = Object.values(this.state.price_total).reduce((sum, value) => sum + value, 0); |
||||
var order = this.env.pos.get_order() |
var order = this.env.pos.get_order() |
||||
var selected_orderline = order.get_selected_orderline() |
var selected_orderline = order.get_selected_orderline() |
||||
var variants = [] |
selected_orderline.price += total |
||||
this.env.pos.selectedOrder.selected_orderline.product_variants=variants |
|
||||
$('.product-img').find('.variant-selected').each(function () |
|
||||
{ |
|
||||
var add = this.previousSibling.innerHTML; |
|
||||
add = add.slice(3) |
|
||||
price += parseFloat(add) |
|
||||
if (order.selected_orderline.product.is_pos_variants){ |
|
||||
variants.push({ |
|
||||
'extra_price': add, |
|
||||
'type': $(this).data('type'), |
|
||||
}) |
|
||||
}; |
|
||||
}) |
|
||||
selected_orderline.price_manually_set = true; |
|
||||
selected_orderline.price += price |
|
||||
this.env.posbus.trigger('close-popup', { |
this.env.posbus.trigger('close-popup', { |
||||
popupId: this.props.id |
popupId: this.props.id |
||||
}); |
}); |
||||
} |
} |
||||
click_cancel(){ |
clickCancel(){ |
||||
|
this.env.pos.get_order().orderlines.remove(this.env.pos.get_order().selected_orderline) |
||||
this.env.posbus.trigger('close-popup', { |
this.env.posbus.trigger('close-popup', { |
||||
popupId: this.props.id |
popupId: this.props.id |
||||
}); |
}); |
||||
} |
} |
||||
|
|
||||
imageUrl() { |
imageUrl() { |
||||
return `/web/image?model=product.product&field=image_1920&id=${this.props.product_tmpl_id}&unique=1`; |
return `/web/image?model=product.product&field=image_1920&id=${this.props.product_tmpl_id}&unique=1`; |
||||
} |
} |
||||
async _clickProduct(event) { |
|
||||
} |
getSelected(attr, variant) { |
||||
|
return this.state.selected_variants[attr] === variant.id |
||||
} |
} |
||||
ProductsPopup.template = 'ProductsPopUp'; |
|
||||
ProductsPopup.defaultProps = {}; |
|
||||
Registries.Component.add(ProductsPopup); |
|
||||
return ProductsPopup; |
|
||||
}); |
|
||||
|
|
||||
|
} |
||||
|
ProductsPopup.template = 'ProductsPopUp'; |
||||
|
ProductsPopup.defaultProps = {}; |
||||
|
Registries.Component.add(ProductsPopup); |
||||
|
Loading…
Reference in new issue