Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 492c85c2

Von Moritz Bunkus vor fast 9 Jahren hinzugefügt

  • ID 492c85c2f086299b3e398188e06541d6d44d3741
  • Vorgänger 3f0ed511
  • Nachfolger 0eb90109

DeliveryOrder->new_from: kein $custom_shipto-Objekt zurückgeben

Falls das Quellobjekt eine individuelle Lieferadresse besaß, wurden bei
new_from() zwei Objekte zurückgegeben: das neue Lieferscheinobjekt und
ein Clone der individuellen Lieferadresse. Diese waren nicht verknüpft.
Der Aufrufer musste daher zuerst das Lieferscheinobjekt speichern,
dessen ID beim gecloneten Lieferadressenobjekt hinterlegen und das
anschließend speichern.

Dies ist umständlich und fehlerträchtig. So hat z.B. der einzige
bisherige Nutzer dieses Interfaces,
SL::DB::Order->convert_to_delivery_order, das bereits falsch gemacht und
vergessen, beim Lieferadressenobjekt die ID des neuen
Lieferscheinobjektes einzutragen. Somit wurden Lieferadressen erzeugt,
die keinerlei Verknüpfung hatten.

Das geänderte Interface hinterlegt das Objekt für die individuelle
Lieferadresse schlicht in $new_delivery_order->custom_shipto. Dort wird
das Objekt gespeichert, wenn der Lieferschein selber gespeichert wird.

Unterschiede anzeigen:

SL/DB/DeliveryOrder.pm
130 130

  
131 131
  # Custom shipto addresses (the ones specific to the sales/purchase
132 132
  # record and not to the customer/vendor) are only linked from
133
  # shipto -> delivery_orders. Meaning delivery_orders.shipto_id
134
  # will not be filled in that case. Therefore we have to return the
135
  # new shipto object as a separate object so that the caller can
136
  # save it, too.
137
  my $custom_shipto;
133
  # shipto → delivery_orders. Meaning delivery_orders.shipto_id
134
  # will not be filled in that case.
138 135
  if (!$source->shipto_id && $source->id) {
139
    $custom_shipto = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto;
136
    $args{custom_shipto} = $source->custom_shipto->clone($class) if $source->can('custom_shipto') && $source->custom_shipto;
140 137

  
141 138
  } else {
142 139
    $args{shipto_id} = $source->shipto_id;
......
172 169

  
173 170
  $delivery_order->items(\@items);
174 171

  
175
  return ($delivery_order, $custom_shipto);
172
  return $delivery_order;
176 173
}
177 174

  
178 175
sub customervendor {
......
258 255
The conversion copies order items into delivery order items. Dates are copied
259 256
as appropriate, e.g. the C<transdate> field will be set to the current date.
260 257

  
261
Returns one or two objects depending on the context. In list context
262
the new delivery order instance and a shipto instance will be
263
returned. In scalar instance only the delivery order instance is
264
returned.
265

  
266
Custom shipto addresses (the ones specific to the sales/purchase
267
record and not to the customer/vendor) are only linked from C<shipto>
268
to C<delivery_orders>. Meaning C<delivery_orders.shipto_id> will not
269
be filled in that case. That's why a separate shipto object is created
270
and returned.
271

  
272
The objects returned are not saved.
258
Returns the new delivery order instance. The object returned is not
259
saved.
273 260

  
274 261
C<%params> can include the following options:
275 262

  
SL/DB/Order.pm
157 157
sub convert_to_delivery_order {
158 158
  my ($self, @args) = @_;
159 159

  
160
  my ($delivery_order, $custom_shipto);
160
  my $delivery_order;
161 161
  if (!$self->db->with_transaction(sub {
162 162
    require SL::DB::DeliveryOrder;
163
    ($delivery_order, $custom_shipto) = SL::DB::DeliveryOrder->new_from($self, @args);
163
    $delivery_order = SL::DB::DeliveryOrder->new_from($self, @args);
164 164
    $delivery_order->save;
165
    $custom_shipto->save if $custom_shipto;
166 165
    $self->link_to_record($delivery_order);
167 166
    # TODO extend link_to_record for items, otherwise long-term no d.r.y.
168 167
    foreach my $item (@{ $delivery_order->items }) {
......
183 182
    $self->update_attributes(delivered => 1);
184 183
    1;
185 184
  })) {
186
    return wantarray ? () : undef;
185
    return undef;
187 186
  }
188 187

  
189
  return wantarray ? ($delivery_order, $custom_shipto) : $delivery_order;
188
  return $delivery_order;
190 189
}
191 190

  
192 191
sub number {
......
261 260
The arguments in C<%params> are passed to
262 261
L<SL::DB::DeliveryOrder::new_from>.
263 262

  
264
Returns C<undef> on failure. Otherwise the return value depends on the
265
context. In list context the new delivery order and a shipto instance
266
will be returned. In scalar instance only the delivery order instance
267
is returned.
268

  
269
Custom shipto addresses (the ones specific to the sales/purchase
270
record and not to the customer/vendor) are only linked from C<shipto>
271
to C<delivery_orders>. Meaning C<delivery_orders.shipto_id> will not
272
be filled in that case. That's why a separate shipto object is created
273
and returned.
263
Returns C<undef> on failure. Otherwise the new delivery order will be
264
returned.
274 265

  
275 266
=head2 C<convert_to_invoice %params>
276 267

  

Auch abrufbar als: Unified diff