X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FShipto.pm;h=6cfcba66ffd5c814fa9607e6ff055c0d6f0f4fab;hb=2b2a37fd95a5cae44a8c6862e79f86d2cbc2a189;hp=99a4036a9b8a7c6a9e9cb73e60a2c7d739e46426;hpb=86bc3cfad9b7f7b3682277a19ec5a7aa3fbd8d93;p=kivitendo-erp.git 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