Skip to content
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

Fix negative credit memo #19899 #19900

Merged
merged 3 commits into from
Jan 4, 2019
Merged

Fix negative credit memo #19899 #19900

merged 3 commits into from
Jan 4, 2019

Conversation

wojtekn
Copy link
Contributor

@wojtekn wojtekn commented Dec 20, 2018

Description

This fixes negative credit memo problem described in #19899. The problem looks as introduced in \Magento\Sales\Model\Order\Creditmemo\Total\Discount which calculates base_shipping_amount based on tax related variables if base_shipping_amount is zero:

private function getBaseShippingAmount(\Magento\Sales\Model\Order\Creditmemo $creditmemo): float
{
    $baseShippingAmount = (float)$creditmemo->getBaseShippingAmount();

    if (!$baseShippingAmount) {
        $baseShippingInclTax = (float)$creditmemo->getBaseShippingInclTax();
        $baseShippingTaxAmount = (float)$creditmemo->getBaseShippingTaxAmount();
        $baseShippingAmount = $baseShippingInclTax - $baseShippingTaxAmount;
    }

    return $baseShippingAmount;
}

I fixed this by setting base_shipping_incl_tax to 0 in \Magento\Sales\Model\Order\CreditmemoFactory::initData too:

$creditmemo->setBaseShippingInclTax((double)$data['shipping_amount']);

Fixed Issues (if relevant)

  1. Credit memo for $0 order without refunded shipping produces negative credit memo #19899

Manual testing scenarios

  1. Create Cart Price Rule with 100% discount, applied to shipping, available for everyone
  2. Create simple product with positive stock and price = $100
  3. Place order in backend for the created product with qty =1 and flat rate shipping ($5 by default).
  4. Invoice order (but don't create shipment)
  5. Navigate to Credit Memo form
  6. Change Refund Shipping from 5 to 0
  7. Click "Refund Offline"

Expected behavior is to have $0 credit memo created. Instead it creates credit memo with negative, -$5.0 total.

Contribution checklist

  • Pull request has a meaningful description of its purpose
  • All commits are accompanied by meaningful commit messages
  • All new or changed code is covered with unit/integration tests (if applicable)
  • All automated tests passed successfully (all builds on Travis CI are green)

@magento-engcom-team
Copy link
Contributor

Hi @wojtekn. Thank you for your contribution
Here is some useful tips how you can test your changes using Magento test environment.
Add the comment under your pull request to deploy test or vanilla Magento instance:

  • @magento-engcom-team give me test instance - deploy test instance based on PR changes
  • @magento-engcom-team give me 2.3-develop instance - deploy vanilla Magento instance

For more details, please, review the Magento Contributor Assistant documentation

@magento-engcom-team magento-engcom-team added this to the Release: 2.3.1 milestone Dec 20, 2018
@magento-engcom-team
Copy link
Contributor

Hi @VladimirZaets, thank you for the review.
ENGCOM-3720 has been created to process this Pull Request

@ghost
Copy link

ghost commented Jan 4, 2019

Hi @wojtekn, thank you for your contribution!
Please, complete Contribution Survey, it will take less than a minute.
Your feedback will help us to improve contribution process.

@magento-engcom-team
Copy link
Contributor

Hi @wojtekn. Thank you for your contribution.
We will aim to release these changes as part of 2.3.1.
Please check the release notes for final confirmation.

1 similar comment
@magento-engcom-team
Copy link
Contributor

Hi @wojtekn. Thank you for your contribution.
We will aim to release these changes as part of 2.3.1.
Please check the release notes for final confirmation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants