From 1a1552a6eda589eab9dfaaaf63e679a424c82e90 Mon Sep 17 00:00:00 2001 From: Pau Perez Date: Wed, 17 Mar 2021 16:48:51 +0100 Subject: [PATCH] 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. --- .../app/services/order_management/order/updater.rb | 13 +------------ 1 file changed, 1 insertion(+), 12 deletions(-) diff --git a/engines/order_management/app/services/order_management/order/updater.rb b/engines/order_management/app/services/order_management/order/updater.rb index 4aac1f7843..b391592577 100644 --- a/engines/order_management/app/services/order_management/order/updater.rb +++ b/engines/order_management/app/services/order_management/order/updater.rb @@ -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