From: Sven Schöling Date: Fri, 28 May 2021 16:46:39 +0000 (+0200) Subject: Inventory: Exception Klassen korrigiert X-Git-Tag: kivitendo-mebil_0.1-0~9^2~204 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=cb53cdd0f403a22c4257ac75204ae4cc5fb8710f;p=kivitendo-erp.git Inventory: Exception Klassen korrigiert Exception::Class behandelt message und error speziell, und dadurch gingen im portierten Inventory Helper feature die exceptions kaputt. In SL::X ist jetzt ein Kommentar der das beschreibt. --- diff --git a/SL/Helper/Inventory.pm b/SL/Helper/Inventory.pm index da3e5b1d8..147bc7d76 100644 --- a/SL/Helper/Inventory.pm +++ b/SL/Helper/Inventory.pm @@ -197,8 +197,8 @@ sub allocate { } if ($rest_qty > 0) { die SL::X::Inventory::Allocation->new( - error => 'not enough to allocate', - msg => t8("can not allocate #1 units of #2, missing #3 units", _format_number($qty), $part->displayable_name, _format_number($rest_qty)), + code => 'not enough to allocate', + message => t8("can not allocate #1 units of #2, missing #3 units", _format_number($qty), $part->displayable_name, _format_number($rest_qty)), ); } else { if ($params{constraints}) { @@ -238,8 +238,8 @@ sub check_constraints { if ('CODE' eq ref $constraints) { if (!$constraints->(@$allocations)) { die SL::X::Inventory::Allocation->new( - error => 'allocation constraints failure', - msg => t8("Allocations didn't pass constraints"), + code => 'allocation constraints failure', + message => t8("Allocations didn't pass constraints"), ); } } else { @@ -272,8 +272,8 @@ sub check_constraints { SL::DB::Bin->load_cached($_->bin_id)->full_description, _format_number($_->qty), _format_number($needed), $_->chargenumber ? $_->chargenumber : '--') for @allocs; die SL::X::Inventory::Allocation->new( - error => 'allocation constraints failure', - msg => $err, + code => 'allocation constraints failure', + message => $err, ); } } @@ -319,7 +319,10 @@ sub produce_assembly { $allocations_by_part{ $assembly->parts_id } -= $assembly->qty * $qty; } - die "allocations are insufficient for production" if any { $_ < 0 } values %allocations_by_part; + die SL::X::Inventory::Allocation->new( + code => "allocations are insufficient for production", + message => t8('can not allocate enough resources for production'), + ) if any { $_ < 0 } values %allocations_by_part; } my @transfers; diff --git a/SL/X.pm b/SL/X.pm index c3533e2ef..e1707cd0e 100644 --- a/SL/X.pm +++ b/SL/X.pm @@ -5,6 +5,11 @@ use warnings; use SL::X::Base; + +# note! the default fields "message", "error" and "show_trace" are created by +# Exception::Class if message or error are given, they are used for +# stringification, so don't use them in error_templates +# use Exception::Class ( 'SL::X::FormError' => { isa => 'SL::X::Base', @@ -32,13 +37,11 @@ use Exception::Class ( }, 'SL::X::Inventory' => { isa => 'SL::X::Base', - fields => [ qw(msg error) ], - defaults => { error_template => [ '%s: %s', qw(msg) ] }, + fields => [ qw(code) ], }, 'SL::X::Inventory::Allocation' => { isa => 'SL::X::Base', - fields => [ qw(msg error) ], - defaults => { error_template => [ '%s: %s', qw(msg) ] }, + fields => [ qw(code) ], }, );