From: Sven Schöling Date: Wed, 26 Jul 2017 09:30:05 +0000 (+0200) Subject: SL::Helper::ShippedQty: write_to garantiert eine Zahl für shipped_qty X-Git-Tag: release-3.5.4~952 X-Git-Url: http://wagnertech.de/git?a=commitdiff_plain;h=4d2ba3125019794b857b71523c8d02e591ebf631;p=kivitendo-erp.git SL::Helper::ShippedQty: write_to garantiert eine Zahl für shipped_qty --- diff --git a/SL/Helper/ShippedQty.pm b/SL/Helper/ShippedQty.pm index 80ee73d9c..63f7df883 100644 --- a/SL/Helper/ShippedQty.pm +++ b/SL/Helper/ShippedQty.pm @@ -207,7 +207,7 @@ sub write_to { 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}) { @@ -452,13 +452,26 @@ No return value. All internal errors will throw an exception. =item C -Save the C and C state to the objects. If L -was called with objects, then C will use these. +Save the C and C state to the given objects. If +L was called with objects, then C will use these. + +C and C 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 is guaranteed to be coerced to a number. If no delivery_order +was found it will be set to zero. + +C is guaranteed only to be the correct boolean value, but not +any specific value. =item C Valid after L. Returns a hasref with shipped qtys by orderitems id. +Unlike the result of C, entries in C may be C if +linked elements were found. + =item C Valid after L. Returns a hasref with delivered flag by order id. diff --git a/t/helper/shipped_qty.t b/t/helper/shipped_qty.t index 743a8a3a9..75a52362c 100644 --- a/t/helper/shipped_qty.t +++ b/t/helper/shipped_qty.t @@ -76,12 +76,12 @@ SL::Helper::ShippedQty ->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'); @@ -108,8 +108,8 @@ SL::Helper::ShippedQty ->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); @@ -145,13 +145,13 @@ SL::Helper::ShippedQty ->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; @@ -172,8 +172,8 @@ SL::Helper::ShippedQty ->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);