From: Bernd Bleßmann Date: Mon, 30 Nov 2015 16:27:22 +0000 (+0100) Subject: Einlagern: Bei einem Fehler die eingebenen Werte in der Maske wieder herstellen X-Git-Tag: release-3.4.1~563 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=81b7704d2bb081e06e5c1b4d7d8f41fa00ca0d10;p=kivitendo-erp.git Einlagern: Bei einem Fehler die eingebenen Werte in der Maske wieder herstellen Zwei Dinge: Zum einen einen $::form->error abfangen und Fehler auch mit flash ausgeben, wenn das Speichern der Lagerbewegung fehl schlägt (passiert z.B. wenn man ein falsches Datumsformat beim Mindesthaltbarkeitsdatum eingibt). Zum anderen bei einem Fehler dem redirect die ursprünglich eingegebenen Werte wieder mitgeben, damit man den Fehler korrigieren und dann einlagern kann. --- diff --git a/SL/Controller/Inventory.pm b/SL/Controller/Inventory.pm index a0764abfd..ceebf6826 100644 --- a/SL/Controller/Inventory.pm +++ b/SL/Controller/Inventory.pm @@ -15,6 +15,8 @@ use SL::Presenter; use SL::DBUtils; use SL::Helper::Flash; +use English qw(-no_match_vars); + use Rose::Object::MakeMethods::Generic ( 'scalar --get_set_init' => [ qw(warehouses units p) ], 'scalar' => [ qw(warehouse bin unit part) ], @@ -43,34 +45,49 @@ sub action_stock_in { sub action_stock { my ($self) = @_; + my $transfer_error; my $qty = $::form->parse_amount(\%::myconfig, $::form->{qty}); if (!$qty) { - flash_later('error', t8('Cannot stock without amount')); + $transfer_error = t8('Cannot stock without amount'); } elsif ($qty < 0) { - flash_later('error', t8('Cannot stock negative amounts')); + $transfer_error = t8('Cannot stock negative amounts'); } else { # do stock - WH->transfer({ - parts => $self->part, - dst_bin => $self->bin, - dst_wh => $self->warehouse, - qty => $qty, - unit => $self->unit, - transfer_type => 'stock', - chargenumber => $::form->{chargenumber}, - bestbefore => $::form->{bestbefore}, - ean => $::form->{ean}, - comment => $::form->{comment}, + $::form->throw_on_error(sub { + eval { + WH->transfer({ + parts => $self->part, + dst_bin => $self->bin, + dst_wh => $self->warehouse, + qty => $qty, + unit => $self->unit, + transfer_type => 'stock', + chargenumber => $::form->{chargenumber}, + bestbefore => $::form->{bestbefore}, + ean => $::form->{ean}, + comment => $::form->{comment}, + }); + 1; + } or do { $transfer_error = $EVAL_ERROR->getMessage; } }); - if ($::form->{write_default_bin}) { - $self->part->load; # onhand is calculated in between. don't mess that up - $self->part->bin($self->bin); - $self->part->warehouse($self->warehouse); - $self->part->save; + if (!$transfer_error) { + if ($::form->{write_default_bin}) { + $self->part->load; # onhand is calculated in between. don't mess that up + $self->part->bin($self->bin); + $self->part->warehouse($self->warehouse); + $self->part->save; + } + + flash_later('info', t8('Transfer successful')); } + } - flash_later('info', t8('Transfer successful')); + my %additional_redirect_params = (); + if ($transfer_error) { + flash_later('error', $transfer_error); + $additional_redirect_params{$_} = $::form->{$_} for qw(qty chargenumber bestbefore ean comment); + $additional_redirect_params{qty} = $qty; } # redirect @@ -80,6 +97,7 @@ sub action_stock { bin_id => $self->bin->id, warehouse_id => $self->warehouse->id, unit_id => $self->unit->id, + %additional_redirect_params, ); } diff --git a/templates/webpages/inventory/warehouse_selection_stock.html b/templates/webpages/inventory/warehouse_selection_stock.html index 5901f6deb..e3119913c 100644 --- a/templates/webpages/inventory/warehouse_selection_stock.html +++ b/templates/webpages/inventory/warehouse_selection_stock.html @@ -29,25 +29,25 @@ [% 'Charge number' | $T8 %] - [% L.input_tag('chargenumber', SELF.chargenumber, size=30) %] + [% L.input_tag('chargenumber', FORM.chargenumber, size=30) %] [% IF INSTANCE_CONF.get_show_bestbefore %] [% 'Best Before' | $T8 %] - [% L.date_tag('bestbefore', SELF.bestbefore) %] + [% L.date_tag('bestbefore', FORM.bestbefore) %] [%- END %] [% 'EAN' | $T8 %] - + [% L.input_tag('ean', FORM.ean, size=30) %] [% 'Quantity' | $T8 %] - + [% L.input_tag('qty', LxERP.format_amount(FORM.qty), size=10) %] [%- IF SELF.part.unit %] [% L.select_tag('unit_id', SELF.part.available_units, title_key='name', default=SELF.unit.id) %] [%- ELSE %] @@ -58,7 +58,7 @@ [% 'Optional comment' | $T8 %] - + [% L.input_tag('comment', FORM.comment, size=60) %]