From e3a7202363d0033a9c29b1143fc47c8c631f269f Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Tue, 11 Jul 2023 10:21:09 +0200 Subject: [PATCH] Bug 33863: Update values in data that will be saved We are not saving the values of the input but a representation of the form, contains in $("#order_edit").data('row'); To acchieve that it's preferable to reuse _update_unitprice and call it when #change_currency is modified. Some code cleaning slipped into the patch, for readability purpose. Signed-off-by: Michaela Sieber Signed-off-by: Nick Clemens Signed-off-by: Tomas Cohen Arazi --- .../prog/en/modules/acqui/orderreceive.tt | 41 +++++++++++-------- 1 file changed, 24 insertions(+), 17 deletions(-) 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 67eb84210b..f169a117e5 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/orderreceive.tt @@ -365,7 +365,7 @@
  • - +
  • @@ -909,32 +909,39 @@ }); - $("#order_edit").on("change", "input[name='change_currency']", function(){ - if ( $(this).is(":checked") ) { + function _update_unitprice() { + let row = $("#order_edit").data('row'); + + let unitprice = $("#unitprice").val(); + let invoice_currency = $("#invoice_currency").val(); + let invoice_unitprice = $("#invoice_unitprice").val(); + let change_currency = $("#change_currency").is(":checked"); + + if ( change_currency ) { $("#select_currency").show(); - if(!$("#invoice_unitprice").val()) - $("#invoice_unitprice").val($('#unitprice').val()); + if(!$("#invoice_unitprice").val()){ + invoice_unitprice = unitprice; + } + var rate = Number($("#invoice_currency option:selected").data('rate')); + unitprice = Number( invoice_unitprice * rate ).toFixed(2); $("#unitprice").prop("readonly", "true"); } else { $("#select_currency").hide(); $("#unitprice").prop("readonly", ""); - $("#invoice_unitprice").val(""); - $("#invoice_currency").val(active_currency); + invoice_unitprice = ""; + invoice_currency = active_currency; } - }); - function _update_unitprice() { - var row = $("#order_edit").data('row'); - var rate = Number($("select[name='invoice_currency'] option:selected").data('rate')); - var invoice_currency = $("select[name='invoice_currency'] option:selected").val(); - var invoice_unitprice = $("#invoice_unitprice").val(); - var unitprice = Number( invoice_unitprice * rate ).toFixed(2); + $("#invoice_unitprice").val(invoice_unitprice); + $("#invoice_currency").val(invoice_currency); $("#unitprice").val(unitprice).change(); + row.invoice_currency = invoice_currency; row.invoice_unit_price = invoice_unitprice; } - $("#order_edit").on("change", "select[name='invoice_currency']", _update_unitprice ); + $("#order_edit").on("change", "#invoice_currency", _update_unitprice ); $("#order_edit").on("change", "#invoice_unitprice", _update_unitprice ); + $("#order_edit").on("change", "#change_currency", _update_unitprice ); $("#order_edit").on("change", "#replacementprice", function() { var val = $(this).val(); @@ -1247,13 +1254,13 @@ if(row.invoice_currency && row.invoice_currency != active_currency) { $("#select_currency").show(); $("#unitprice").prop("readonly", true); - $("input[name='change_currency']").prop('checked', true); + $("#change_currency").prop('checked', true); $("#invoice_currency").val(row.invoice_currency); $("#invoice_unitprice").val(row.invoice_unit_price); } else { $("#select_currency").hide(); $("#unitprice").prop("readonly", ""); - $("input[name='change_currency']").prop('checked', false); + $("#change_currency").prop('checked', false); $("#invoice_currency").val(active_currency); $("#invoice_unitprice").val(''); } -- 2.39.5