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.
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;
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 {
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);
}