mollie / magento2

Mollie Payments for Magento 2
https://www.mollie.com
Other
98 stars 50 forks source link

Error 'Unable to ship order' when creating a partial shipment #739

Closed aartse closed 4 months ago

aartse commented 5 months ago

Describe the bug When i create a partial shipment, i get the following error:

Unable to ship order "1000020369" due to error: [2024-01-22T11:09:52+0000] Error executing API call (422: Unprocessable Entity): Line 0 contains invalid data. Invalid amount specified. Must be exactly €35.20, got: €35.52.. Field: lines.0.amount. Documentation: https://docs.mollie.com/reference/v2/shipments-api/create-shipment

Used versions

To Reproduce Set method for payment method

  1. Go to Stores => Configuration => Molie => Payment method
  2. Click on a payment method
  3. Set 'Method' to 'Orders API'
  4. Save

Set magento tax settings

  1. Go to Stores => Configuration => Sales => Tax
  2. Set 'Apply Discount On Prices' to 'Excluding Tax'
  3. Save

Create order and create partial shipment

  1. Create order with 2 products in frontend and use the payment method which uses 'Orders API' and complete the transaction.
  2. Login to the admin
  3. Goto the created order
  4. Click on ship
  5. Ship 1 product
  6. Got the error

Expected behavior Can create a partial shipment.

Actual behavior Error and no shipment is created in magento or mollie

Screenshots If applicable, add screenshots to help explain your problem.

Additional context Bug is caused at this line: https://github.com/mollie/magento2/blob/master/Model/OrderLines.php#L222

When the setting 'Apply Discount On Prices' is set to 'Excluding Tax', the amount in the field 'base_discount_amount' is also excluding tax. so when you do $rowTotal = $orderItem->getBaseRowTotalInclTax() - $orderItem->getBaseDiscountAmount(); the $rowTotal misses the tax on the discount and causes the error.

Frank-Magmodules commented 5 months ago

Hi there @aartse ,

Thank you for opening this issue with detailed steps. We seem to be unable to reproduce this issue. Could you please describe what kinds of taxes and/or discounts are in play here? And do you have any extensions in place that add order totals (payment fees, extra discounts, etc)? Feel free to share this here or contact us directly.

aartse commented 5 months ago

@Frank-Magmodules i can give you admin access to the staging server with this problem so you can check the tax settings?

Frank-Magmodules commented 5 months ago

Yes please @aartse , that would be great, please share directly.

patricksteenks commented 4 months ago

I have the exact same issue. After some debugging it appears that in mollie/magento2/Model/OrderLines.php on orders with a discount a discount percentage is applied to the order line. This leads to a different price for the order line than what magento is expecting.

If I remove the $orderHasDiscount check, the order is shipped fine.

The discount code that is applied is a cart-wide percentage discount.

Frank-Magmodules commented 4 months ago

Thanks, @patricksteenks ! I've just received your email providing additional context. It seems we may have identified the problem and are currently investigating both the issue and the potential solution. We aim to implement these changes in the upcoming release.

Frank-Magmodules commented 4 months ago

We have resolved this issue and provided the fix to both @aartse and @patricksteenks . It will be merged into the upcoming release. Thank you for bringing this to our attention; I will keep the issue open until the release.

Celoain commented 4 months ago

@Frank-Magmodules Could you clarify what was done in order to fix this issue in the new release? We are struggling with the same issue and would like to review the change as well.

Frank-Magmodules commented 4 months ago

Hello @Celoain , of course! I'll share it in the upcoming days once we've finalized the testing phase on our end.

Frank-Magmodules commented 4 months ago

Hello @Celoain , as requested, here is the .diff file ahead of our upcoming release of the new version.

Frank-Magmodules commented 4 months ago

Hello @Celoain and @aartse and @patricksteenks , I'm pleased to inform you that we have successfully implemented a solution for the issue you reported in our latest release. Thank you for providing the details and for your patience; it is greatly appreciated. Please feel free to share any comments or reopen the issue if necessary.