summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xLedgerSMB/Template.pm5
-rw-r--r--t/04-template-handling.t25
2 files changed, 28 insertions, 2 deletions
diff --git a/LedgerSMB/Template.pm b/LedgerSMB/Template.pm
index aff967a0..0c396ac6 100755
--- a/LedgerSMB/Template.pm
+++ b/LedgerSMB/Template.pm
@@ -205,8 +205,9 @@ sub _preprocess {
if (UNIVERSAL::isa($vars, 'Math::BigFloat')){
$vars =
LedgerSMB::format_amount('LedgerSMB',
- {amount => $vars.
- user => $self->{myconfig} });
+ amount => $vars,
+ user => $self->{myconfig},
+ precision => 2);
}
my $type = ref($vars);
diff --git a/t/04-template-handling.t b/t/04-template-handling.t
index 27e63bf3..e5cd0347 100644
--- a/t/04-template-handling.t
+++ b/t/04-template-handling.t
@@ -344,6 +344,31 @@ SKIP: {
'Template, render (PDF): testfile removed');
}
+#########################################
+## LedgerSMB::Template private methods ##
+#########################################
+
+use Math::BigFloat;
+$template = undef;
+$template = new LedgerSMB::Template('user' => {numberformat => '1.000,00'},
+ 'format' => 'HTML', 'template' => '04-template', 'no_auto_output' => 1);
+ok(defined $template,
+ 'Template, private (_preprocess): Object creation with format and template');
+isa_ok($template, 'LedgerSMB::Template',
+ 'Template, private (_preprocess): Object creation with format and template');
+my $number = Math::BigFloat->new(17.5);
+isa_ok($number, 'Math::BigFloat',
+ 'Template, private (_preprocess): number');
+$template->_preprocess($number);
+cmp_ok($number, 'eq', '17,50',
+ 'Template, private (_preprocess): Math::BigFloat conversion');
+$number = [Math::BigFloat->new(1008.51), 'hello'];
+$template->_preprocess($number);
+cmp_ok($number->[0], 'eq', '1.008,51',
+ 'Template, private (_preprocess): Math::BigFloat conversion (array)');
+cmp_ok($number->[1], 'eq', 'hello',
+ 'Template, private (_preprocess): no conversion (array)');
+
###################################
## LedgerSMB::Template::Elements ##
###################################