diff --git a/app/models/invoice/data_presenter.rb b/app/models/invoice/data_presenter.rb index b7100560622d..0c2c930c970a 100644 --- a/app/models/invoice/data_presenter.rb +++ b/app/models/invoice/data_presenter.rb @@ -61,6 +61,12 @@ def checkout_adjustments(exclude: [], reject_zero_amount: true) } end + if exclude.include? :shipment + adjustments.reject! { |a| + a.adjustable_type == 'Spree::Shipment' + } + end + if reject_zero_amount adjustments.reject! { |a| a.amount == 0 } end @@ -68,6 +74,30 @@ def checkout_adjustments(exclude: [], reject_zero_amount: true) adjustments end + def shipment_adjustment + all_eligible_adjustments.find { |a| a.originator.type == 'Spree::ShippingMethod' } + end + + # contains limited information about the shipment + def shipment + shipment_adjustment.adjustable + end + + def display_shipment_amount_without_taxes + Spree::Money.new(shipment.amount - shipment.included_tax_total, currency:) + end + + def display_shipment_amount_with_taxes + Spree::Money.new(shipment.amount + shipment.additional_tax_total, currency:) + end + + def display_shipment_tax_rates + all_eligible_adjustments.select { |a| + a.originator.type == 'Spree::TaxRate' && a.adjustable_type == 'Spree::Shipment' + }.map(&:originator) + .map { |tr| number_to_percentage(tr.amount * 100, precision: 1) }.join(", ") + end + def display_checkout_taxes_hash tax_adjustment_totals.map do |tax_rate_id, tax_amount| tax_rate = tax_rate_by_id[tax_rate_id] diff --git a/app/views/spree/admin/orders/_invoice_table4.html.haml b/app/views/spree/admin/orders/_invoice_table4.html.haml index 96673dee4dab..0a3a234d34f3 100644 --- a/app/views/spree/admin/orders/_invoice_table4.html.haml +++ b/app/views/spree/admin/orders/_invoice_table4.html.haml @@ -35,8 +35,20 @@ = item.display_line_item_tax_rates %td{:align => "right"} = item.display_amount_with_adjustments_and_with_taxes - - - @order.checkout_adjustments(exclude: [:line_item]).reverse_each do |adjustment| + %tr + %td + %strong= "#{t(:shipping)} " + = "( #{t(:invoice_shipping_type)} #{raw(@order.shipping_method.name)} )" + %td{:align => "right"} + %td{:align => "right"} + %td{:align => "right"} + %td{:align => "right"} + = @order.display_shipment_amount_without_taxes + %td{:align => "right"} + = @order.display_shipment_tax_rates + %td{:align => "right"} + = @order.display_shipment_amount_with_taxes + - @order.checkout_adjustments(exclude: [:line_item, :shipment]).reverse_each do |adjustment| %tr %td %strong= "#{raw(adjustment.label)}" diff --git a/config/locales/en.yml b/config/locales/en.yml index 0a353292ab3c..382bc7ab2e69 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -1885,6 +1885,7 @@ en: invoice_tax_total: "GST Total:" tax_invoice: "TAX INVOICE" tax_total: "Total tax (%{rate}):" + invoice_shipping_type: "Type:" total_excl_tax: "Total (Excl. tax):" total_incl_tax: "Total (Incl. tax):" abn: "ABN:"