Qu factor purchase to stock & Product Barcode Details (#801)

* Puchase add qu_factor_to_stock

* qu_factor_purchase_to_stock for stock edit

* product barcodes with QU and Stores

* remove product barcode tags

* migrations/0103 add value and factor_puchase_amount to stock_current and stock_current_location_content

* Remove unused method

* StockService#GetProductDetails: include stock_value

* productcard: include stock_value

* Add Purchase Factor to Stock Overview

* update demo data with stock qu_factor_purchase_to_stock

* recipes_pos_resolved update

* avg_price and oldest_price in product details

* add average price to product card

* hint for recipe costs not included if not in stock

* Round value and factor_purchas_amount. Include currency for stock value

* Add factor_purchase_amount to product card stock amount

* Allow editing qu_factor_purchase_to_stock for stock entries

* fix update qu_factor_purchase_to_stock for Transfers

* Add barcode to existing product update to add to product_barcodes table

* Add barcode to new product workflow update to add to product_barcodes table

* *** Price now saved as 1 QU to stock in stock tables ***

* remove column product barcode and use product_barcodes

* Allow products to be deactivated instead of deleted

* Embedded barcode and qu-conversion with page reload on change

* Save current product barcode into new product_barcodes table

* Embedded popup for product group add/edit

* barcode scanner added to product barcodes input

* Edit product qu_stock is unavailable after first purchase

* StockOverview: Filters break when columns are reordered so for now just disable colReorder

* view stockoverview.blade: display product_group column

* Review

Co-authored-by: Bernd Bestel <bernd@berrnd.de>
This commit is contained in:
kriddles
2020-08-17 14:47:33 -05:00
committed by GitHub
parent d1e395b45e
commit e8845fe2e8
40 changed files with 1216 additions and 266 deletions

View File

@@ -8,12 +8,13 @@
Grocy.Api.Get('stock/products/' + jsonForm.product_id,
function(productDetails)
{
var amount = jsonForm.amount * productDetails.product.qu_factor_purchase_to_stock;
var amount = jsonForm.amount * jsonForm.qu_factor_purchase_to_stock;
var price = "";
if (!jsonForm.price.toString().isEmpty())
{
price = parseFloat(jsonForm.price).toFixed(2);
// price is saved as 1 QU to stock
price = parseFloat(jsonForm.price / amount).toFixed(2);
if ($("input[name='price-type']:checked").val() == "total-price")
{
@@ -37,6 +38,7 @@
{
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
}
jsonData.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/add', jsonData,
function(result)
@@ -49,17 +51,13 @@
var addBarcode = GetUriParam('addbarcodetoselection');
if (addBarcode !== undefined)
{
var existingBarcodes = productDetails.product.barcode || '';
if (existingBarcodes.length === 0)
{
productDetails.product.barcode = addBarcode;
}
else
{
productDetails.product.barcode += ',' + addBarcode;
}
var jsonDataBarcode = {};
jsonDataBarcode.barcode = addBarcode;
jsonDataBarcode.product_id = jsonForm.product_id;
jsonDataBarcode.qu_factor_purchase_to_stock = jsonForm.qu_factor_purchase_to_stock;
jsonDataBarcode.shopping_location_id = jsonForm.shopping_location_id;
Grocy.Api.Put('objects/products/' + productDetails.product.id, productDetails.product,
Grocy.Api.Post('objects/product_barcodes', jsonDataBarcode,
function(result)
{
$("#flow-info-addbarcodetoselection").addClass("d-none");
@@ -69,7 +67,7 @@
function(xhr)
{
Grocy.FrontendHelpers.EndUiBusy("purchase-form");
console.error(xhr);
Grocy.FrontendHelpers.ShowGenericError('Error while saving, probably this item already exists', xhr.response);
}
);
}
@@ -140,13 +138,66 @@ if (Grocy.Components.ProductPicker !== undefined)
{
Grocy.Components.ProductCard.Refresh(productId);
if (document.getElementById("product_id").getAttribute("barcode") != "null")
{
Grocy.Api.Get('productbarcodedetails/' + document.getElementById("product_id").getAttribute("barcode"),
function(resultBarcode)
{
if (resultBarcode != null)
{
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", resultBarcode.qu_factor_purchase_to_stock);
$('#product_id').attr("barcode-shopping-location-id", resultBarcode.shopping_location_id);
}
else
{
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", "null");
$('#product_id').attr("barcode-shopping-location-id", "null");
}
},
function(xhr)
{
console.error(xhr);
}
);
}
else
{
$('#product_id').attr("barcode-qu-factor-purchase-to-stock", "null");
$('#product_id').attr("barcode-shopping-location-id", "null");
}
Grocy.Api.Get('stock/products/' + productId,
function(productDetails)
{
$('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }));
$('#price').val(parseFloat(productDetails.last_price).toLocaleString({ minimumFractionDigits: 2, maximumFractionDigits: 2 }));
var qu_factor_purchase_to_stock = null;
var barcode_shopping_location_id = null;
if (document.getElementById("product_id").getAttribute("barcode") != "null" && document.getElementById("product_id").getAttribute("barcode-qu-factor-purchase-to-stock") != "null")
{
qu_factor_purchase_to_stock = document.getElementById("product_id").getAttribute("barcode-qu-factor-purchase-to-stock");
barcode_shopping_location_id = document.getElementById("product_id").getAttribute("barcode-shopping-location-id");
}
else
{
if (productDetails.last_qu_factor_purchase_to_stock != null)
{
qu_factor_purchase_to_stock = productDetails.last_qu_factor_purchase_to_stock;
}
else
{
qu_factor_purchase_to_stock = productDetails.product.qu_factor_purchase_to_stock;
}
}
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRICE_TRACKING) {
if (productDetails.last_shopping_location_id != null)
if (barcode_shopping_location_id != null)
{
Grocy.Components.ShoppingLocationPicker.SetId(barcode_shopping_location_id);
}
else if (productDetails.last_shopping_location_id != null)
{
Grocy.Components.ShoppingLocationPicker.SetId(productDetails.last_shopping_location_id);
}
@@ -161,15 +212,22 @@ if (Grocy.Components.ProductPicker !== undefined)
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
}
$('#amount_qu_unit').attr("qu-factor-purchase-to-stock", productDetails.product.qu_factor_purchase_to_stock);
$('#amount_qu_unit').attr("qu-factor-purchase-to-stock", qu_factor_purchase_to_stock);
$('#amount_qu_unit').attr("quantity-unit-purchase-name", productDetails.quantity_unit_purchase.name);
$('#amount_qu_unit').attr("quantity-unit-stock-name", productDetails.quantity_unit_stock.name);
if (productDetails.product.qu_id_purchase === productDetails.product.qu_id_stock)
$('#amount_qu_unit').attr("quantity-unit-stock-name-plural", productDetails.quantity_unit_stock.name_plural);
$('#qu_factor_purchase_to_stock').val(qu_factor_purchase_to_stock);
if (qu_factor_purchase_to_stock == 1)
{
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name);
$('#group-qu_factor_purchase_to_stock').addClass('d-none');
}
else
{
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name + " (" + __t("will be multiplied by a factor of %1$s to get %2$s", parseFloat(productDetails.product.qu_factor_purchase_to_stock).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }), __n(2, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)) + ")");
$('#amount_qu_unit').text(productDetails.quantity_unit_purchase.name + " (" + __t("will be multiplied by a factor of %1$s to get %2$s", parseFloat(qu_factor_purchase_to_stock).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }), __n(2, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)) + ")");
$('#group-qu_factor_purchase_to_stock').removeClass('d-none');
}
var priceTypeUnitPrice = $("#price-type-unit-price");
@@ -193,7 +251,7 @@ if (Grocy.Components.ProductPicker !== undefined)
if (productDetails.product.enable_tare_weight_handling == 1)
{
var minAmount = parseFloat(productDetails.product.tare_weight) / productDetails.product.qu_factor_purchase_to_stock + parseFloat(productDetails.stock_amount);
var minAmount = parseFloat(productDetails.product.tare_weight) / qu_factor_purchase_to_stock + parseFloat(productDetails.stock_amount);
$("#amount").attr("min", minAmount);
$("#amount").attr("step", "0.0001");
$("#amount").parent().find(".invalid-feedback").text(__t('The amount cannot be lower than %s', minAmount.toLocaleString()));
@@ -339,6 +397,15 @@ $('#amount').on('change', function(e)
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
$('#qu_factor_purchase_to_stock').on('change', function(e)
{
var value = $(e.target).val();
$('#amount_qu_unit').attr("qu-factor-purchase-to-stock", value);
$('#amount_qu_unit').text(document.getElementById("amount_qu_unit").getAttribute("quantity-unit-purchase-name") + " (" + __t("will be multiplied by a factor of %1$s to get %2$s", parseFloat(value).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 2 }), __n(2, document.getElementById("amount_qu_unit").getAttribute("quantity-unit-stock-name"), document.getElementById("amount_qu_unit").getAttribute("quantity-unit-stock-name-plural")) + ")"));
refreshPriceHint();
Grocy.FrontendHelpers.ValidateForm('purchase-form');
});
if (GetUriParam("flow") === "shoppinglistitemtostock")
{
$('#amount').val(parseFloat(GetUriParam("amount")).toLocaleString({ minimumFractionDigits: 0, maximumFractionDigits: 4 }));