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 how orders payment total is calculated #1536

Closed
wants to merge 1 commit into from

Conversation

DanielePalombo
Copy link
Contributor

In Spree::OrderUpdater the update_payment_total was incorrectly
removing the refunds total from each order payment. This seems
incorrect because they are separate things. Refund total has to be
taken away into the outstanding_balance calculation instead.

rel #1475

@@ -73,7 +73,7 @@ def update_shipments
end

def update_payment_total
order.payment_total = payments.completed.includes(:refunds).map { |payment| payment.amount - payment.refunds.sum(:amount) }.sum
order.payment_total = payments.completed.sum(&:amount)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm concerned that we're changing the meaning of this column. Both because existing applications may expect the amount to have the refunds subtracted, and because existing records in the database will already exist with the existing values.

@jhawthorn
Copy link
Contributor

cc @jordan-brough who has written a good summary of the state of Refunds, payment_total and outstanding balanace in #1254

stewart added a commit to stewart/solidus that referenced this pull request Oct 24, 2016
This commit addresses an issue in `Spree::Order#outstanding_balance`, in
circumstances where an Order has had refunds applied.

The existing behaviour cancels out the amount of refunded payments,
resulting in a negative outstanding balance and an order state of
'credit_due', when in fact the order balance is zero. This is caused by
the calculation of `payment_total` already factoring in refunds.

Some more discussion about this behaviour can be found in the following
issues:

solidusio#1107
solidusio#1536

With these changes, `outstanding_balance` is now defined as
`total - payment_total`. This corrects the behaviour around refunds.

Tests have been updated accordingly, with some help from
DanielePalombo's commit:

solidusio@c851404
In Spree::OrderUpdater the `update_payment_total` was incorrectly
removing  the refunds total from each order payment. This seems
incorrect because they are separate things. Refund total has to be
taken away into the outstanding_balance calculation instead.

Replace payment_total column with method that subtract refunds from
incoming_payment.

To keep backward compatibility update_payment_total call
update_incoming_payment, and put in incoming_payment the sum of
completed payments.

rel solidusio#1475
@DanielePalombo
Copy link
Contributor Author

After some insights i refactor the code to keep backward compatibility

@bbuchalter
Copy link
Contributor

@DanielePalombo this PR didn't work as expected for me. Steps I took:

  1. Pulled your branch local
  2. Wiped my sandbox
  3. Created sandbox
  4. Added an item to my cart
  5. Completed my order
  6. Went to admin and captured payment for order
  7. Refunded order.

Expected to see balance due as $0.00 with a payment state of paid. Instead:
screen shot 2016-10-28 at 3 38 40 pm

Thank you very much for your effort on this. I'll be happy to continue to QA, but I believe we now need some feature tests to automate some of this QA if wish to avoid future regressions.

@DanielePalombo
Copy link
Contributor Author

@bbuchalter,
thanks for your attemps.

but I believe we now need some feature tests to automate some of this QA if wish to avoid future regressions.

I Agree with you!

I can confirm the result after the same steps, but maybe i found a workaround. After the refund i create an adjustment ,or delete the item from cancel tab, and the balance becomes 0 and the state paid.

screenshot from 2016-10-30 22-02-11
screenshot from 2016-10-30 22-02-04

I don't know if this can resolve your issues or if we can create an adjustment after the reimbursment... i would like to deepen the discussion.

@bbuchalter
Copy link
Contributor

I'm going to defer further conversation on this topic to the core team at the moment.

@ericsaupe
Copy link
Contributor

Any updates on this?

@jhawthorn
Copy link
Contributor

Thanks Daniele. I think this is fixed #2002. If not please file a new issue or PR

@jhawthorn jhawthorn closed this Jun 22, 2017
@DanielePalombo DanielePalombo deleted the update-credits-owed branch June 22, 2017 23:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants