Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 3f0ed511

Von Moritz Bunkus vor fast 9 Jahren hinzugefügt

  • ID 3f0ed511a589aca9642391108a960ef4e8a6286d
  • Vorgänger c7241bf7
  • Nachfolger 492c85c2

Shipto: Methode zum Clonen in SL::DB::Shipto und nicht in DeliveryOrder->new_from

Unterschiede anzeigen:

SL/DB/DeliveryOrder.pm
136 136
  # save it, too.
137 137
  my $custom_shipto;
138 138
  if (!$source->shipto_id && $source->id) {
139
    my $old = $source->custom_shipto;
140
    if ($old) {
141
      $custom_shipto = SL::DB::Shipto->new(
142
        map  { +($_ => $old->$_) }
143
        grep { !m{^ (?: itime | mtime | shipto_id | trans_id ) $}x }
144
        map  { $_->name }
145
        @{ $old->meta->columns }
146
      );
147
      $custom_shipto->module('DO');
148
    }
139
    $custom_shipto = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto;
149 140

  
150 141
  } else {
151 142
    $args{shipto_id} = $source->shipto_id;
SL/DB/Shipto.pm
2 2

  
3 3
use strict;
4 4

  
5
use Carp;
6

  
5 7
use SL::DB::MetaSetup::Shipto;
6 8
use SL::DB::Manager::Shipto;
7 9
use SL::DB::Helper::CustomVariables (
......
43 45
  $_[0];
44 46
}
45 47

  
48
sub clone {
49
  my ($self, $target) = @_;
50

  
51
  my $type   = ref($target) || $target;
52
  my $module = $type =~ m{::Order$}               ? 'OE'
53
             : $type =~ m{::DeliveryOrder$}       ? 'DO'
54
             : $type =~ m{::Invoice$}             ? 'AR'
55
             : $type =~ m{::(?:Customer|Vendor)$} ? 'CT'
56
             :                                      croak "Unsupported target class '$type'";
57

  
58
  my $new_shipto = SL::DB::Shipto->new(
59
    (map  { +($_ => $self->$_) }
60
     grep { !m{^ (?: itime | mtime | shipto_id | trans_id ) $}x }
61
     map  { $_->name }
62
     @{ $self->meta->columns }),
63
    module => $module,
64
  );
65

  
66
  return $new_shipto;
67
}
68

  
46 69
1;
70

  
71
__END__
72

  
73
=pod
74

  
75
=encoding utf8
76

  
77
=head1 NAME
78

  
79
SL::DB::Shipto - Database model for shipping addresses
80

  
81
=head1 SYNOPSIS
82

  
83
  my $order = SL::DB::Order->new(id => …)->load;
84
  if ($order->custom_shipto) {
85
    my $cloned_shipto = $order->custom_shipto->clone('SL::DB::Invoice');
86
  }
87

  
88
=head1 FUNCTIONS
89

  
90
=over 4
91

  
92
=item C<clone $target>
93

  
94
Creates and returns a clone of the current object. The mandatory
95
parameter C<$target> must be either an instance of a Rose DB class or
96
the name of one. It's used for setting the new instance's C<module>
97
attribute to the correct value.
98

  
99
Currently the following classes are supported:
100

  
101
=over 2
102

  
103
=item C<SL::DB::Order>
104

  
105
=item C<SL::DB::DeliveryOrder>
106

  
107
=item C<SL::DB::Invoice>
108

  
109
=item C<SL::DB::Customer>
110

  
111
=item C<SL::DB::Vendor>
112

  
113
=back
114

  
115
=back
116

  
117
=head1 BUGS
118

  
119
Nothing here yet.
120

  
121
=head1 AUTHOR
122

  
123
Moritz Bunkus E<lt>m.bunkus@linet-services.deE<gt>
124

  
125
=cut

Auch abrufbar als: Unified diff