use strict;
use Carp;
+use List::MoreUtils qw(all);
+
+use SL::Util qw(trim);
use SL::DB::MetaSetup::Shipto;
use SL::DB::Manager::Shipto;
__PACKAGE__->meta->initialize;
+
sub displayable_id {
my $self = shift;
my $text = join('; ', grep { $_ } (map({ $self->$_ } qw(shiptoname shiptostreet)),
|| 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];
=over 4
+=item C<is_empty>
+
+Returns truish if all fields to consider are empty, falsish if not.
+Fields are trimmed before the test is performed.
+C<shiptocp_gender> 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<clone $target>
Creates and returns a clone of the current object. The mandatory