From 9e99dce5b45847d3ebed445a277aa37ba6798173 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 25 Sep 2017 13:07:04 +0200 Subject: [PATCH] =?utf8?q?DATEV-Export:=20Feldpr=C3=BCfung=20als=20Warnung?= =?utf8?q?en=20ausgeben?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Anstatt hart auszusteigen (die), erhält der Anwender jetzt eine Übersicht der fehlerhaften Feldwerte mit einem Minimum an Zusatz-Info (Umsatz der Transaktion). Entsprechend den Test-Fall angepasst. --- SL/DATEV.pm | 21 +++++++++++++---- bin/mozilla/datev.pl | 2 +- locale/de/all | 2 ++ t/datev/datev_format_2018.t | 33 ++++++++++++++++++--------- templates/webpages/datev/export3.html | 9 +++++++- 5 files changed, 50 insertions(+), 17 deletions(-) diff --git a/SL/DATEV.pm b/SL/DATEV.pm index 61e4d80dd..0d6915f40 100644 --- a/SL/DATEV.pm +++ b/SL/DATEV.pm @@ -215,6 +215,16 @@ sub trans_id { return $self->{trans_id}; } +sub warnings { + my $self = shift; + + if (@_) { + $self->{warnings} = \@_; + } else { + return $self->{warnings}; + } +} + sub accnofrom { my $self = shift; @@ -1365,6 +1375,7 @@ sub csv_buchungsexport { push @array_of_datev, \@csv_headers; push @array_of_datev, [ map { $_->{csv_header_name} } @csv_columns ]; + my @warnings; foreach my $row ( @datev_lines ) { my @current_datev_row; @@ -1389,15 +1400,17 @@ sub csv_buchungsexport { die "Incorrect lenght of field" if length($row->{ $column->{kivi_datev_name} }) > $column->{max_length}; } if (exists $column->{valid_check} && $column->{kivi_datev_name} ne 'not yet implemented') { - # more checks - die "Not a valid value: '$row->{ $column->{kivi_datev_name} }'" . - " for '$column->{kivi_datev_name}' with amount '$row->{umsatz}'" - unless ($column->{valid_check}->($row->{ $column->{kivi_datev_name} })); + # more checks, listed as user warnings + push @warnings, t8("Wrong field value '#1' for field '#2' for the transaction" . + " with amount '#3'",$row->{ $column->{kivi_datev_name} }, + $column->{kivi_datev_name},$row->{umsatz}) + unless ($column->{valid_check}->($row->{ $column->{kivi_datev_name} })); } push @current_datev_row, $row->{ $column->{kivi_datev_name} }; } push @array_of_datev, \@current_datev_row; } + $self->warnings(@warnings) if @warnings; return \@array_of_datev; } diff --git a/bin/mozilla/datev.pl b/bin/mozilla/datev.pl index 129dedaa7..32032e514 100644 --- a/bin/mozilla/datev.pl +++ b/bin/mozilla/datev.pl @@ -127,7 +127,7 @@ sub export3 { setup_datev_export3_action_bar(download_token => $datev->download_token); $::form->header; - print $::form->parse_html_template('datev/export3'); + print $::form->parse_html_template('datev/export3', { WARNINGS => $datev->warnings }); } else { $::form->error("Export schlug fehl.\n" . join "\n", $datev->errors); } diff --git a/locale/de/all b/locale/de/all index de817d151..3b197d213 100755 --- a/locale/de/all +++ b/locale/de/all @@ -3572,6 +3572,7 @@ $self->{texts} = { 'Warn before saving orders with duplicate parts (new controller only)' => 'Beim Speichern warnen, wenn doppelte Artikel in einem Auftrag sind', 'Warning' => 'Warnung', 'Warning! Loading a draft will discard unsaved data!' => 'Achtung! Beim Laden eines Entwurfs werden ungespeicherte Daten verworfen!', + 'Warning: One or more field value are not in valid DATEV format at:' => 'Warnung: Ein oder mehere Felder haben ungültige Feldwerte laut DATEV-Spezifikation bei:', 'Warnings and errors' => 'Warnungen und Fehler', 'Watch status' => 'Hintergrund-Job Status', 'WebDAV' => 'WebDAV', @@ -3599,6 +3600,7 @@ $self->{texts} = { 'Working copy; no description yet' => 'Arbeitskopie; noch keine Beschreibung', 'Working on export' => 'Generiere Export', 'Write bin to default bin in part?' => 'Diesen Lagerplatz als Standardlagerplatz im Artikel setzen?', + 'Wrong field value \'#1\' for field \'#2\' for the transaction with amount \'#3\'' => 'Falscher Feldwert \'#1\' für Feld \'#2\' bei der Transaktion mit dem Umsatz von \'#3\'', 'Wrong tax keys recorded' => 'Gespeicherte Steuerschlüssel sind falsch', 'Wrong taxes recorded' => 'Gespeicherte Steuern passen nicht zum Steuerschlüssel', 'X' => 'X', diff --git a/t/datev/datev_format_2018.t b/t/datev/datev_format_2018.t index aeb9979ed..9857e0709 100644 --- a/t/datev/datev_format_2018.t +++ b/t/datev/datev_format_2018.t @@ -68,20 +68,31 @@ $datev1->generate_datev_lines; # check conversion to csv $datev1->from($startdate); $datev1->to($enddate); -eval { - $datev1->csv_buchungsexport(); - 1; }; -like($@, qr/^Not a valid value: '' for 'belegfeld1' with .*/, "wrong encoding"); +$datev1->csv_buchungsexport(); +my @warnings = $datev1->warnings; +is(@warnings[0]->[0]->{untranslated}, + 'Wrong field value \'#1\' for field \'#2\' for the transaction with amount \'#3\'', 'wrong_encoding'); -# redefine invnumber, but still broken + +# redefine invnumber, we have mixed encodings, should still generate a warning $invoice->invnumber('ݗݘݰݶmuh'); $invoice->save(); -$datev1->generate_datev_data; -$datev1->generate_datev_lines; -eval { - $datev1->csv_buchungsexport(); - 1; }; -like($@, qr/^Not a valid value: '' for 'belegfeld1' with amount/, "mixed encoding"); + +my $datev3 = SL::DATEV->new( + dbh => $dbh, + trans_id => $invoice->id, +); + +$datev3->from($startdate); +$datev3->to($enddate); +$datev3->generate_datev_data; +$datev3->generate_datev_lines; +$datev3->csv_buchungsexport; +@warnings = []; +@warnings = $datev3->warnings; +is(@warnings[0]->[0]->{untranslated}, + 'Wrong field value \'#1\' for field \'#2\' for the transaction with amount \'#3\'', 'mixed_wrong_encoding'); + # create one haben buchung with GLTransaction today diff --git a/templates/webpages/datev/export3.html b/templates/webpages/datev/export3.html index cc5fdf9e9..0e5fb116c 100644 --- a/templates/webpages/datev/export3.html +++ b/templates/webpages/datev/export3.html @@ -15,7 +15,14 @@ [% END %] -
+

+[% IF WARNINGS.size %] + [% 'Warning: One or more field value are not in valid DATEV format at:' | $T8 %]

+ [%- FOREACH warning = WARNINGS %] + [% warning | $T8 %]
+ [%- END %] +
+[% END %] [% IF datev.net_gross_differences.size %] [% INCLUDE 'datev/net_gross_difference.html' -- 2.20.1