Skip to content

After invoicing an item Print Invoices returns a 'no printable documents' error. #4974

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
pynej opened this issue Jun 10, 2016 · 14 comments
Closed

Comments

@pynej
Copy link

pynej commented Jun 10, 2016

Steps to reproduce

  1. Install Magento from 2.0.7 branch.
  2. Generic store, order created with a few items, invoiced.
  3. Select the order under Sales->Orders, click Dropdown->Print Invoices

Expected result

  1. A PDF invoice

Actual result

  1. "There are no printable documents related to selected orders."

The invoice exists and if i go to Sales->Invoices I can print it there fine.

@pynej
Copy link
Author

pynej commented Jun 10, 2016

Also when choosing Print All it seams to print the invoice twice and the second one printed is messed up.

@NadiyaS NadiyaS added the CS label Jun 13, 2016
@NadiyaS NadiyaS self-assigned this Jun 13, 2016
@NadiyaS
Copy link
Contributor

NadiyaS commented Jun 15, 2016

Hi @pynej,
we can not reproduce this bug. So we need to know more details which could affect this issue.
If you use additional extensions then please disable them, clean the cache and try to reproduce this bug again.

@palamar
Copy link
Contributor

palamar commented Jul 7, 2016

According to contributor guide, tickets without response for two weeks should be closed.
Please feel free to reopen if it's needed.

@palamar palamar closed this as completed Jul 7, 2016
@maderlock
Copy link

This is still a problem in 2.1. Please re-open, and I will test with extension disabled.

@maderlock
Copy link

I've now reproduced this using the same steps as the original poster on a clean installation of 2.1.0 with just the fix to add the base_grand_total column to the sales_invoice_grid.

The mass-action in the order view -> invoice grid works. Print from the invoice view page works. It's the mass action in the order grid that is not working.

@olysenko
Copy link

Hi @maderlock,
we can not reproduce this bug on a clean installation of 2.1.0. Can you try this action in incognito/anonymous browser mode?

@maderlock
Copy link

maderlock commented Jul 14, 2016

Reproduced on a clear installation of 2.1 in incogneto running on PHP 7.0.7. I would have been surprised if that had made a difference as the error is displayed in the notifications area so it should not be relevant given that packing slips etc. can be printed this way.

@maderlock
Copy link

To confirm, I can go to the invoice and print it directly. The problem is not related to the actual generation of the pdf - just the mass action.

@maderlock
Copy link

Is there still an update needed? Clear steps to reproduce...

@dmitrisol
Copy link

dmitrisol commented Oct 25, 2016

This is happening because of incorrect collection being passed to PdfInvoices massAction.

The consequence is that the invoice collection is filtered (incorrectly) by orderId.

To reproduce the issue, you shall invoice some of the orders, leave some orders not invoiced, then invoice some others in a random order.

The issue is not reproducible if orders are invoices in the same order as they're placed.

Another consequence would be wrong (unrelated to selected orders in Sales Orders grid) invoices being printed.

As soon as order entity_ids diverge from invoice entity_ids, you will experience these issues when trying to print invoices on orders that have been invoices but there's no invoice with the same entity_id as the order's entity_id.

Magento\Ui\Component\MassAction\Filter::getCollection() returns ids from query "SELECT main_table.* FROM sales_invoice AS main_table" applied as a filter to sales_invoice collection, something like the following (not sure for what purpose and then an AND filter is added again by entity_id..., however...):

SELECTmain_table.* FROMsales_invoiceASmain_tableWHERE (entity_idIN('2', '3', '4', '5', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '29', '31', '33', '34', '35', '38', '39', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '90', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '111', '112', '113', '114', '115', '116', '117', '118', '119', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160', '161', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199', '200', '201', '202', '203', '204', '205', '206', '207', '208', '209', '210', '211', '212', '213', '214', '215', '216', '217', '218', '219', '220', '221', '222', '223', '224', '225', '226', '227', '229', '230', '231', '232', '233', '234', '235', '236', '237', '238', '239', '240', '241', '242', '243', '244', '245', '246', '247', '248', '249', '250', '251', '252', '253', '254', '255', '256', '257', '258', '259', '260', '261', '262', '263', '264'))

The applies selection (order_ids!!!) to the resulting collection, where mentioned order_id was selected in order admin grid (Magento\Ui\Component\MassAction\Filter::applySelection() method), which results in something like:

