/**
  * Check if order item can be invoiced. Dummy item can be invoiced or with his children or
  * with parent item which is included to invoice
  *
  * @param \Magento\Sales\Api\Data\OrderItemInterface $item
  * @return bool
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  */
 protected function _canInvoiceItem(\Magento\Sales\Api\Data\OrderItemInterface $item)
 {
     $qtys = [];
     if ($item->getLockedDoInvoice()) {
         return false;
     }
     if ($item->isDummy()) {
         if ($item->getHasChildren()) {
             foreach ($item->getChildrenItems() as $child) {
                 if (empty($qtys)) {
                     if ($child->getQtyToInvoice() > 0) {
                         return true;
                     }
                 } else {
                     if (isset($qtys[$child->getId()]) && $qtys[$child->getId()] > 0) {
                         return true;
                     }
                 }
             }
             return false;
         } elseif ($item->getParentItem()) {
             $parent = $item->getParentItem();
             if (empty($qtys)) {
                 return $parent->getQtyToInvoice() > 0;
             } else {
                 return isset($qtys[$parent->getId()]) && $qtys[$parent->getId()] > 0;
             }
         }
     } else {
         return $item->getQtyToInvoice() > 0;
     }
 }