Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 4d2ba312

Von Sven Schöling vor mehr als 7 Jahren hinzugefügt

  • ID 4d2ba3125019794b857b71523c8d02e591ebf631
  • Vorgänger 1baa85d7
  • Nachfolger 66d68994

SL::Helper::ShippedQty: write_to garantiert eine Zahl für shipped_qty

Unterschiede anzeigen:

SL/Helper/ShippedQty.pm
207 207

  
208 208
  for my $obj (@$objects) {
209 209
    if ('SL::DB::OrderItem' eq ref $obj) {
210
      $obj->{shipped_qty} = $shipped_qty->{$obj->id};
210
      $obj->{shipped_qty} = $shipped_qty->{$obj->id} //= 0;
211 211
      $obj->{delivered}   = $shipped_qty->{$obj->id} == $obj->qty;
212 212
    } elsif ('SL::DB::Order' eq ref $obj) {
213 213
      if (exists $obj->{orderitems}) {
......
452 452

  
453 453
=item C<write_to_objects>
454 454

  
455
Save the C<shipped_qty> and C<delivered> state to the objects. If L</calculate>
456
was called with objects, then C<write_to_objects> will use these.
455
Save the C<shipped_qty> and C<delivered> state to the given objects. If
456
L</calculate> was called with objects, then C<write_to_objects> will use these.
457

  
458
C<shipped_qty> and C<delivered> will be directly infused into the objects
459
without calling the accessor for delivered. If you want to save afterwards,
460
you'll have to do that yourself.
461

  
462
C<shipped_qty> is guaranteed to be coerced to a number. If no delivery_order
463
was found it will be set to zero.
464

  
465
C<delivered> is guaranteed only to be the correct boolean value, but not
466
any specific value.
457 467

  
458 468
=item C<shipped_qty>
459 469

  
460 470
Valid after L</calculate>. Returns a hasref with shipped qtys by orderitems id.
461 471

  
472
Unlike the result of C</write_to>, entries in C<shipped_qty> may be C<undef> if
473
linked elements were found.
474

  
462 475
=item C<delivered>
463 476

  
464 477
Valid after L</calculate>. Returns a hasref with delivered flag by order id.
t/helper/shipped_qty.t
76 76
  ->calculate($purchase_order)
77 77
  ->write_to_objects;
78 78

  
79
is($purchase_order->orderitems->[0]->{shipped_qty}, undef, "first purchase orderitem has no shipped_qty");
80
is($purchase_order->orderitems->[0]->{delivered},   '',    "first purchase orderitem is not delivered");
79
is($purchase_order->orderitems->[0]->{shipped_qty}, 0, "first purchase orderitem has no shipped_qty");
80
is($purchase_order->orderitems->[0]->{delivered},   '', "first purchase orderitem is not delivered");
81 81

  
82 82
my $purchase_orderitem_part1 = SL::DB::Manager::OrderItem->find_by( parts_id => $part1->id, trans_id => $purchase_order->id);
83 83

  
84
is($purchase_orderitem_part1->shipped_qty, undef, "OrderItem shipped_qty method ok");
84
is($purchase_orderitem_part1->shipped_qty, 0, "OrderItem shipped_qty method ok");
85 85

  
86 86
is($purchase_order->closed,     0, 'purchase order is open');
87 87
is($purchase_order->delivered, '', 'purchase order is not delivered');
......
108 108
  ->calculate($purchase_order)
109 109
  ->write_to_objects;
110 110

  
111
is($purchase_order->orderitems->[0]->{shipped_qty}, undef, "require_stock_out => 1: first purchase orderitem has no shipped_qty");
112
is($purchase_order->orderitems->[0]->{delivered},   '',    "require_stock_out => 1: first purchase orderitem is not delivered");
111
is($purchase_order->orderitems->[0]->{shipped_qty}, 0,  "require_stock_out => 1: first purchase orderitem has no shipped_qty");
112
is($purchase_order->orderitems->[0]->{delivered},   '', "require_stock_out => 1: first purchase orderitem is not delivered");
113 113

  
114 114
# ship items from delivery order
115 115
SL::Dev::Inventory::transfer_purchase_delivery_order($purchase_delivery_order);
......
145 145
  ->calculate($sales_order)
146 146
  ->write_to_objects;
147 147

  
148
is($sales_order->orderitems->[0]->{shipped_qty}, undef, "first sales orderitem has no shipped_qty");
149
is($sales_order->orderitems->[0]->{delivered},   '',    "first sales orderitem is not delivered");
148
is($sales_order->orderitems->[0]->{shipped_qty}, 0,  "first sales orderitem has no shipped_qty");
149
is($sales_order->orderitems->[0]->{delivered},   '', "first sales orderitem is not delivered");
150 150

  
151 151
my $orderitem_part1 = SL::DB::Manager::OrderItem->find_by(parts_id => $part1->id, trans_id => $sales_order->id);
152 152
my $orderitem_part2 = SL::DB::Manager::OrderItem->find_by(parts_id => $part2->id, trans_id => $sales_order->id);
153 153

  
154
is($orderitem_part1->shipped_qty, undef, "OrderItem shipped_qty method ok");
154
is($orderitem_part1->shipped_qty, 0, "OrderItem shipped_qty method ok");
155 155

  
156 156
# create sales delivery order from sales order
157 157
my $sales_delivery_order = $sales_order->convert_to_delivery_order;
......
172 172
  ->calculate($sales_order)
173 173
  ->write_to_objects;
174 174

  
175
is($sales_order->orderitems->[0]->{shipped_qty}, undef, "require_stock_out => 1: first sales orderitem has no shipped_qty");
176
is($sales_order->orderitems->[0]->{delivered},   '',    "require_stock_out => 1: first sales orderitem is not delivered");
175
is($sales_order->orderitems->[0]->{shipped_qty}, 0,  "require_stock_out => 1: first sales orderitem has no shipped_qty");
176
is($sales_order->orderitems->[0]->{delivered},   '', "require_stock_out => 1: first sales orderitem is not delivered");
177 177

  
178 178
# ship items from delivery order
179 179
SL::Dev::Inventory::transfer_sales_delivery_order($sales_delivery_order);

Auch abrufbar als: Unified diff