mirror of
https://github.com/grocy/grocy.git
synced 2026-04-08 21:46:16 +02:00
Reworked purchase page default due date handling (fixes #2895)
This commit is contained in:
parent
3137d4b4cf
commit
736cc8c2f6
|
|
@ -10,7 +10,7 @@
|
||||||
|
|
||||||
### Stock
|
### Stock
|
||||||
|
|
||||||
- xxx
|
- Fixed that changing the location on the purchase page re-initialized the due date based on product defaults (if any)
|
||||||
|
|
||||||
### Shopping list
|
### Shopping list
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -441,36 +441,65 @@ if (Grocy.Components.ProductPicker !== undefined)
|
||||||
|
|
||||||
function PrefillBestBeforeDate(product, location)
|
function PrefillBestBeforeDate(product, location)
|
||||||
{
|
{
|
||||||
|
if (!Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (location == null)
|
if (location == null)
|
||||||
{
|
{
|
||||||
location = {}
|
location = {}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_BEST_BEFORE_DATE_TRACKING)
|
var shortcutValue = $("#datetimepicker-shortcut").attr("data-datetimepicker-shortcut-value");
|
||||||
|
var dueDateCurrent = Grocy.Components.DateTimePicker.GetValue();
|
||||||
|
var dueDateDefault = null;
|
||||||
|
var dueDateFreezer = null;
|
||||||
|
|
||||||
|
if (product.default_best_before_days != 0)
|
||||||
{
|
{
|
||||||
var dueDays;
|
dueDateDefault = moment().add(product.default_best_before_days, 'days').format('YYYY-MM-DD');
|
||||||
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING && BoolVal(location.is_freezer))
|
|
||||||
|
if (product.default_best_before_days == -1)
|
||||||
{
|
{
|
||||||
dueDays = product.default_best_before_days_after_freezing;
|
dueDateDefault = shortcutValue;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
dueDays = product.default_best_before_days;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dueDays != 0)
|
if (Grocy.FeatureFlags.GROCY_FEATURE_FLAG_STOCK_PRODUCT_FREEZING && BoolVal(location.is_freezer) && product.default_best_before_days_after_freezing != 0)
|
||||||
{
|
{
|
||||||
if (dueDays == -1)
|
dueDateFreezer = moment().add(product.default_best_before_days_after_freezing, 'days').format('YYYY-MM-DD');
|
||||||
|
|
||||||
|
if (product.default_best_before_days_after_freezing == -1)
|
||||||
{
|
{
|
||||||
if (!$("#datetimepicker-shortcut").is(":checked"))
|
dueDateFreezer = shortcutValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the default due date when currently no one is set
|
||||||
|
if (dueDateDefault && !dueDateCurrent)
|
||||||
|
{
|
||||||
|
if (!$("#datetimepicker-shortcut").is(":checked") && dueDateDefault == shortcutValue)
|
||||||
{
|
{
|
||||||
$("#datetimepicker-shortcut").click();
|
$("#datetimepicker-shortcut").click();
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Grocy.Components.DateTimePicker.SetValue(dueDateDefault);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the default due date after freezing when currently no one is set or when it was previously set to the default due date
|
||||||
|
// (so essentially don't overwrite a by the user different entered due date)
|
||||||
|
if (dueDateFreezer && (!dueDateCurrent || dueDateCurrent == dueDateDefault))
|
||||||
|
{
|
||||||
|
if (!$("#datetimepicker-shortcut").is(":checked") && dueDateFreezer == shortcutValue)
|
||||||
|
{
|
||||||
|
$("#datetimepicker-shortcut").click();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Grocy.Components.DateTimePicker.SetValue(moment().add(dueDays, 'days').format('YYYY-MM-DD'));
|
Grocy.Components.DateTimePicker.SetValue(dueDateFreezer);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user