From: G. Richardson Date: Tue, 30 May 2017 13:27:33 +0000 (+0200) Subject: neue SL::DB::Part Methode used_in_record. X-Git-Tag: release-3.5.4~1057 X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/commitdiff_plain/bf78e242d22391be5f937f410153342f7acaf59b?ds=inline neue SL::DB::Part Methode used_in_record. 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. --- 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