mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-01 02:03:22 +00:00
Update shipment to re-calculate included tax
And re-create tax charges on the order. (untested)
This commit is contained in:
committed by
Rob Harrington
parent
479c7ba24b
commit
db4a528ba3
@@ -33,6 +33,7 @@ class LineItemsController < BaseController
|
||||
order.update_shipping_fees!
|
||||
order.update_payment_fees!
|
||||
order.update_distribution_charge!
|
||||
order.create_tax_charge!
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -145,6 +145,7 @@ Spree::Order.class_eval do
|
||||
shipments.each do |shipment|
|
||||
next if shipment.shipped?
|
||||
update_adjustment! shipment.adjustment
|
||||
shipment.save # updates included tax
|
||||
end
|
||||
update_totals
|
||||
save
|
||||
|
||||
@@ -61,7 +61,9 @@ describe LineItemsController do
|
||||
end
|
||||
|
||||
it "updates fees" do
|
||||
distributor = create(:distributor_enterprise, allow_order_changes: true)
|
||||
Spree::Config.shipment_inc_vat = true
|
||||
Spree::Config.shipping_tax_rate = 0.25
|
||||
distributor = create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true)
|
||||
shipping_fee = 3
|
||||
payment_fee = 5
|
||||
order = create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee)
|
||||
@@ -70,6 +72,7 @@ describe LineItemsController do
|
||||
item_num = order.line_items.length
|
||||
initial_fees = item_num * (shipping_fee + payment_fee)
|
||||
expect(order.adjustment_total).to eq initial_fees
|
||||
expect(order.shipment.adjustment.included_tax).to eq 1.2
|
||||
|
||||
# Delete the item
|
||||
item = order.line_items.first
|
||||
@@ -80,6 +83,8 @@ describe LineItemsController do
|
||||
|
||||
# Check the fees again
|
||||
order.reload
|
||||
order.shipment.reload
|
||||
expect(order.adjustment_total).to eq initial_fees - shipping_fee - payment_fee
|
||||
expect(order.shipment.adjustment.included_tax).to eq 0.6
|
||||
end
|
||||
end
|
||||
|
||||
@@ -652,11 +652,16 @@ describe Spree::Order do
|
||||
end
|
||||
|
||||
describe "a completed order with shipping and transaction fees" do
|
||||
let(:distributor) { create(:distributor_enterprise, allow_order_changes: true) }
|
||||
let(:distributor) { create(:distributor_enterprise, charges_sales_tax: true, allow_order_changes: true) }
|
||||
let(:order) { create(:completed_order_with_fees, distributor: distributor, shipping_fee: shipping_fee, payment_fee: payment_fee) }
|
||||
let(:shipping_fee) { 3 }
|
||||
let(:payment_fee) { 5 }
|
||||
|
||||
before do
|
||||
Spree::Config.shipment_inc_vat = true
|
||||
Spree::Config.shipping_tax_rate = 0.25
|
||||
end
|
||||
|
||||
it "updates shipping fees" do
|
||||
# Sanity check the fees
|
||||
expect(order.adjustments.length).to eq 2
|
||||
@@ -664,6 +669,7 @@ describe Spree::Order do
|
||||
expect(item_num).to eq 2
|
||||
expected_fees = item_num * (shipping_fee + payment_fee)
|
||||
expect(order.adjustment_total).to eq expected_fees
|
||||
expect(order.shipment.adjustment.included_tax).to eq 1.2
|
||||
|
||||
# Delete the item
|
||||
order.line_items.first.destroy
|
||||
@@ -673,6 +679,7 @@ describe Spree::Order do
|
||||
expect(order.adjustments.length).to eq 2
|
||||
expect(order.line_items.length).to eq item_num - 1
|
||||
expect(order.adjustment_total).to eq expected_fees - shipping_fee
|
||||
expect(order.shipment.adjustment.included_tax).to eq 0.6
|
||||
end
|
||||
|
||||
it "updates transaction fees" do
|
||||
|
||||
Reference in New Issue
Block a user