Skip to content

Commit

Permalink
fix tax rates listing in invoices
Browse files Browse the repository at this point in the history
  • Loading branch information
abdellani committed Feb 19, 2024
1 parent 91ecdb0 commit ec2676b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 10 additions & 0 deletions app/models/invoice/data_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
6 changes: 1 addition & 5 deletions app/models/invoice/data_presenter/line_item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
2 changes: 1 addition & 1 deletion app/views/spree/admin/orders/_invoice_table4.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit ec2676b

Please sign in to comment.