feat(pos): enhance product kit price handling and UI interaction

- Updated price aggregation logic in update_product_kit to include unit prices.
- Improved terminal.js to allow inline editing of product prices in the kit.
- Added parsePrice function for consistent price parsing across the application.
- Ensured that the correct price is saved when creating or updating product kits.
This commit is contained in:
2026-01-27 11:31:22 +03:00
parent 2dc397b3ce
commit 2aed6f60e5
3 changed files with 93 additions and 22 deletions

View File

@@ -748,6 +748,16 @@
// Кэш цен товаров для быстрого доступа
const priceCache = {};
function parsePrice(value) {
if (value === null || value === undefined) {
return 0;
}
if (typeof value === 'string') {
return parseFloat(value.replace(',', '.')) || 0;
}
return parseFloat(value) || 0;
}
// Функция для получения цены товара с AJAX если необходимо
async function getProductPrice(selectElement) {
// Строгая проверка: нужен валидный element с value
@@ -765,7 +775,7 @@
// Если уже загружена в кэш - возвращаем
if (priceCache[productId] !== undefined) {
const cachedPrice = parseFloat(priceCache[productId]) || 0;
const cachedPrice = parsePrice(priceCache[productId]);
console.log('getProductPrice: from cache', productId, cachedPrice);
return cachedPrice;
}
@@ -776,7 +786,7 @@
const formPrice = form.getAttribute('data-product-price');
const formProductId = form.getAttribute('data-product-id');
if (formPrice && productId.toString() === formProductId) {
const price = parseFloat(formPrice) || 0;
const price = parsePrice(formPrice);
if (price > 0) {
priceCache[productId] = price;
console.log('getProductPrice: from form data', productId, price);
@@ -789,7 +799,7 @@
const selectedOption = $(selectElement).find('option:selected');
let priceData = selectedOption.data('actual_price') || selectedOption.data('price');
if (priceData) {
const price = parseFloat(priceData) || 0;
const price = parsePrice(priceData);
if (price > 0) {
priceCache[productId] = price;
console.log('getProductPrice: from select2 data', productId, price);
@@ -808,7 +818,7 @@
const data = await response.json();
if (data.results && data.results.length > 0) {
const productData = data.results[0];
const price = parseFloat(productData.actual_price || productData.price || 0);
const price = parsePrice(productData.actual_price || productData.price || 0);
if (price > 0) {
priceCache[productId] = price;
console.log('getProductPrice: from API', productId, price);
@@ -868,7 +878,7 @@
// Если уже загружена в кэш - возвращаем
const cacheKey = `variant_${variantGroupId}`;
if (priceCache[cacheKey] !== undefined) {
const cachedPrice = parseFloat(priceCache[cacheKey]) || 0;
const cachedPrice = parsePrice(priceCache[cacheKey]);
console.log('getVariantGroupPrice: from cache', variantGroupId, cachedPrice);
return cachedPrice;
}
@@ -877,7 +887,7 @@
const selectedOption = $(selectElement).find('option:selected');
let priceData = selectedOption.data('actual_price') || selectedOption.data('price');
if (priceData) {
const price = parseFloat(priceData) || 0;
const price = parsePrice(priceData);
if (price > 0) {
priceCache[cacheKey] = price;
console.log('getVariantGroupPrice: from select2 data', variantGroupId, price);
@@ -896,7 +906,7 @@
const data = await response.json();
if (data.results && data.results.length > 0) {
const variantData = data.results[0];
const price = parseFloat(variantData.actual_price || variantData.price || 0);
const price = parsePrice(variantData.actual_price || variantData.price || 0);
if (price > 0) {
priceCache[cacheKey] = price;
console.log('getVariantGroupPrice: from API', variantGroupId, price);
@@ -940,7 +950,7 @@
// Если уже загружена в кэш - возвращаем
const cacheKey = `sales_unit_${salesUnitId}`;
if (priceCache[cacheKey] !== undefined) {
const cachedPrice = parseFloat(priceCache[cacheKey]) || 0;
const cachedPrice = parsePrice(priceCache[cacheKey]);
return cachedPrice;
}
@@ -949,7 +959,7 @@
if (selectedOption) {
let priceData = selectedOption.dataset.actual_price || selectedOption.dataset.price;
if (priceData) {
const price = parseFloat(priceData) || 0;
const price = parsePrice(priceData);
if (price > 0) {
priceCache[cacheKey] = price;
console.log('getSalesUnitPrice: from standard select option data', salesUnitId, price);
@@ -966,7 +976,7 @@
const itemData = selectedData[0];
const priceData = itemData.actual_price || itemData.price;
if (priceData) {
const price = parseFloat(priceData) || 0;
const price = parsePrice(priceData);
if (price > 0) {
priceCache[cacheKey] = price;
console.log('getSalesUnitPrice: from select2 data', salesUnitId, price);
@@ -988,7 +998,7 @@
if (data.sales_units && data.sales_units.length > 0) {
const salesUnitData = data.sales_units.find(su => su.id == salesUnitId);
if (salesUnitData) {
const price = parseFloat(salesUnitData.actual_price || salesUnitData.price || 0);
const price = parsePrice(salesUnitData.actual_price || salesUnitData.price || 0);
if (price > 0) {
priceCache[cacheKey] = price;
console.log('getSalesUnitPrice: from API', salesUnitId, price);