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) ],
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
bin_id => $self->bin->id,
warehouse_id => $self->warehouse->id,
unit_id => $self->unit->id,
+ %additional_redirect_params,
);
}
<tr>
<th align="right" nowrap>[% 'Charge number' | $T8 %]</th>
- <td>[% L.input_tag('chargenumber', SELF.chargenumber, size=30) %]</td>
+ <td>[% L.input_tag('chargenumber', FORM.chargenumber, size=30) %]</td>
</tr>
[% IF INSTANCE_CONF.get_show_bestbefore %]
<tr>
<th align="right" nowrap>[% 'Best Before' | $T8 %]</th>
- <td>[% L.date_tag('bestbefore', SELF.bestbefore) %]</td>
+ <td>[% L.date_tag('bestbefore', FORM.bestbefore) %]</td>
</tr>
[%- END %]
<tr>
<th align="right" nowrap>[% 'EAN' | $T8 %]</th>
- <td><input name="ean" size="30" value="[% HTML.escape(ean) %]"></td>
+ <td>[% L.input_tag('ean', FORM.ean, size=30) %]</td>
</tr>
<tr>
<th align="right" nowrap>[% 'Quantity' | $T8 %]</th>
<td>
- <input name="qty" size="10" value="[% HTML.escape(LxERP.format_amount(qty)) %]">
+ [% 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 %]
<tr>
<th align="right" nowrap>[% 'Optional comment' | $T8 %]</th>
- <td><input name="comment" size="60" value="[% HTML.escape(comment) %]"></td>
+ <td>[% L.input_tag('comment', FORM.comment, size=60) %]</td>
</tr>
</table>