From bf78e242d22391be5f937f410153342f7acaf59b Mon Sep 17 00:00:00 2001 From: "G. Richardson" Date: Tue, 30 May 2017 15:27:33 +0200 Subject: [PATCH] neue SL::DB::Part Methode used_in_record. MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit 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 | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/SL/DB/Part.pm b/SL/DB/Part.pm index df0169d9c..c2cb641ae 100644 --- a/SL/DB/Part.pm +++ b/SL/DB/Part.pm @@ -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 + +Checks if this article has been used in orders, invoices or delivery orders. + =item C Checks if this article is used in orders, invoices, delivery orders or -- 2.20.1