PriceSource: Featureabdeckung
[kivitendo-erp.git] / SL / PriceSource / MasterData.pm
index c639ccb..3f7c11d 100644 (file)
@@ -13,31 +13,59 @@ sub description { t8('Master Data') }
 sub available_prices {
   my ($self, %params) = @_;
 
-  my $part = $self->part;
+  return () unless $self->part;
 
-  return () unless $part;
-
-  # TODO: sellprice only in sales, lastcost in purchase
-  return $self->make_sellprice($part);
+  grep { $_->price > 0 } $self->record->is_sales
+    ? ($self->make_sellprice, $self->make_listprice)
+    : ($self->make_lastcost,  $self->make_listprice);
 }
 
 sub price_from_source {
   my ($self, $source, $spec) = @_;
 
-  if ($spec eq 'sellprice') {
-    return $self->make_sellprice($self->part);
-  }
+    $spec eq 'sellprice' ? $self->make_sellprice
+  : $spec eq 'lastcost'  ? $self->make_lastcost
+  : $spec eq 'listprice' ? $self->make_listprice
+  : do { die "unknown spec '$spec'" };
+}
+
+sub best_price {
+  $_[0]->record->is_sales
+  ? $_[0]->make_sellprice
+  : $_[0]->make_lastcost
 }
 
 sub make_sellprice {
-  my ($self, $part) = @_;
+  my ($self) = @_;
 
   return SL::PriceSource::Price->new(
-    price        => $part->sellprice,
+    price        => $self->part->sellprice,
     spec         => 'sellprice',
     description  => t8('Sellprice'),
     price_source => $self,
   );
 }
 
+sub make_listprice {
+  my ($self) = @_;
+
+  return SL::PriceSource::Price->new(
+    price        => $self->part->listprice,
+    spec         => 'listprice',
+    description  => t8('List Price'),
+    price_source => $self,
+  );
+}
+
+sub make_lastcost {
+  my ($self) = @_;
+
+  return SL::PriceSource::Price->new(
+    price        => $self->part->lastcost,
+    spec         => 'lastcost',
+    description  => t8('Lastcost'),
+    price_source => $self,
+  );
+}
+
 1;