From: Jan Büren Date: Mon, 10 Nov 2014 14:23:51 +0000 (+0100) Subject: OrderItems-> delivered_qty in helper-funktion ausgelagert X-Git-Tag: release-3.2.0beta~261 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=f7c37ff950e74addee71558c2f3e1860ce7bf967;p=kivitendo-erp.git OrderItems-> delivered_qty in helper-funktion ausgelagert Ergänzung zum Commit von gerade: Da man nicht sicher sein kann, ob dieser Wert als Objekt-Variable zu dem Zeitpunkt (t2) schon berechnet wurde, entsprechend in eine nach perl-konvention private (_delivered_qty) funktion ausgelagert. --- diff --git a/SL/DB/OrderItem.pm b/SL/DB/OrderItem.pm index 65772955f..1925c8085 100644 --- a/SL/DB/OrderItem.pm +++ b/SL/DB/OrderItem.pm @@ -37,6 +37,13 @@ sub shipped_qty { sub delivered_qty { my ($self) = @_; + $self->_delivered_qty unless $self->{delivered_qty}; + return $self->{delivered_qty}; +} + +sub _delivered_qty { + my ($self) = @_; + my $d_orders = $self->order->linked_records(direction => 'to', to => 'SL::DB::DeliveryOrder'); my @d_orders_delivered = grep { $_->delivered } @$d_orders; @@ -45,7 +52,6 @@ sub delivered_qty { require SL::AM; $self->{delivered_qty} = sum(map { AM->convert_unit($_->unit => $self->unit) * $_->qty } @doi_delivered); - return $self->{delivered_qty}; } sub value_of_goods { @@ -53,6 +59,7 @@ sub value_of_goods { my $price_factor = $self->price_factor || 1; + $self->_delivered_qty unless $self->{delivered_qty}; return ($self->{delivered_qty} * $self->sellprice * (1 - $self->discount ) / $price_factor); }