always render shipment on the invoice

This commit is contained in:
Mohamed ABDELLANI
2023-10-30 19:31:39 +01:00
parent c513eb5d9d
commit c8f69c8778
3 changed files with 45 additions and 2 deletions

View File

@@ -61,6 +61,12 @@ class Invoice
}
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 @@ class Invoice
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]

View File

@@ -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)}"

View File

@@ -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:"