Update shipment updating

This commit is contained in:
Matt-Yorkley
2021-05-16 11:21:02 +01:00
parent 6b364dc420
commit 2d76c2730a
4 changed files with 11 additions and 9 deletions

View File

@@ -40,7 +40,6 @@ class LineItemsController < BaseController
order = item.order
order.with_lock do
order.contents.remove(item.variant)
order.update_shipping_fees!
order.update_payment_fees!
end
end

View File

@@ -70,7 +70,6 @@ module Spree
@order.recreate_all_fees! # Enterprise fees on line items and on the order itself
if @order.complete?
@order.update_shipping_fees!
@order.update_payment_fees!
@order.create_tax_charge!
end

View File

@@ -46,7 +46,7 @@ module Spree
def update_cart(params)
if order.update_attributes(params)
discard_empty_line_items
order.ensure_updated_shipments
update_shipment
update_order
true
else
@@ -56,10 +56,10 @@ module Spree
def update_item(line_item, params)
if line_item.update_attributes(params)
discard_empty_line_items
order.update_line_item_fees! line_item
order.update_order_fees! if order.completed?
discard_empty_line_items
order.ensure_updated_shipments
update_shipment
update_order
true
else
@@ -73,8 +73,12 @@ module Spree
order.line_items = order.line_items.select {|li| li.quantity.positive? }
end
def update_shipment(shipment)
shipment.present? ? shipment.update_amounts : order.ensure_updated_shipments
def update_shipment(target_shipment = nil)
if order.completed? || target_shipment.present?
order.update_shipping_fees!
else
order.ensure_updated_shipments
end
end
def add_to_line_item(variant, quantity, shipment = nil)

View File

@@ -347,7 +347,7 @@ describe Admin::BulkLineItemsController, type: :controller do
let(:line_item_params) { { quantity: 3 } }
let(:params) { { id: line_item1.id, order_id: order.number, line_item: line_item_params } }
xit "correctly updates order totals and states" do
it "correctly updates order totals and states" do
expect(order.total).to eq 35.0
expect(order.shipment_adjustments.shipping.sum(:amount)).to eq 6.0
expect(order.shipment_adjustments.tax.sum(:amount)).to eq 0.29
@@ -374,7 +374,7 @@ describe Admin::BulkLineItemsController, type: :controller do
describe "deleting a line item" do
let(:params) { { id: line_item1.id, order_id: order.number } }
xit "correctly updates order totals and states" do
it "correctly updates order totals and states" do
expect(order.total).to eq 35.0
expect(order.shipment_adjustments.shipping.sum(:amount)).to eq 6.0
expect(order.shipment_adjustments.tax.sum(:amount)).to eq 0.29