From 56fe7f5e2187ef6a3ef38bd0cbc63af8df5d5499 Mon Sep 17 00:00:00 2001 From: Mohamed ABDELLANI Date: Mon, 19 Feb 2024 12:22:57 +0100 Subject: [PATCH] fix tax rates listing in invoices --- app/models/invoice/data_presenter.rb | 8 ++++++++ app/models/invoice/data_presenter/line_item.rb | 6 +----- app/views/spree/admin/orders/_invoice_table4.html.haml | 2 +- 3 files changed, 10 insertions(+), 6 deletions(-) diff --git a/app/models/invoice/data_presenter.rb b/app/models/invoice/data_presenter.rb index 8c5c4dbbab..f45e35612b 100644 --- a/app/models/invoice/data_presenter.rb +++ b/app/models/invoice/data_presenter.rb @@ -91,6 +91,14 @@ class Invoice Spree::Money.new(shipment.amount + shipment.additional_tax_total, currency:) end + def display_line_item_tax_rate(item) + all_tax_adjustments.select { |a| + a.adjustable.type == 'Spree::LineItem' && a.adjustable.id == item.id + }.map(&:originator).map { |tr| + number_to_percentage(tr.amount * 100, precision: 1) + }.join(", ") + 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 2b43a1a4d8..92ed1cc9f9 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 @@ class Invoice 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 a19f7aa20c..5382d3d8ce 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