Bug 22038: Fix excel export if CurrencyFormat is FR

DataTables excel export is broken if number decimal separator is a comma.

Test plan:
1 - Set syspref CurrencyFormat to US
2 - Export as excel a table with decimal numbers, patrons list with fines
for example.
3 - Open in libreoffice or excel, numbers are ok.
4 - Set syspref CurrencyFormat to FR
5 - Export and open again, number are wrong 25,10 is imported as 2510
6 - Apply patch
7 - Redo 1 to 4
8 - Excel export, number is 25,10

Signed-off-by: hakam <hakam@inlibro.com>
Signed-off-by: Florian Bontemps <florian.bontemps@biblibre.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Didier Gautheron 2020-12-11 10:46:04 +01:00 committed by Fridolin Somers
parent 31960e86df
commit 4a35fd5363

View file

@ -1,3 +1,4 @@
[% USE Koha %]
[% USE TablesSettings %]
<!-- columns_settings.inc -->
@ -41,15 +42,21 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
}
}
var export_numeric = {
body: function ( data, row, column, node ) {
var newnode = $(node);
if ( newnode.find(".noExport").length > 0 ) {
newnode = newnode.clone();
newnode.find(".noExport").remove();
}
let tp = newnode.text().replace( /\n/g, ' ' ).trim();
tp = $('<p>' + tp + '</p>').text();
return $.isNumeric(tp.replace(',', '.')) ? tp.replace(',', '.') : tp;
}
}
var export_buttons = [
{
extend: 'excelHtml5',
text: _("Excel"),
exportOptions: {
columns: exportColumns,
format: export_format
},
},
{
extend: 'csvHtml5',
text: _("CSV"),
@ -76,6 +83,30 @@ function KohaTable(id_selector, dt_parameters, columns_settings, add_filters) {
}
];
[% IF Koha.Preference("CurrencyFormat") != 'FR' %]
export_buttons.unshift (
{
extend: 'excelHtml5',
text: _("Excel"),
exportOptions: {
columns: exportColumns,
format: export_format
},
}
);
[% ELSE %]
export_buttons.unshift (
{
extend: 'excelHtml5',
text: _("Excel"),
exportOptions: {
columns: exportColumns,
format: export_numeric
},
}
);
[% END %]
dt_parameters[ "buttons" ] = [
{
fade: 100,