Fixed stock entry Userfield edit handling (fixes #1969)

This commit is contained in:
Bernd Bestel 2022-08-18 21:29:19 +02:00
parent 9b52168b94
commit 06968ac289
No known key found for this signature in database
GPG Key ID: 71BD34C0D4891300
3 changed files with 23 additions and 0 deletions

View File

@ -13,6 +13,7 @@
- Fixed that when the stock setting "Decimal places allowed for amounts" was set to `0`, unit conversion (if any) failed when adding the corresponding product to stock
- Fixed that consuming a parent product which is not in stock itself (so essentially using any of the child products) may failed when unit conversions were involved (the current stock amount check was wrong in that case)
- Fixed that the status button counters on the stock overview page ("X products are overdue" and so on) included products which have the option `Never show on stock overview` enabled
- Fixed that adding Userfields to existing stock entries was not possible (only editing existing Userfield values, e.g. added during purchase or inventory, was possible)
### Shopping list

21
migrations/0196.sql Normal file
View File

@ -0,0 +1,21 @@
DROP TRIGGER userfield_values_special_handling_INS;
CREATE TRIGGER userfield_values_special_handling_INS AFTER INSERT ON userfield_values
BEGIN
-- Entity stock:
-- object_id is the transaction_id on insert -> replace it by the corresponding stock_id
INSERT OR REPLACE INTO userfield_values
(field_id, object_id, value)
SELECT uv.field_id, sl.stock_id, uv.value
FROM userfield_values uv
JOIN stock_log sl
ON uv.object_id = sl.transaction_id
AND sl.transaction_type IN ('purchase', 'inventory-correction', 'stock-edit-new')
WHERE uv.field_id IN (SELECT id FROM userfields WHERE entity = 'stock')
AND uv.field_id = NEW.field_id
AND uv.object_id = NEW.object_id;
DELETE FROM userfield_values
WHERE field_id IN (SELECT id FROM userfields WHERE entity = 'stock')
AND field_id = NEW.field_id
AND object_id = NEW.object_id;
END;

View File

@ -44,6 +44,7 @@
Grocy.Api.Put("stock/entry/" + Grocy.EditObjectRowId, jsonData,
function(result)
{
Grocy.EditObjectId = result[0].transaction_id;
Grocy.Components.UserfieldsForm.Save(function()
{
var successMessage = __t('Stock entry successfully updated') + '<br><a class="btn btn-secondary btn-sm mt-2" href="#" onclick="UndoStockBookingEntry(\'' + result.id + '\',\'' + Grocy.EditObjectRowId + '\')"><i class="fa-solid fa-undo"></i> ' + __t("Undo") + '</a>';