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

Change calculation payment_total #3

Closed
wants to merge 42 commits into from

Conversation

kennyadsl
Copy link
Member

Internal review

In Spree::OrderUpdater the update_payment_total subs from payments the
refunds. I change this behavior and now the payment_total is composed
with only payments completed.

rel solidusio#1475

kennyadsl and others added 4 commits October 9, 2016 20:54
DEPRECATION WARNING: Passing a class as a value in an Active Record
query is deprecated and will be removed. Pass a string instead. (called
from block in <class:PromotionAction> at ...
The taxon products API which is used to manage display order falls down
under its own weight in any sort of reasonable data set. In order to
simplify that, I have added the ability to customize the return data
from this controller.

In a simple case, the results will be the same as they are right now,
however you can pass `simple: 1` to the taxon/products API request and
it will return significantly less data.

Additionally, this updates the backend taxons.js.coffee to use this
simple view for all it needs. This reduces the amount of data that needs
to be queried and returned in order to make this fast. Previously I was
seeing 20+ second response times for a small number of products in a
complicated taxon structure. This reduces that down to the 100ms range.
Add the ability to get simple results from taxon API
Copy link
Member Author

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

I'd also change the commit message to:

Fix how orders payment total is calculated 

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.

@@ -355,7 +355,7 @@ def create_tax_charge!
def outstanding_balance
# If reimbursement has happened add it back to total to prevent balance_due payment state
Copy link
Member Author

Choose a reason for hiding this comment

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

I think these two comment lines do not apply anymore since we are not adding back any refund (but we are removing it). I'd probably remove them at all since the code is self-explanatory now.

@@ -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.map { |payment| payment.amount }.sum
Copy link
Member Author

Choose a reason for hiding this comment

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

order.payment_total = payments.completed.sum(&:amount)

@@ -185,15 +213,17 @@ module Spree
context "for canceled orders" do
before { order.update_attributes(state: 'canceled') }

it "it should be a negative amount incorporating reimbursements" do
it "it should be a zero amount incorporating reimbursements" do
Copy link
Member Author

Choose a reason for hiding this comment

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

this specs is saying that it should be a zero amount but you expect -10. Probably the description is wrong?

Graeme Nathan and others added 11 commits October 14, 2016 10:18
In the bootstrap refactoring, the argument "wrapper_class" given to
rendering the `rebuild_vat_prices_checkbox` was lost, leading to
method not founds for stores with VAT. This commit changes the
reference from `wrapper_class` to `local_assigns[:wrapper_class]`
so that

  a) the partial does not error out when rendered without it and
  b) it is immediately apparent to the reader that `wrapper_class`
     is not a helper.
Fix deprecations from PromotionAction.of_type
Change new order button text on users edit page
…ass-error

Do not require 'wrapper_class' var in price checkbox partial
Copy link
Member Author

@kennyadsl kennyadsl left a comment

Choose a reason for hiding this comment

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

just two small things

it "should return negative amount when payment_total is greater than total" do
order.total = 8.20
order.payment_total = 10.20
expect(order.outstanding_balance).to be_within(0.001).of(-2.00)
end

let(:amount_payed) { 20.0 }
let(:reimbursement) { create(:reimbursement) }
Copy link
Member Author

Choose a reason for hiding this comment

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

@DanielePalombo can this be removed?

context "with reimburesements on the order" do
let(:amount) { 10.0 }
let(:amount_payed) { 20.0 }
Copy link
Member Author

Choose a reason for hiding this comment

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

paid everywhere 😄

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 solidusio#1475
@kennyadsl
Copy link
Member Author

review done, opened on solidus repo: solidusio#1536!

@kennyadsl kennyadsl closed this Oct 19, 2016
spaghetticode pushed a commit that referenced this pull request Mar 26, 2021
Implement voiding transactions
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.

5 participants