From e5097146f785a1b7690dd1be8a9a0aec190a404b Mon Sep 17 00:00:00 2001 From: =?utf8?q?Bernd=20Ble=C3=9Fmann?= Date: Tue, 25 Aug 2020 15:26:36 +0200 Subject: [PATCH] =?utf8?q?S/D/Shipto:=20Methode=20is=5Fempty,=20um=20auf?= =?utf8?q?=20leere=20Lieferadresse=20zu=20pr=C3=BCfen?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- SL/DB/Shipto.pm | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) 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 -- 2.20.1