[Bug 43289] New: TypeError in cashup summary modal when API returns totals as strings
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43289 Bug ID: 43289 Summary: TypeError in cashup summary modal when API returns totals as strings Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Point of Sale Assignee: koha-bugs@lists.koha-community.org Reporter: martin.renvoize@openfifth.co.uk QA Contact: martin.renvoize@openfifth.co.uk Target Milestone: --- format_price() is only defined on Number.prototype (see koha-tmpl/intranet-tmpl/prog/en/includes/format_price.inc), but the /api/v1/cashups/:id summary endpoint's grouped and total amounts (out.total, income.total, type.total, data.summary.total, and the derived cashCollected/actualAmount) can come back as strings - DECIMAL columns are frequently stringified by the DB layer before JSON encoding. Calling e.g. out.total.format_price() on a string throws "TypeError: out.total.format_price is not a function", which aborts the rest of the AJAX success handler and leaves the cashup summary modal partially or fully unrendered. This patch wraps every such value in Number(...) before calling format_price(). It also fixes the "Other payment types collected" filter, which compared type.total !== 0 with strict inequality - always true when type.total is a string, so a $0.00 payment type could show a spurious row in the summary. Test plan: 1. Configure more than one payment type in the CashupPaymentTypes system preference 2. Complete a cashup (pos/register.pl) with income/payout/refund transactions across several payment types, including at least one with a zero total for some payment type 3. Click the cashup's "Summary" link to open the cashup summary modal 4. Before this patch: open the browser console - a TypeError is thrown and the modal's table/footer is only partially populated (or a spurious $0.00 payment type row appears) 5. Apply the patch and repeat step 3 6. The modal renders fully and correctly, with no console error and no spurious zero-amount row -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43289 --- Comment #1 from Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> --- Created attachment 203588 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=203588&action=edit Bug 43289: Fix TypeError in cashup summary modal when totals are strings format_price() is only defined on Number.prototype (see format_price.inc), but the /api/v1/cashups/:id summary endpoint's grouped and total amounts (out.total, income.total, type.total, data.summary.total, and the derived cashCollected/actualAmount) can come back as strings - accountlines/cashup DECIMAL columns are frequently stringified by the DB layer before JSON encoding. Calling out.total.format_price() on a string throws 'TypeError: out.total.format_price is not a function', aborting the rest of the modal's success handler and leaving the cashup summary partially or fully unrendered. Wrap every such value in Number(...) before calling format_price(). Also fixed the 'Other payment types collected' filter, which compared type.total !== 0 with strict inequality - always true when type.total is a string, so a $0.00 payment type could show a spurious row. Test plan: 1) Configure more than one payment type in CashupPaymentTypes 2) Complete a cashup with income/payout/refund transactions across several payment types, including at least one with a zero total 3) Click the cashup's Summary link 4) Before this patch: browser console shows a TypeError and the modal render stops partway through (or a $0.00 payment type row appears) 5) Apply the patch, repeat step 3 6) Modal renders fully and correctly, no console error, no spurious zero-amount row -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43289 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |martin.renvoize@openfifth.c |ity.org |o.uk -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=43289 Martin Renvoize (ashimema) <martin.renvoize@openfifth.co.uk> changed: What |Removed |Added ---------------------------------------------------------------------------- QA Contact|martin.renvoize@openfifth.c |andrew@bywatersolutions.com |o.uk | -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org