Merge pull request #12427 from abdulazizali77/bugfix/11680-order-additional-tax

Display additional tax total in order - fixes #11680
This commit is contained in:
Filipe
2024-06-05 23:22:31 +02:00
committed by GitHub
5 changed files with 77 additions and 0 deletions

View File

@@ -11,9 +11,25 @@ module Admin
def order_adjustments_for_display(order)
order.adjustments +
voucher_included_tax_representations(order) +
additional_tax_total_representation(order) +
order.all_adjustments.payment_fee.eligible
end
def additional_tax_total_representation(order)
adjustment = Spree::Adjustment.additional.tax.where(
order_id: order.id, adjustable_type: 'Spree::Adjustment'
).sum(:amount)
return [] unless adjustment != 0
[
AdjustmentData.new(
I18n.t("admin.orders.edit.tax_on_fees"),
adjustment
)
]
end
def voucher_included_tax_representations(order)
return [] unless VoucherAdjustmentsService.new(order).voucher_included_tax.negative?

View File

@@ -1061,6 +1061,7 @@ en:
edit:
order_sure_want_to: Are you sure you want to %{event} this order?
voucher_tax_included_in_price: "%{label} (tax included in voucher)"
tax_on_fees: "Tax on fees"
invoice_email_sent: 'Invoice email has been sent'
order_email_resent: 'Order email has been resent'
bulk_management:

View File

@@ -94,6 +94,11 @@ FactoryBot.define do
transient { amount { 1 } }
calculator { build(:calculator_per_item, preferred_amount: amount) }
end
trait :flat_percent_per_item do
transient { amount { 1 } }
calculator { build(:calculator_flat_percent_per_item, preferred_flat_percent: amount) }
end
end
factory :adjustment_metadata, class: AdjustmentMetadata do

View File

@@ -14,6 +14,10 @@ FactoryBot.define do
preferred_amount { generate(:calculator_amount) }
end
factory :calculator_flat_percent_per_item, class: Calculator::FlatPercentPerItem do
preferred_flat_percent { generate(:calculator_amount) }
end
factory :weight_calculator, class: Calculator::Weight do
after(:build) { |c|
c.set_preference(:per_unit, 0.5)

View File

@@ -55,5 +55,56 @@ RSpec.describe Admin::OrdersHelper, type: :helper do
expect(fake_adjustment.amount).to eq(-0.5)
end
end
context "with additional tax total" do
let!(:shipping_method){ create(:free_shipping_method) }
let!(:enterprise){
create(:distributor_enterprise_with_tax, name: 'Enterprise', charges_sales_tax: true,
shipping_methods: [shipping_method])
}
let!(:country_zone){ create(:zone_with_member) }
let!(:tax_category){ create(:tax_category, name: 'tax_category') }
let!(:tax_rate){
create(:tax_rate, zone: country_zone, tax_category:, name: 'Tax Rate', amount: 0.13,
included_in_price: false)
}
let!(:ship_address){ create(:ship_address) }
let!(:product) {
create(:simple_product, supplier: enterprise, price: 10, tax_category_id: tax_category.id)
}
let!(:variant){
create(:variant, :with_order_cycle, product:, distributor: enterprise, order_cycle:,
tax_category:)
}
let!(:coordinator_fees){
create(:enterprise_fee, :flat_percent_per_item, enterprise:, amount: 20,
name: 'Adminstration',
fee_type: 'sales',
tax_category:)
}
let!(:order_cycle){
create(:simple_order_cycle, name: "oc1", suppliers: [enterprise],
distributors: [enterprise],
coordinator_fees: [coordinator_fees])
}
let!(:order){
create(:order_with_distributor, distributor: enterprise, order_cycle:, ship_address:)
}
let!(:line_item) { create(:line_item, variant:, quantity: 1, price: 10, order:) }
before do
order_cycle.variants << [product.variants.first]
order_cycle.exchanges.outgoing.first.variants << product.variants.first
order.recreate_all_fees!
Orders::WorkflowService.new(order).complete!
end
it "includes additional tax on fees" do
adjustment = order_adjustments_for_display(order).first
expect(adjustment.label).to eq("Tax on fees")
expect(adjustment.amount).to eq(0.26)
end
end
end
end