Description
Katrin Fischer
2023-06-30 09:27:47 UTC
This could be a quick fix while we work on 34231. Joubu suggested using a CSS class and adding the pattern check with jQuery in the global .js file. I tried to write a POC using jQuery starting with the normal acq order form: $("#acq_neworderempty #unitprice").attr({inputmode: "decimal", pattern: "^\d+(\.\d{2})?$" }); It didn't work there, because we use the validate JS plugin. But we could maybe use that to our advantage. With Joubu's help: diff --git a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt index 42f537a5924..7f0be4c0af2 100644 --- a/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt +++ b/koha-tmpl/intranet-tmpl/prog/en/modules/acqui/neworderempty.tt @@ -669,7 +669,7 @@ </li> <li class="ordering_unitprice"> <label for="unitprice">Actual cost: </label> - <input type="text" id="unitprice" size="20" name="unitprice" value="[% unitprice | html %]" /> + <input type="text" id="unitprice" size="20" name="unitprice" value="[% unitprice | html %]" class="price" /> [% IF (invoiceincgst == 1) %](tax inc.)[% ELSE %](tax exc.)[% END %] </li> <li> diff --git a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js index 74af1ad89ae..aeab2be8667 100644 --- a/koha-tmpl/intranet-tmpl/prog/js/staff-global.js +++ b/koha-tmpl/intranet-tmpl/prog/js/staff-global.js @@ -110,6 +110,9 @@ $(document).ready(function() { $(".validated").each(function() { $(this).validate(); }); + jQuery.validator.addClassRules("price", { + number: true + }); $("#logout").on("click",function(){ logOut(); * It allows to add negative and positive amounts with decimal dot. This is OK as we do need the ability to add negatives in acquisitions. * It does allow entering thousand separators with a ., but Koha hates it and won't save the value: check_budget_total.pl: XML Parsing Error: syntax error Location: http://localhost:8081/cgi-bin/koha/acqui/check_budget_total.pl?budget_id=2&total=21.60 Line Number 1, Column 1: Created attachment 153568 [details] [review] Bug 34169: Use jQuery validator plugin to validate amounts This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It allows us to mark all input fields for monetary values, such as prices, replacement prices, fees etc. with a class that is linked to a check for the 'number' format in the jQuery Validator plugin. This is the base patch that does nothing by itself, please see test plan in second patch. Created attachment 153569 [details] [review] Bug 34169: Add decimal class to all relevant input fields in the acquisitions module This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It marks all input fields for monetary values, such as prices, replacement prices etc. with a class that is linked to a check for number format with the jQuery Validator plugin. To test: For any input field to test, try adding various false entries, like "abc" or "1,00". It should only accept inputs with decimal dot, like: "1.00" 0) Apply patch, restart_all 1) Suggestion * Add a new suggestion in the staff interface * Test: price input field at the bottom of the form. * Accept the suggestion 2) Order form * Create a new basket * Create an order line from an existing record * Test: list price, replacement price, and actual price. * Check the checkbox for uncertain price before you save 3) Uncertain prices * Go to the uncertain prices page for this vendor * Test: price field Note: this form does its own validation, but the change should not change behaviour for now * Resolve the uncertain price * Close order 4) Receive shipment * Test: Shipping cost 5) Receive the order * Test: replacement price, actual price * Check checkbox for price in foreign currency * Test: price in foreign currency * Receive order line 6) Invoice summary * Finish receiving * Test: shipping cost * Test: invoice adjustments: amount in the form for the first entry, amount in the table after adding it 7) Merging invoices * Receive another shipment and create and invoice * Go to invoices and search all * Check the 2 entries for merging * Test: shipping cost 8) Adding orders from a staged/new file * Export some records using the cart or list * Create a new basket * Order from new file * Import your file, ignore item records * Test: price and replacement price + Bonus: also test with items, test plan and file from bug 22802 are really helpful here Created attachment 153577 [details] [review] Bug 34169: Use jQuery validator plugin to validate amounts This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It allows us to mark all input fields for monetary values, such as prices, replacement prices, fees etc. with a class that is linked to a check for the 'number' format in the jQuery Validator plugin. This is the base patch that does nothing by itself, please see test plan in second patch. Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Created attachment 153578 [details] [review] Bug 34169: Add decimal class to all relevant input fields in the acquisitions module This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It marks all input fields for monetary values, such as prices, replacement prices etc. with a class that is linked to a check for number format with the jQuery Validator plugin. To test: For any input field to test, try adding various false entries, like "abc" or "1,00". It should only accept inputs with decimal dot, like: "1.00" 0) Apply patch, restart_all 1) Suggestion * Add a new suggestion in the staff interface * Test: price input field at the bottom of the form. * Accept the suggestion 2) Order form * Create a new basket * Create an order line from an existing record * Test: list price, replacement price, and actual price. * Check the checkbox for uncertain price before you save 3) Uncertain prices * Go to the uncertain prices page for this vendor * Test: price field Note: this form does its own validation, but the change should not change behaviour for now * Resolve the uncertain price * Close order 4) Receive shipment * Test: Shipping cost 5) Receive the order * Test: replacement price, actual price * Check checkbox for price in foreign currency * Test: price in foreign currency * Receive order line 6) Invoice summary * Finish receiving * Test: shipping cost * Test: invoice adjustments: amount in the form for the first entry, amount in the table after adding it 7) Merging invoices * Receive another shipment and create and invoice * Go to invoices and search all * Check the 2 entries for merging * Test: shipping cost 8) Adding orders from a staged/new file * Export some records using the cart or list * Create a new basket * Order from new file * Import your file, ignore item records * Test: price and replacement price + Bonus: also test with items, test plan and file from bug 22802 are really helpful here Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Could please someone check 8) Adding orders from a staged/new file I tested it in http://staff-pricevalid.sandboxes.ptfs-europe.co.uk/cgi-bin/koha/acqui/basket.pl?basketno=4 but the prices are not stored, the price is always 0.00 I'm not sure if I did everything correctly. Perhaps this is a separate bug and has nothing to do with the validation. 1) - 7) Signed Off (In reply to Michaela Sieber from comment #7) > Could please someone check > > 8) Adding orders from a staged/new file > > > I tested it in > http://staff-pricevalid.sandboxes.ptfs-europe.co.uk/cgi-bin/koha/acqui/ > basket.pl?basketno=4 > > but the prices are not stored, the price is always 0.00 > > I'm not sure if I did everything correctly. > > Perhaps this is a separate bug and has nothing to do with the validation. > > 1) - 7) Signed Off Hi Michaela, could it have been: Bug 18914 - 'Add order' links from staged file order information isn't carried over It happens when you use the order link to add a single order line insted of using the checkboxes and the button at the bottom. I think there is something wrong still with the multi-select. If I pick more than one, only the price of the first is carried over into the order. I'll have a look. Created attachment 153580 [details] [review] Bug 34169: (follow-up) Fix ordering from staged files by removing superfluous form Removes the unneded new form element as we have one big form for the whole page. This should fix the situation where only the prices and information of the first selected record carreid over into the order. Created attachment 153581 [details] [review] Bug 34169: Use jQuery validator plugin to validate amounts This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It allows us to mark all input fields for monetary values, such as prices, replacement prices, fees etc. with a class that is linked to a check for the 'number' format in the jQuery Validator plugin. This is the base patch that does nothing by itself, please see test plan in second patch. Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Created attachment 153582 [details] [review] Bug 34169: Add decimal class to all relevant input fields in the acquisitions module This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It marks all input fields for monetary values, such as prices, replacement prices etc. with a class that is linked to a check for number format with the jQuery Validator plugin. To test: For any input field to test, try adding various false entries, like "abc" or "1,00". It should only accept inputs with decimal dot, like: "1.00" 0) Apply patch, restart_all 1) Suggestion * Add a new suggestion in the staff interface * Test: price input field at the bottom of the form. * Accept the suggestion 2) Order form * Create a new basket * Create an order line from an existing record * Test: list price, replacement price, and actual price. * Check the checkbox for uncertain price before you save 3) Uncertain prices * Go to the uncertain prices page for this vendor * Test: price field Note: this form does its own validation, but the change should not change behaviour for now * Resolve the uncertain price * Close order 4) Receive shipment * Test: Shipping cost 5) Receive the order * Test: replacement price, actual price * Check checkbox for price in foreign currency * Test: price in foreign currency * Receive order line 6) Invoice summary * Finish receiving * Test: shipping cost * Test: invoice adjustments: amount in the form for the first entry, amount in the table after adding it 7) Merging invoices * Receive another shipment and create and invoice * Go to invoices and search all * Check the 2 entries for merging * Test: shipping cost 8) Adding orders from a staged/new file * Export some records using the cart or list * Create a new basket * Order from new file * Import your file, ignore item records * Test: price and replacement price + Bonus: also test with items, test plan and file from bug 22802 are really helpful here Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Created attachment 153583 [details] [review] Bug 34169: (follow-up) Fix ordering from staged files by removing superfluous form Removes the unneded new form element as we have one big form for the whole page. This should fix the situation where only the prices and information of the first selected record carreid over into the order. I think I found an fixed it for the checkboxes/multi-select. Bug 18914 is not fixed by it. Created attachment 153801 [details] [review] Bug 34169: Use jQuery validator plugin to validate amounts This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It allows us to mark all input fields for monetary values, such as prices, replacement prices, fees etc. with a class that is linked to a check for the 'number' format in the jQuery Validator plugin. This is the base patch that does nothing by itself, please see test plan in second patch. Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Created attachment 153802 [details] [review] Bug 34169: Add decimal class to all relevant input fields in the acquisitions module This is a first step towards more consistency and possibly supporting multiple input formats as well in the future. It marks all input fields for monetary values, such as prices, replacement prices etc. with a class that is linked to a check for number format with the jQuery Validator plugin. To test: For any input field to test, try adding various false entries, like "abc" or "1,00". It should only accept inputs with decimal dot, like: "1.00" 0) Apply patch, restart_all 1) Suggestion * Add a new suggestion in the staff interface * Test: price input field at the bottom of the form. * Accept the suggestion 2) Order form * Create a new basket * Create an order line from an existing record * Test: list price, replacement price, and actual price. * Check the checkbox for uncertain price before you save 3) Uncertain prices * Go to the uncertain prices page for this vendor * Test: price field Note: this form does its own validation, but the change should not change behaviour for now * Resolve the uncertain price * Close order 4) Receive shipment * Test: Shipping cost 5) Receive the order * Test: replacement price, actual price * Check checkbox for price in foreign currency * Test: price in foreign currency * Receive order line 6) Invoice summary * Finish receiving * Test: shipping cost * Test: invoice adjustments: amount in the form for the first entry, amount in the table after adding it 7) Merging invoices * Receive another shipment and create and invoice * Go to invoices and search all * Check the 2 entries for merging * Test: shipping cost 8) Adding orders from a staged/new file * Export some records using the cart or list * Create a new basket * Order from new file * Import your file, ignore item records * Test: price and replacement price + Bonus: also test with items, test plan and file from bug 22802 are really helpful here Signed-off-by: Michaela Sieber <michaela.sieber@kit.edu> Signed-off-by: Nick Clemens <nick@bywatersolutions.com> Created attachment 153803 [details] [review] Bug 34169: (follow-up) Fix ordering from staged files by removing superfluous form Removes the unneded new form element as we have one big form for the whole page. This should fix the situation where only the prices and information of the first selected record carreid over into the order. Signed-off-by: Nick Clemens <nick@bywatersolutions.com> There are places where you end up with NaN when you enter invalid format, but you cannot submit and this seems a large improvement, passing QA Pushed to master for 23.11. Nice work everyone, thanks! Thank you! Is backporting for 23.05.x possible ? Long lasting bug I gladly backport. Pushed to 23.05.x for 23.05.03 Missing dependencies for 22.11.x. Not pushing. |