X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/86bc3cfad9b7f7b3682277a19ec5a7aa3fbd8d93..53593baa211863fbf66540cf1bcc36c8fb37257f:/SL/DB/Shipto.pm 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