Implemented stock sub-feature-flags (closes #314)

This commit is contained in:
Bernd Bestel
2019-09-19 17:46:52 +02:00
parent 5e9a7fb7ca
commit cbf1d1ca40
16 changed files with 164 additions and 50 deletions

View File

@@ -17,7 +17,14 @@
var jsonData = { };
jsonData.new_amount = jsonForm.new_amount;
jsonData.best_before_date = Grocy.Components.DateTimePicker.GetValue();
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
{
jsonData.location_id = Grocy.Components.LocationPicker.GetValue();
}
else
{
jsonData.location_id = 1;
}
jsonData.price = price;
Grocy.Api.Post('stock/products/' + jsonForm.product_id + '/inventory', jsonData,
@@ -120,7 +127,10 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
}
$('#price').val(productDetails.last_price);
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
{
Grocy.Components.LocationPicker.SetId(productDetails.location.id);
}
$('#new_amount').focus();
},
function(xhr)
@@ -221,13 +231,24 @@ $('#new_amount').on('keyup', function(e)
{
$('#inventory-change-info').text(__t('This means %s will be added to stock', estimatedBookingAmount.toLocaleString() + ' ' + __n(estimatedBookingAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)));
Grocy.Components.DateTimePicker.GetInputElement().attr('required', '');
Grocy.Components.LocationPicker.GetInputElement().attr('required', '');
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
{
Grocy.Components.LocationPicker.GetInputElement().attr('required', '');
}
}
else if (newAmount < productStockAmount + containerWeight)
{
$('#inventory-change-info').text(__t('This means %s will be removed from stock', estimatedBookingAmount.toLocaleString() + ' ' + __n(estimatedBookingAmount, productDetails.quantity_unit_stock.name, productDetails.quantity_unit_stock.name_plural)));
Grocy.Components.DateTimePicker.GetInputElement().removeAttr('required');
Grocy.Components.LocationPicker.GetInputElement().removeAttr('required');
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_LOCATION_TRACKING)
{
Grocy.Components.LocationPicker.GetInputElement().removeAttr('required');
}
}
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
{
Grocy.Components.DateTimePicker.GetInputElement().removeAttr('required');
}
Grocy.FrontendHelpers.ValidateForm('inventory-form');