mirror of
https://github.com/grocy/grocy.git
synced 2025-04-29 09:39:57 +00:00
Make it possible to disable open per product (closes #1911)
This commit is contained in:
parent
72e1a9aee7
commit
bc78359dba
@ -20,6 +20,9 @@
|
||||
- Added a new stock setting (top right corner settings menu) "Show all out of stock products" to optionally also show all out of stock products on the stock overview page (defaults to disabled, so no changed behavior when not configured)
|
||||
- By default the stock overview page lists all products which are currently in stock or below their min. stock amount
|
||||
- When this new setting is enabled, all (active) products are always shown
|
||||
- Added a new product option "Can't be opened"
|
||||
- When enabled the product open functionality for that product is disabled
|
||||
- Defaults to disabled, so no changed behavior when not configured
|
||||
- Product barcode matching is now case-insensitive
|
||||
- Added a new column "Product picture" on the products list (master data) page (hidden by default)
|
||||
- Optimized that when navigation between the different "Group by"-variants on the stock report "Spendings", the selected date range now remains persistent
|
||||
|
@ -2458,3 +2458,6 @@ msgstr ""
|
||||
|
||||
msgid "For ingredients that are only partially in stock, the in stock amount will be consumed."
|
||||
msgstr ""
|
||||
|
||||
msgid "Can't be opened"
|
||||
msgstr ""
|
||||
|
92
migrations/0248.sql
Normal file
92
migrations/0248.sql
Normal file
@ -0,0 +1,92 @@
|
||||
ALTER TABLE products
|
||||
ADD disable_open TINYINT NOT NULL DEFAULT 0 CHECK(disable_open IN (0, 1));
|
||||
|
||||
DROP VIEW uihelper_stock_current_overview;
|
||||
CREATE VIEW uihelper_stock_current_overview
|
||||
AS
|
||||
SELECT
|
||||
p.id,
|
||||
sc.amount_opened AS amount_opened,
|
||||
p.tare_weight AS tare_weight,
|
||||
p.enable_tare_weight_handling AS enable_tare_weight_handling,
|
||||
sc.amount AS amount,
|
||||
sc.value as value,
|
||||
sc.product_id AS product_id,
|
||||
IFNULL(sc.best_before_date, '2888-12-31') AS best_before_date,
|
||||
EXISTS(SELECT id FROM stock_missing_products WHERE id = sc.product_id) AS product_missing,
|
||||
p.name AS product_name,
|
||||
pg.name AS product_group_name,
|
||||
EXISTS(SELECT * FROM shopping_list WHERE shopping_list.product_id = sc.product_id) AS on_shopping_list,
|
||||
qu_stock.name AS qu_stock_name,
|
||||
qu_stock.name_plural AS qu_stock_name_plural,
|
||||
qu_purchase.name AS qu_purchase_name,
|
||||
qu_purchase.name_plural AS qu_purchase_name_plural,
|
||||
qu_consume.name AS qu_consume_name,
|
||||
qu_consume.name_plural AS qu_consume_name_plural,
|
||||
qu_price.name AS qu_price_name,
|
||||
qu_price.name_plural AS qu_price_name_plural,
|
||||
sc.is_aggregated_amount,
|
||||
sc.amount_opened_aggregated,
|
||||
sc.amount_aggregated,
|
||||
p.calories AS product_calories,
|
||||
sc.amount * p.calories AS calories,
|
||||
sc.amount_aggregated * p.calories AS calories_aggregated,
|
||||
p.quick_consume_amount,
|
||||
p.quick_consume_amount / p.qu_factor_consume_to_stock AS quick_consume_amount_qu_consume,
|
||||
p.quick_open_amount,
|
||||
p.quick_open_amount / p.qu_factor_consume_to_stock AS quick_open_amount_qu_consume,
|
||||
p.due_type,
|
||||
plp.purchased_date AS last_purchased,
|
||||
plp.price AS last_price,
|
||||
pap.price as average_price,
|
||||
p.min_stock_amount,
|
||||
pbcs.barcodes AS product_barcodes,
|
||||
p.description AS product_description,
|
||||
l.name AS product_default_location_name,
|
||||
p_parent.id AS parent_product_id,
|
||||
p_parent.name AS parent_product_name,
|
||||
p.picture_file_name AS product_picture_file_name,
|
||||
p.no_own_stock AS product_no_own_stock,
|
||||
p.qu_factor_purchase_to_stock AS product_qu_factor_purchase_to_stock,
|
||||
p.qu_factor_price_to_stock AS product_qu_factor_price_to_stock,
|
||||
sc.is_in_stock_or_below_min_stock,
|
||||
p.disable_open
|
||||
FROM (
|
||||
SELECT *, 1 AS is_in_stock_or_below_min_stock
|
||||
FROM stock_current
|
||||
WHERE best_before_date IS NOT NULL
|
||||
UNION
|
||||
SELECT m.id, 0, 0, 0, null, 0, 0, 0, p.due_type, 1 AS is_in_stock_or_below_min_stock
|
||||
FROM stock_missing_products m
|
||||
JOIN products p
|
||||
ON m.id = p.id
|
||||
WHERE m.id NOT IN (SELECT product_id FROM stock_current)
|
||||
UNION
|
||||
SELECT p2.id, 0, 0, 0, null, 0, 0, 0, p2.due_type, 0 AS is_in_stock_or_below_min_stock
|
||||
FROM products p2
|
||||
WHERE active = 1
|
||||
AND p2.id NOT IN (SELECT product_id FROM stock_current UNION SELECT id FROM stock_missing_products)
|
||||
) sc
|
||||
JOIN products_view p
|
||||
ON sc.product_id = p.id
|
||||
JOIN locations l
|
||||
ON p.location_id = l.id
|
||||
JOIN quantity_units qu_stock
|
||||
ON p.qu_id_stock = qu_stock.id
|
||||
JOIN quantity_units qu_purchase
|
||||
ON p.qu_id_purchase = qu_purchase.id
|
||||
JOIN quantity_units qu_consume
|
||||
ON p.qu_id_consume = qu_consume.id
|
||||
JOIN quantity_units qu_price
|
||||
ON p.qu_id_price = qu_price.id
|
||||
LEFT JOIN product_groups pg
|
||||
ON p.product_group_id = pg.id
|
||||
LEFT JOIN cache__products_last_purchased plp
|
||||
ON sc.product_id = plp.product_id
|
||||
LEFT JOIN cache__products_average_price pap
|
||||
ON sc.product_id = pap.product_id
|
||||
LEFT JOIN product_barcodes_comma_separated pbcs
|
||||
ON sc.product_id = pbcs.product_id
|
||||
LEFT JOIN products p_parent
|
||||
ON p.parent_product_id = p_parent.id
|
||||
WHERE p.hide_on_stock_overview = 0;
|
@ -494,7 +494,7 @@ Grocy.Components.ProductPicker.GetPicker().on('change', function(e)
|
||||
$('#display_amount').focus();
|
||||
}, 500);
|
||||
|
||||
if (productDetails.stock_amount == productDetails.stock_amount_opened || productDetails.product.enable_tare_weight_handling == 1)
|
||||
if (productDetails.stock_amount == productDetails.stock_amount_opened || productDetails.product.enable_tare_weight_handling == 1 || productDetails.product.disable_open == 1)
|
||||
{
|
||||
$("#save-mark-as-open-button").addClass("disabled");
|
||||
}
|
||||
|
@ -248,6 +248,11 @@ function RefreshStockEntryRow(stockRowId)
|
||||
|
||||
$('#stock-' + stockRowId + '-price').text(__t("%1$s per %2$s", (result.price * productDetails.qu_conversion_factor_purchase_to_stock).toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices_display, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices_display }), productDetails.default_quantity_unit_purchase.name));
|
||||
$('#stock-' + stockRowId + '-price').attr("data-original-title", __t("%1$s per %2$s", result.price.toLocaleString(undefined, { style: "currency", currency: Grocy.Currency, minimumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices_display, maximumFractionDigits: Grocy.UserSettings.stock_decimal_places_prices_display }), productDetails.quantity_unit_stock.name));
|
||||
|
||||
if (productDetails.product.disable_open == 1)
|
||||
{
|
||||
$(".product-open-button[data-stockrow-id='" + stockRowId + "']").addClass("disabled");
|
||||
}
|
||||
},
|
||||
function(xhr)
|
||||
{
|
||||
|
@ -359,6 +359,11 @@ function RefreshProductRow(productId)
|
||||
$(".product-consume-button[data-product-id='" + productId + "']").removeClass("disabled");
|
||||
$(".product-open-button[data-product-id='" + productId + "']").removeClass("disabled");
|
||||
}
|
||||
|
||||
if (result.product.disable_open == 1)
|
||||
{
|
||||
$(".product-open-button[data-product-id='" + productId + "']").addClass("disabled");
|
||||
}
|
||||
}
|
||||
|
||||
$('#product-' + productId + '-next-due-date').text(result.next_due_date);
|
||||
|
@ -953,10 +953,16 @@ class StockService extends BaseService
|
||||
throw new \Exception('Product does not exist or is inactive');
|
||||
}
|
||||
|
||||
$product = $this->getDatabase()->products($productId);
|
||||
|
||||
if ($product->disable_open == 1)
|
||||
{
|
||||
throw new \Exception('Product can\'t be opened');
|
||||
}
|
||||
|
||||
$productDetails = (object)$this->GetProductDetails($productId);
|
||||
$productStockAmountUnopened = $productDetails->stock_amount_aggregated - $productDetails->stock_amount_opened_aggregated;
|
||||
$potentialStockEntries = $this->GetProductStockEntries($productId, true, $allowSubproductSubstitution);
|
||||
$product = $this->getDatabase()->products($productId);
|
||||
|
||||
if ($product->enable_tare_weight_handling == 1)
|
||||
{
|
||||
|
@ -570,10 +570,18 @@
|
||||
</div>
|
||||
@endif
|
||||
|
||||
@include('components.userfieldsform', array(
|
||||
'userfields' => $userfields,
|
||||
'entity' => 'products'
|
||||
))
|
||||
@if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING)
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input @if($mode=='edit'
|
||||
&&
|
||||
$product->disable_open == 1) checked @endif class="form-check-input custom-control-input" type="checkbox" id="disable_open" name="disable_open" value="1">
|
||||
<label class="form-check-label custom-control-label"
|
||||
for="disable_open">{{ $__t('Can\'t be opened') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
@endif
|
||||
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox">
|
||||
@ -589,7 +597,7 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="form-group mb-5">
|
||||
<div class="form-group">
|
||||
<div class="custom-control custom-checkbox">
|
||||
<input @if($mode=='edit'
|
||||
&&
|
||||
@ -603,6 +611,12 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@include('components.userfieldsform', array(
|
||||
'userfields' => $userfields,
|
||||
'entity' => 'products'
|
||||
))
|
||||
|
||||
<div class="py-5"></div>
|
||||
<div class="sticky-form-footer pt-1">
|
||||
<small id="save-hint"
|
||||
class="my-1 form-text text-muted @if($mode == 'edit') d-none @endif">{{ $__t('Save & continue to add quantity unit conversions & barcodes') }}</small>
|
||||
@ -878,10 +892,10 @@
|
||||
class="img-fluid img-thumbnail mt-2 mb-5"
|
||||
loading="lazy">
|
||||
<p id="delete-current-product-picture-on-save-hint"
|
||||
class="form-text text-muted font-italic d-none mb-5">{{ $__t('The current picture will be deleted on save') }}</p>
|
||||
class="form-text text-muted font-italic d-none pb-5">{{ $__t('The current picture will be deleted on save') }}</p>
|
||||
@else
|
||||
<p id="no-current-product-picture-hint"
|
||||
class="form-text text-muted font-italic mb-5">{{ $__t('No picture available') }}</p>
|
||||
class="form-text text-muted font-italic pb-5">{{ $__t('No picture available') }}</p>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
@ -121,7 +121,7 @@
|
||||
<i class="fa-solid fa-utensils"></i>
|
||||
</a>
|
||||
@if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING)
|
||||
<a class="btn btn-success btn-sm product-open-button @if($stockEntry->open == 1 || FindObjectInArrayByPropertyValue($products, 'id', $stockEntry->product_id)->enable_tare_weight_handling == 1) disabled @endif"
|
||||
<a class="btn btn-success btn-sm product-open-button @if($stockEntry->open == 1 || FindObjectInArrayByPropertyValue($products, 'id', $stockEntry->product_id)->enable_tare_weight_handling == 1 || FindObjectInArrayByPropertyValue($products, 'id', $stockEntry->product_id)->disable_open == 1) disabled @endif"
|
||||
href="#"
|
||||
data-toggle="tooltip"
|
||||
data-placement="left"
|
||||
|
@ -221,7 +221,7 @@
|
||||
<i class="fa-solid fa-utensils"></i> {{ $__t('All') }}
|
||||
</a>
|
||||
@if(GROCY_FEATURE_FLAG_STOCK_PRODUCT_OPENED_TRACKING)
|
||||
<a class="btn btn-success btn-sm product-open-button @if($currentStockEntry->amount_aggregated < $currentStockEntry->quick_open_amount || $currentStockEntry->amount_aggregated == $currentStockEntry->amount_opened_aggregated || $currentStockEntry->enable_tare_weight_handling == 1) disabled @endif"
|
||||
<a class="btn btn-success btn-sm product-open-button @if($currentStockEntry->amount_aggregated < $currentStockEntry->quick_open_amount || $currentStockEntry->amount_aggregated == $currentStockEntry->amount_opened_aggregated || $currentStockEntry->enable_tare_weight_handling == 1 || $currentStockEntry->disable_open == 1) disabled @endif"
|
||||
href="#"
|
||||
data-toggle="tooltip"
|
||||
data-placement="left"
|
||||
|
Loading…
x
Reference in New Issue
Block a user