From: Bernd Bleßmann Date: Tue, 25 Aug 2020 13:26:36 +0000 (+0200) Subject: S/D/Shipto: Methode is_empty, um auf leere Lieferadresse zu prüfen X-Git-Tag: release-3.5.6.1~59 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=e5097146f785a1b7690dd1be8a9a0aec190a404b;p=kivitendo-erp.git S/D/Shipto: Methode is_empty, um auf leere Lieferadresse zu prüfen --- diff --git a/SL/DB/Shipto.pm b/SL/DB/Shipto.pm index 99a4036a9..6cfcba66f 100644 --- a/SL/DB/Shipto.pm +++ b/SL/DB/Shipto.pm @@ -3,6 +3,9 @@ package SL::DB::Shipto; use strict; use Carp; +use List::MoreUtils qw(all); + +use SL::Util qw(trim); use SL::DB::MetaSetup::Shipto; use SL::DB::Manager::Shipto; @@ -16,6 +19,7 @@ our @SHIPTO_VARIABLES = qw(shiptoname shiptostreet shiptozipcode shiptocity ship __PACKAGE__->meta->initialize; + sub displayable_id { my $self = shift; my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(shiptoname shiptostreet)), @@ -40,6 +44,15 @@ sub used { || SL::DB::Manager::DeliveryOrder->get_all_count(query => [ shipto_id => $self->shipto_id ]); } +sub is_empty { + my ($self) = @_; + + # todo: consider cvars + my @fields_to_consider = grep { !m{^ (?: itime | mtime | shipto_id | trans_id | shiptocp_gender | module ) $}x } map {$_->name} $self->meta->columns; + + return all { trim($self->$_) eq '' } @fields_to_consider; +} + sub detach { $_[0]->trans_id(undef); $_[0]; @@ -90,6 +103,18 @@ SL::DB::Shipto - Database model for shipping addresses =over 4 +=item C + +Returns truish if all fields to consider are empty, falsish if not. +Fields are trimmed before the test is performed. +C is not considered because in forms this is usually +a selection with 'm' as default value. +CVar fields are not considered by now. + +=back + +=over 4 + =item C Creates and returns a clone of the current object. The mandatory