From 8e116dd58aba5ba8000e896fd312f90df63ca1bf Mon Sep 17 00:00:00 2001 From: Luis Ramos Date: Wed, 1 Jul 2020 20:55:58 +0100 Subject: [PATCH] Make ensure_correct_adjustment a public method because we call it in OFN --- app/models/spree/shipment.rb | 38 ++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/app/models/spree/shipment.rb b/app/models/spree/shipment.rb index bff7421c70..d35c84ca08 100644 --- a/app/models/spree/shipment.rb +++ b/app/models/spree/shipment.rb @@ -241,6 +241,25 @@ module Spree inventory_units.create(variant_id: variant.id, state: state, order_id: order.id) end + def ensure_correct_adjustment + if adjustment + adjustment.originator = shipping_method + adjustment.label = shipping_method.adjustment_label + adjustment.amount = selected_shipping_rate.cost if adjustment.open? + adjustment.save! + adjustment.reload + elsif selected_shipping_rate_id + shipping_method.create_adjustment(shipping_method.adjustment_label, + order, + self, + true, + "open") + reload # ensure adjustment is present on later saves + end + + update_adjustment_included_tax if adjustment + end + private def manifest_unstock(item) @@ -285,25 +304,6 @@ module Spree ShipmentMailer.shipped_email(id).deliver end - def ensure_correct_adjustment - if adjustment - adjustment.originator = shipping_method - adjustment.label = shipping_method.adjustment_label - adjustment.amount = selected_shipping_rate.cost if adjustment.open? - adjustment.save! - adjustment.reload - elsif selected_shipping_rate_id - shipping_method.create_adjustment(shipping_method.adjustment_label, - order, - self, - true, - "open") - reload # ensure adjustment is present on later saves - end - - update_adjustment_included_tax if adjustment - end - def update_adjustment_included_tax if Config.shipment_inc_vat && (order.distributor.nil? || order.distributor.charges_sales_tax) adjustment.set_included_tax! Config.shipping_tax_rate