mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Make OrderUpdater use new balance implementation
In this class we properly calculated the balance taking into account the orders in cancellation state so we need to use the new implementation if we don't want to introduce a regression by using `#old_oustanding_balance`. I was initially a bit dubious because this method was checking `order.payments` as well but now I see that was redundant. Is on `payment_total` to take into account whether or not the order is paid or any other payment related details.
This commit is contained in:
@@ -157,8 +157,7 @@ module OrderManagement
|
||||
def infer_payment_state_from_balance
|
||||
# This part added so that we don't need to override
|
||||
# order.outstanding_balance
|
||||
balance = order.outstanding_balance
|
||||
balance = -1 * order.payment_total if canceled_and_paid_for?
|
||||
balance = order.new_outstanding_balance
|
||||
|
||||
infer_state(balance)
|
||||
end
|
||||
@@ -184,20 +183,10 @@ module OrderManagement
|
||||
order.state_changed('payment')
|
||||
end
|
||||
|
||||
# Taken from order.outstanding_balance in Spree 2.4
|
||||
# See: https://github.com/spree/spree/commit/7b264acff7824f5b3dc6651c106631d8f30b147a
|
||||
def canceled_and_paid_for?
|
||||
order.canceled? && paid?
|
||||
end
|
||||
|
||||
def canceled_and_not_paid_for?
|
||||
order.state == 'canceled' && order.payment_total.zero?
|
||||
end
|
||||
|
||||
def paid?
|
||||
payments.present? && !payments.completed.empty?
|
||||
end
|
||||
|
||||
def failed_payments?
|
||||
payments.present? && payments.valid.empty?
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user