for my $obj (@$objects) {
if ('SL::DB::OrderItem' eq ref $obj) {
- $obj->{shipped_qty} = $shipped_qty->{$obj->id};
+ $obj->{shipped_qty} = $shipped_qty->{$obj->id} //= 0;
$obj->{delivered} = $shipped_qty->{$obj->id} == $obj->qty;
} elsif ('SL::DB::Order' eq ref $obj) {
if (exists $obj->{orderitems}) {
=item C<write_to_objects>
-Save the C<shipped_qty> and C<delivered> state to the objects. If L</calculate>
-was called with objects, then C<write_to_objects> will use these.
+Save the C<shipped_qty> and C<delivered> state to the given objects. If
+L</calculate> was called with objects, then C<write_to_objects> will use these.
+
+C<shipped_qty> and C<delivered> will be directly infused into the objects
+without calling the accessor for delivered. If you want to save afterwards,
+you'll have to do that yourself.
+
+C<shipped_qty> is guaranteed to be coerced to a number. If no delivery_order
+was found it will be set to zero.
+
+C<delivered> is guaranteed only to be the correct boolean value, but not
+any specific value.
=item C<shipped_qty>
Valid after L</calculate>. Returns a hasref with shipped qtys by orderitems id.
+Unlike the result of C</write_to>, entries in C<shipped_qty> may be C<undef> if
+linked elements were found.
+
=item C<delivered>
Valid after L</calculate>. Returns a hasref with delivered flag by order id.
->calculate($purchase_order)
->write_to_objects;
-is($purchase_order->orderitems->[0]->{shipped_qty}, undef, "first purchase orderitem has no shipped_qty");
-is($purchase_order->orderitems->[0]->{delivered}, '', "first purchase orderitem is not delivered");
+is($purchase_order->orderitems->[0]->{shipped_qty}, 0, "first purchase orderitem has no shipped_qty");
+is($purchase_order->orderitems->[0]->{delivered}, '', "first purchase orderitem is not delivered");
my $purchase_orderitem_part1 = SL::DB::Manager::OrderItem->find_by( parts_id => $part1->id, trans_id => $purchase_order->id);
-is($purchase_orderitem_part1->shipped_qty, undef, "OrderItem shipped_qty method ok");
+is($purchase_orderitem_part1->shipped_qty, 0, "OrderItem shipped_qty method ok");
is($purchase_order->closed, 0, 'purchase order is open');
is($purchase_order->delivered, '', 'purchase order is not delivered');
->calculate($purchase_order)
->write_to_objects;
-is($purchase_order->orderitems->[0]->{shipped_qty}, undef, "require_stock_out => 1: first purchase orderitem has no shipped_qty");
-is($purchase_order->orderitems->[0]->{delivered}, '', "require_stock_out => 1: first purchase orderitem is not delivered");
+is($purchase_order->orderitems->[0]->{shipped_qty}, 0, "require_stock_out => 1: first purchase orderitem has no shipped_qty");
+is($purchase_order->orderitems->[0]->{delivered}, '', "require_stock_out => 1: first purchase orderitem is not delivered");
# ship items from delivery order
SL::Dev::Inventory::transfer_purchase_delivery_order($purchase_delivery_order);
->calculate($sales_order)
->write_to_objects;
-is($sales_order->orderitems->[0]->{shipped_qty}, undef, "first sales orderitem has no shipped_qty");
-is($sales_order->orderitems->[0]->{delivered}, '', "first sales orderitem is not delivered");
+is($sales_order->orderitems->[0]->{shipped_qty}, 0, "first sales orderitem has no shipped_qty");
+is($sales_order->orderitems->[0]->{delivered}, '', "first sales orderitem is not delivered");
my $orderitem_part1 = SL::DB::Manager::OrderItem->find_by(parts_id => $part1->id, trans_id => $sales_order->id);
my $orderitem_part2 = SL::DB::Manager::OrderItem->find_by(parts_id => $part2->id, trans_id => $sales_order->id);
-is($orderitem_part1->shipped_qty, undef, "OrderItem shipped_qty method ok");
+is($orderitem_part1->shipped_qty, 0, "OrderItem shipped_qty method ok");
# create sales delivery order from sales order
my $sales_delivery_order = $sales_order->convert_to_delivery_order;
->calculate($sales_order)
->write_to_objects;
-is($sales_order->orderitems->[0]->{shipped_qty}, undef, "require_stock_out => 1: first sales orderitem has no shipped_qty");
-is($sales_order->orderitems->[0]->{delivered}, '', "require_stock_out => 1: first sales orderitem is not delivered");
+is($sales_order->orderitems->[0]->{shipped_qty}, 0, "require_stock_out => 1: first sales orderitem has no shipped_qty");
+is($sales_order->orderitems->[0]->{delivered}, '', "require_stock_out => 1: first sales orderitem is not delivered");
# ship items from delivery order
SL::Dev::Inventory::transfer_sales_delivery_order($sales_delivery_order);