X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=SL%2FDB%2FShipto.pm;h=99a4036a9b8a7c6a9e9cb73e60a2c7d739e46426;hb=356fec7ed87236e0b68c0ef45fe5f99c8b1f5038;hp=5e2813d2fe6eb2ee66d462b1c52239dd9905aadf;hpb=6ef4190ee87f3b7ba053bcc247aa92b92ef02cb4;p=kivitendo-erp.git diff --git a/SL/DB/Shipto.pm b/SL/DB/Shipto.pm index 5e2813d2f..99a4036a9 100644 --- a/SL/DB/Shipto.pm +++ b/SL/DB/Shipto.pm @@ -2,6 +2,8 @@ package SL::DB::Shipto; use strict; +use Carp; + use SL::DB::MetaSetup::Shipto; use SL::DB::Manager::Shipto; use SL::DB::Helper::CustomVariables ( @@ -43,4 +45,82 @@ sub detach { $_[0]; } +sub clone { + my ($self, $target) = @_; + + my $type = ref($target) || $target; + my $module = $type =~ m{::Order$} ? 'OE' + : $type =~ m{::DeliveryOrder$} ? 'DO' + : $type =~ m{::Invoice$} ? 'AR' + : $type =~ m{::(?:Customer|Vendor)$} ? 'CT' + : croak "Unsupported target class '$type'"; + + my $new_shipto = SL::DB::Shipto->new( + (map { +($_ => $self->$_) } + grep { !m{^ (?: itime | mtime | shipto_id | trans_id ) $}x } + map { $_->name } + @{ $self->meta->columns }), + module => $module, + custom_variables => [ map { $_->clone_and_reset } @{ $self->custom_variables } ], + ); + + return $new_shipto; +} + 1; + +__END__ + +=pod + +=encoding utf8 + +=head1 NAME + +SL::DB::Shipto - Database model for shipping addresses + +=head1 SYNOPSIS + + my $order = SL::DB::Order->new(id => …)->load; + if ($order->custom_shipto) { + my $cloned_shipto = $order->custom_shipto->clone('SL::DB::Invoice'); + } + +=head1 FUNCTIONS + +=over 4 + +=item C + +Creates and returns a clone of the current object. The mandatory +parameter C<$target> must be either an instance of a Rose DB class or +the name of one. It's used for setting the new instance's C +attribute to the correct value. + +Currently the following classes are supported: + +=over 2 + +=item C + +=item C + +=item C + +=item C + +=item C + +=back + +=back + +=head1 BUGS + +Nothing here yet. + +=head1 AUTHOR + +Moritz Bunkus Em.bunkus@linet-services.deE + +=cut