diff --git a/app/models/invoice/data_presenter.rb b/app/models/invoice/data_presenter.rb index 8c5c4dbbab9f..c683da678fec 100644 --- a/app/models/invoice/data_presenter.rb +++ b/app/models/invoice/data_presenter.rb @@ -91,6 +91,16 @@ def display_shipment_amount_with_taxes Spree::Money.new(shipment.amount + shipment.additional_tax_total, currency:) end + def display_line_item_tax_rate(item) + adjustment = all_tax_adjustments.find { |a| + a&.adjustable&.type == 'Spree::LineItem' && + a&.adjustable&.id == item.id + } + return 0 unless adjustment + + number_to_percentage(adjustment.originator.amount * 100, precision: 1) + end + def display_shipment_tax_rates all_eligible_adjustments.select { |a| a.originator.type == 'Spree::TaxRate' && a.adjustable_type == 'Spree::Shipment' diff --git a/app/models/invoice/data_presenter/line_item.rb b/app/models/invoice/data_presenter/line_item.rb index 2b43a1a4d828..92ed1cc9f9bb 100644 --- a/app/models/invoice/data_presenter/line_item.rb +++ b/app/models/invoice/data_presenter/line_item.rb @@ -3,7 +3,7 @@ class Invoice class DataPresenter class LineItem < Invoice::DataPresenter::Base - attributes :added_tax, :currency, :included_tax, :price_with_adjustments, :quantity, + attributes :id, :added_tax, :currency, :included_tax, :price_with_adjustments, :quantity, :variant_id, :unit_price_price_and_unit, :unit_presentation, :enterprise_fee_additional_tax, :enterprise_fee_included_tax attributes_with_presenter :variant @@ -35,10 +35,6 @@ def single_display_amount_with_adjustments fee_tax = enterprise_fee_included_tax || 0.0 Spree::Money.new(price_with_adjustments - ((included_tax + fee_tax) / quantity), currency:) end - - def display_line_item_tax_rates - tax_rates.map { |tr| number_to_percentage(tr.amount * 100, precision: 1) }.join(", ") - end end end end diff --git a/app/views/spree/admin/orders/_invoice_table4.html.haml b/app/views/spree/admin/orders/_invoice_table4.html.haml index a19f7aa20c09..5382d3d8ce82 100644 --- a/app/views/spree/admin/orders/_invoice_table4.html.haml +++ b/app/views/spree/admin/orders/_invoice_table4.html.haml @@ -32,7 +32,7 @@ %td{:align => "right"} = item.display_amount_with_adjustments_without_taxes %td{:align => "right"} - = item.display_line_item_tax_rates + = @order.display_line_item_tax_rate(item) %td{:align => "right"} = item.display_amount_with_adjustments_and_with_taxes %tr