From f7c37ff950e74addee71558c2f3e1860ce7bf967 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jan=20B=C3=BCren?= Date: Mon, 10 Nov 2014 15:23:51 +0100 Subject: [PATCH] OrderItems-> delivered_qty in helper-funktion ausgelagert MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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. --- SL/DB/OrderItem.pm | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) 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); } -- 2.20.1