neue SL::DB::Part Methode used_in_record.
authorG. Richardson <information@kivitendo-premium.de>
Tue, 30 May 2017 13:27:33 +0000 (15:27 +0200)
committerG. Richardson <information@kivitendo-premium.de>
Tue, 30 May 2017 13:36:42 +0000 (15:36 +0200)
Die Prüfung auf orphaned ist viel strenger, und sollte für z.B. Löschen
verwendet werden, während used_in_record nur prüft, ob der Artikel in
Belegen vorkommt.

SL/DB/Part.pm

index df0169d..c2cb641 100644 (file)
@@ -165,6 +165,24 @@ sub last_modification {
   return $self->mtime // $self->itime;
 };
 
+sub used_in_record {
+  my ($self) = @_;
+  die 'not an accessor' if @_ > 1;
+
+  return 1 unless $self->id;
+
+  my @relations = qw(
+    SL::DB::InvoiceItem
+    SL::DB::OrderItem
+    SL::DB::DeliveryOrderItem
+  );
+
+  for my $class (@relations) {
+    eval "require $class";
+    return 1 if $class->_get_manager_class->get_all_count(query => [ parts_id => $self->id ]);
+  }
+  return 0;
+}
 sub orphaned {
   my ($self) = @_;
   die 'not an accessor' if @_ > 1;
@@ -522,6 +540,10 @@ fields belonging to the tax zone given by C<$params{taxzone}>.
 
 The information retrieved by the function is cached.
 
+=item C<used_in_record>
+
+Checks if this article has been used in orders, invoices or delivery orders.
+
 =item C<orphaned>
 
 Checks if this article is used in orders, invoices, delivery orders or