From 49602d6a97a10d1716a61d20fb06e30a8ef006e2 Mon Sep 17 00:00:00 2001 From: Nick Clemens Date: Fri, 4 Aug 2023 14:13:25 +0000 Subject: [PATCH] Bug 34109: Check mandatory item fields when creating during recipt This patch adds a check of mandatory item fields before saving during order receipt. We check both when adding the item initially, and when submitting the order, as it will use the values from the open form. To test: * Go to administration > frameworks > ACQ > MARC structure > 952 * Set callnumber (o) or barcode (p) to mandatory * In acquisition: * Create a basket with "create items on order" and "is standing" "standing" helps as you can do multiple receives testing different things, but is optional * Add an order line * Receive shipment * Verify the mandatory fields show in the item form * Set itemtype = Music * Save with the fields blank * Item row is added, no warning * Edit the item, change the item type to blank * Click 'Confirm' for the order without closing the item edit form * Verify the item was added with itemtype Books (on sample data) and empty mandatory field * Apply patch * Repeat above, however, you should not be able to submit the item or order until mandatory fields are filled Signed-off-by: Sam Lau Signed-off-by: Martin Renvoize --- .../prog/en/modules/acqui/orderreceive.tt | 17 +++++++++++++++++ koha-tmpl/intranet-tmpl/prog/js/additem.js | 16 +++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt index a7b9db35e4..79f274c2ae 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -1328,6 +1328,23 @@ }); $('.modal-save').click(function() { + + //We need to validate the item forms here - if one is opened with missing subfields at + //confirm, it would be submitted without this + var _alertString= _("Form not submitted because of the following problem(s)")+"\n"; + _alertString +="-------------------------------------------------------------------\n\n"; + var empty_mandatory_fields = 0; + $('div[id^="itemblock"]').each(function(){ + var item_form = $(this); + var empty_item_mandatory = CheckMandatorySubfields(item_form); + empty_mandatory_fields += empty_item_mandatory; + }); + if (empty_mandatory_fields > 0) { + _alertString +="\n- " + _("%s item mandatory fields empty").format(empty_mandatory_fields); + alert(_alertString); + return false; + } + var saved_rows = save_row(); if(Object.keys(saved_rows).length) $('.save').prop('disabled', false); $("#order_edit").modal('hide'); diff --git a/koha-tmpl/intranet-tmpl/prog/js/additem.js b/koha-tmpl/intranet-tmpl/prog/js/additem.js index 35ee4e2995..b3045c656e 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/additem.js +++ b/koha-tmpl/intranet-tmpl/prog/js/additem.js @@ -1,7 +1,21 @@ /* global __ */ /* exported addItem checkCount showItem deleteItemBlock clearItemBlock check_additem */ function addItem( node, unique_item_fields ) { - var index = $(node).closest("div").attr('id'); + var item_form = $(node).closest("div"); + var index = item_form.attr("id"); + + //We need to verify the item form before saving + var empty_item_mandatory = CheckMandatorySubfields(item_form); + if (empty_item_mandatory > 0) { + var _alertString= _("Form not submitted because of the following problem(s)")+"\n"; + + _alertString +="-------------------------------------------------------------------\n\n"; + _alertString += + "\n- " + _("%s item mandatory fields empty").format(empty_item_mandatory); + alert(_alertString); + return false; + } + var current_qty = parseInt($("#quantity").val()); var max_qty; if($("#quantity_to_receive").length != 0){ -- 2.41.0