SELECTmain_table.* FROMsales_invoiceASmain_tableWHERE (entity_idIN('2', '3', '4', '5', '7', '8', '9', '10', '11', '12', '13', '14', '15', '16', '18', '19', '20', '21', '22', '23', '24', '25', '26', '27', '29', '31', '33', '34', '35', '38', '39', '43', '44', '45', '46', '47', '48', '49', '50', '51', '52', '53', '54', '55', '56', '57', '58', '59', '60', '61', '62', '63', '64', '65', '66', '67', '68', '69', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '80', '81', '82', '83', '84', '85', '86', '87', '88', '90', '95', '96', '97', '98', '99', '100', '101', '102', '103', '104', '105', '106', '107', '108', '111', '112', '113', '114', '115', '116', '117', '118', '119', '121', '122', '123', '124', '125', '126', '127', '128', '129', '130', '131', '132', '133', '134', '135', '136', '137', '138', '139', '140', '141', '142', '143', '144', '145', '146', '147', '148', '149', '150', '151', '152', '153', '154', '155', '156', '157', '158', '159', '160', '161', '163', '164', '165', '166', '167', '168', '169', '170', '171', '172', '173', '174', '175', '176', '177', '178', '179', '180', '181', '182', '183', '184', '185', '186', '187', '188', '189', '190', '191', '192', '193', '194', '195', '196', '197', '198', '199', '200', '201', '202', '203', '204', '205', '206', '207', '208', '209', '210', '211', '212', '213', '214', '215', '216', '217', '218', '219', '220', '221', '222', '223', '224', '225', '226', '227', '229', '230', '231', '232', '233', '234', '235', '236', '237', '238', '239', '240', '241', '242', '243', '244', '245', '246', '247', '248', '249', '250', '251', '252', '253', '254', '255', '256', '257', '258', '259', '260', '261', '262', '263', '264')) AND (entity_idIN('264'))

(note the last part is an order id from massaction filter, not an invoice id!!!)

Next step, in Magento\Sales\Controller\Adminhtml\Order::massAction(), $collection->getAllIds() returns NULL (of course) and the invoice query clearly results in something like:

SELECTmain_table.* FROMsales_invoiceASmain_tableWHERE (order_idIN(NULL))

Which obviously is returning count of 0, hence the error message...

@dunarri
Copy link

dunarri commented Oct 27, 2016

I am experiencing this problem as well after migrating data to 2.1.1

@SilvanLaroo
Copy link

SilvanLaroo commented Oct 31, 2016

I also have this problem on 2.0.7. Individual printing of an invoice works well, but the mass action gives the error 'There are no printable documents related to selected orders.'.

@olysenko
Copy link

Hi, this issue was fixed in develop branch (see commit). Also fix will be delivered in 2.1 with 2.1.3 release in the end of November

@dmitrisol
Copy link

dmitrisol commented Oct 31, 2016

Magento2 filters in Admin grid are all affected by this bug, had to bypass the filter applied to collection in my custom MassAction, implementing my own version of the filter's applySelection($collection) method. See example:

class MassExport extends AbstractMassAction
{
    // this is protected in Filter, cannot invoke directly, so created my own in my MassAction ...
    protected function applySelection(AbstractDb $collection)
    {
        $selected = $this->_request->getParam('selected');
        $excluded = $this->_request->getParam('excluded');

        if ('false' === $excluded) {
            return $collection;
        }

        try {
            if (is_array($excluded) && !empty($excluded)) {
                $collection->addFieldToFilter($collection->getIdFieldName(), ['nin' => $excluded]);
            } elseif (is_array($selected) && !empty($selected)) {
                $collection->addFieldToFilter($collection->getIdFieldName(), ['in' => $selected]);
            } else {
                throw new LocalizedException(__('Please select item(s).'));
            }
        } catch (\Exception $e) {
            throw new LocalizedException(__($e->getMessage()));
        }
        return $collection;
    }

    public function execute()
    {
        try {
            // have to replace this as filters in admin grid are buggy!!!
            // see 
            $collection = $this->applySelection($this->collectionFactory->create());
            return $this->massAction($collection);
        } catch (\Exception $e) {
            $this->messageManager->addError($e->getMessage());
            /** @var \Magento\Backend\Model\View\Result\Redirect $resultRedirect */
            $resultRedirect = $this->resultFactory->create(ResultFactory::TYPE_REDIRECT);
            return $resultRedirect->setPath($this->redirectUrl);
        }
    }

    protected function massAction(AbstractCollection $collection)
    {
        $orders = [];
        foreach ($collection->getItems() as $order) {
            $orders[] = $order;
        }
        // ... my operations on orders checked in admin grid ...
    }
    // ...
}

magento-engcom-team pushed a commit that referenced this issue Nov 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

9 participants