]> wagnertech.de Git - mfinanz.git/blobdiff - SL/Helper/ShippedQty.pm
SL::Helper::ShippedQty: write_to garantiert eine Zahl für shipped_qty
[mfinanz.git] / SL / Helper / ShippedQty.pm
index cf1c70bfee9939b3fca9ff261d0729822eddc684..63f7df88385db867bdf0c2f84018dd24264fd814 100644 (file)
@@ -61,7 +61,7 @@ my $stock_item_links_query = <<'';
   ORDER BY oi.trans_id, oi.position
 
 my $stock_fill_up_doi_query = <<'';
-  SELECT doi.id, doi.delivery_order_id, doi.position, doi.parts_id, doi.description, doi.reqdate, doi.serialnumber, i.qty, i.unit
+  SELECT doi.id, doi.delivery_order_id, doi.position, doi.parts_id, doi.description, doi.reqdate, doi.serialnumber, i.qty, p.unit
   FROM delivery_order_items doi
   INNER JOIN parts p                         ON p.id = doi.parts_id
   INNER JOIN delivery_order_items_stock dois ON dois.delivery_order_item_id = doi.id
@@ -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<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.