inventory icon indicating copy to clipboard operation
inventory copied to clipboard

Cannot create a credit memo when product entity is deleted

Open convenient opened this issue 2 years ago • 2 comments

Preconditions (*)

  1. Spotted on 2.4.4-p2 enterprise

Steps to reproduce (*)

  1. cataloginventory/options/synchronize_with_catalog=0 (default this is the default value)
  2. Create a sku with an inventory source
  3. Purchase the product
  4. invoice the order
  5. Delete the sku via the rest api
    1. See that the product is missing in catalog_product_entity
    2. See that the product still exists inside inventory_source_item
      1. select * from inventory_source_item where sku not in (select sku from catalog_product_entity) and sku in (select sku from sales_order_item)
  6. In the admin panel go sales -> order, view your order, pick the invoice, click "credit memo" and see an error page and the following stack trace
[2023-03-03T14:15:41.489918+00:00] report.CRITICAL: TypeError: Magento\InventoryConfiguration\Model\IsSourceItemManagementAllowedForProductType\Interceptor::execute(): Argument #1 ($productType) must be of type string, null given, called in vendor/magento/module-inventory-sales/Model/GetProductSalableQty.php on line 108 and defined in generated/code/Magento/InventoryConfiguration/Model/IsSourceItemManagementAllowedForProductType/Interceptor.php:20
Stack trace:
#0 vendor/magento/module-inventory-sales/Model/GetProductSalableQty.php(108): Magento\InventoryConfiguration\Model\IsSourceItemManagementAllowedForProductType\Interceptor->execute()
#1 vendor/magento/module-inventory-sales/Model/GetProductSalableQty.php(75): Magento\InventorySales\Model\GetProductSalableQty->validateProductType()
#2 vendor/magento/module-inventory-sales-admin-ui/Model/GetSalableQuantityDataBySku.php(84): Magento\InventorySales\Model\GetProductSalableQty->execute()
#3 vendor/magento/module-inventory-sales-admin-ui/Model/GetIsManageStockForProduct.php(95): Magento\InventorySalesAdminUi\Model\GetSalableQuantityDataBySku->execute()
#4 vendor/magento/module-inventory-sales-admin-ui/Model/GetIsManageStockForProduct.php(66): Magento\InventorySalesAdminUi\Model\GetIsManageStockForProduct->getProductStockIds()
#5 vendor/magento/module-inventory-sales-admin-ui/Plugin/Sales/Block/Items/Renderer/DefaultRenderer/ChildManageStockIsOn.php(59): Magento\InventorySalesAdminUi\Model\GetIsManageStockForProduct->execute()

Because we have an inventory_source_item but no product, we are doing a stock check and getting a PHP fatal error.

Expected result (*)

  1. I can create a credit memo

Actual result (*)

  1. I can not create a credit memo

convenient avatar Mar 03 '23 15:03 convenient

Hi @convenient. Thank you for your report. To speed up processing of this issue, make sure that you provided sufficient information. Add a comment to assign the issue: @magento I am working on this


Join Magento Community Engineering Slack and ask your questions in #github channel.

m2-assistant[bot] avatar Mar 03 '23 15:03 m2-assistant[bot]

Adding to this that this error is also thrown if the SKU of a product is changed, you don't even need to delete the product.

This suggests that the functionality should use the product ID which can't be changed (but could be deleted) rather than the SKU which can be changed or deleted.

Our workaround for this is that we have to update the SKU on the order to the new SKU for the SKU that is no longer in use and then process the credit memo. Not ideal.

davidgreenwooduktf avatar Jun 20 '23 08:06 davidgreenwooduktf