mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Updating order invoice template to be more legally compliant
This commit is contained in:
@@ -2,6 +2,7 @@ require 'open_food_network/spree_api_key_loader'
|
||||
|
||||
Spree::Admin::OrdersController.class_eval do
|
||||
include OpenFoodNetwork::SpreeApiKeyLoader
|
||||
helper CheckoutHelper
|
||||
before_filter :load_spree_api_key, :only => :bulk_management
|
||||
|
||||
# We need to add expections for collection actions other than :index here
|
||||
|
||||
@@ -38,6 +38,10 @@ module CheckoutHelper
|
||||
Spree::Money.new order.total_tax, currency: order.currency
|
||||
end
|
||||
|
||||
def display_checkout_total_less_tax(order)
|
||||
Spree::Money.new order.total - order.total_tax, currency: order.currency
|
||||
end
|
||||
|
||||
def checkout_state_options(source_address)
|
||||
if source_address == :billing
|
||||
address = @order.billing_address
|
||||
|
||||
@@ -25,5 +25,9 @@ module Spree
|
||||
def has_tax?
|
||||
included_tax > 0
|
||||
end
|
||||
|
||||
def display_included_tax
|
||||
Spree::Money.new(included_tax, { :currency => currency })
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -37,6 +37,10 @@ Spree::LineItem.class_eval do
|
||||
adjustments.included_tax.any?
|
||||
end
|
||||
|
||||
def included_tax
|
||||
adjustments.included_tax.sum(&:included_tax)
|
||||
end
|
||||
|
||||
def price_with_adjustments
|
||||
# EnterpriseFee#create_locked_adjustment applies adjustments on line items to their parent order,
|
||||
# so line_item.adjustments returns an empty array
|
||||
@@ -57,4 +61,8 @@ Spree::LineItem.class_eval do
|
||||
def display_amount_with_adjustments
|
||||
Spree::Money.new(amount_with_adjustments, { :currency => currency })
|
||||
end
|
||||
|
||||
def display_included_tax
|
||||
Spree::Money.new(included_tax, { :currency => currency })
|
||||
end
|
||||
end
|
||||
|
||||
57
app/views/spree/admin/orders/_invoice_table.html.haml
Normal file
57
app/views/spree/admin/orders/_invoice_table.html.haml
Normal file
@@ -0,0 +1,57 @@
|
||||
%table.order-summary{:width => "100%"}
|
||||
%thead
|
||||
%tr
|
||||
%th{:align => "left"}
|
||||
%h4 Item
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h4 Qty
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h4 GST
|
||||
%th{:align => "right", :width => "15%"}
|
||||
%h4 Price
|
||||
%tbody
|
||||
- @order.line_items.each do |item|
|
||||
%tr
|
||||
%td
|
||||
- if item.variant.product.name == item.variant.name_to_display
|
||||
%strong= "#{raw(item.variant.product.name)}"
|
||||
- else
|
||||
%strong
|
||||
%span= "#{raw(item.variant.product.name)}"
|
||||
%span= "- " + "#{raw(item.variant.name_to_display)}"
|
||||
- if item.variant.options_text
|
||||
= "(" + "#{raw(item.variant.options_text)}" + ")"
|
||||
%td{:align => "right"}
|
||||
= item.quantity
|
||||
%td{:align => "right"}
|
||||
= item.display_included_tax
|
||||
%td{:align => "right"}
|
||||
= item.display_amount_with_adjustments
|
||||
- checkout_adjustments_for(@order, exclude: [:line_item]).reject{ |a| a.amount == 0 }.reverse_each do |adjustment|
|
||||
%tr
|
||||
%td
|
||||
%strong= "#{raw(adjustment.label)}"
|
||||
%td{:align => "right"}
|
||||
1
|
||||
%td{:align => "right"}
|
||||
= adjustment.display_included_tax
|
||||
%td{:align => "right"}
|
||||
= adjustment.display_amount
|
||||
%tfoot
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong GST Total:
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= display_checkout_tax_total(@order)
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong Total (Excl. GST):
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= display_checkout_total_less_tax(@order)
|
||||
%tr
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong Total (Incl. GST):
|
||||
%td{:align => "right", :colspan => "2"}
|
||||
%strong= @order.display_total
|
||||
%p
|
||||
|
||||
@@ -3,13 +3,39 @@
|
||||
|
||||
%table{:width => "100%"}
|
||||
%tbody
|
||||
%tr
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
= "Order ##{@order.number}"
|
||||
%h4
|
||||
- if @order.total_tax > 0
|
||||
= "TAX"
|
||||
= "INVOICE: "
|
||||
= "#{@order.number}"
|
||||
%td{width: "10%" }
|
||||
|
||||
%td{ :align => "right" }
|
||||
- if @order.total_tax > 0
|
||||
= "TAX"
|
||||
= "INVOICE"
|
||||
%h4= Time.zone.now.strftime("%F")
|
||||
%tr{ valign: "top" }
|
||||
%td{ :align => "left" }
|
||||
%strong= "From: #{@order.distributor.name}"
|
||||
- if @order.distributor.abn.present?
|
||||
%br
|
||||
= "ABN: #{@order.distributor.abn}"
|
||||
%br
|
||||
= @order.distributor.address.full_address
|
||||
%br
|
||||
= @order.distributor.email
|
||||
%td{width: "10%" }
|
||||
|
||||
%td{ :align => "right" }
|
||||
%strong= "To: #{@order.ship_address.full_name}"
|
||||
- if @order.customer.code.present?
|
||||
%br
|
||||
= "Code: #{@order.customer.code}"
|
||||
%br
|
||||
= @order.ship_address.full_address
|
||||
%br
|
||||
= "#{@order.customer.email},"
|
||||
= "#{@order.bill_address.phone}"
|
||||
|
||||
= render 'spree/order_mailer/order_summary'
|
||||
= render 'spree/admin/orders/invoice_table'
|
||||
= render 'spree/order_mailer/payment'
|
||||
|
||||
@@ -64,18 +64,30 @@ module Spree
|
||||
end
|
||||
end
|
||||
|
||||
describe "checking if a line item has tax included" do
|
||||
describe "tax" do
|
||||
let(:li_no_tax) { create(:line_item) }
|
||||
let(:li_tax) { create(:line_item) }
|
||||
let(:tax_rate) { create(:tax_rate, calculator: Spree::Calculator::DefaultTax.new) }
|
||||
let!(:adjustment) { create(:adjustment, adjustable: li_tax, originator: tax_rate, label: "TR", amount: 123, included_tax: 10.00) }
|
||||
|
||||
it "returns true when it does" do
|
||||
li_tax.should have_tax
|
||||
context "checking if a line item has tax included" do
|
||||
it "returns true when it does" do
|
||||
expect(li_tax).to have_tax
|
||||
end
|
||||
|
||||
it "returns false otherwise" do
|
||||
expect(li_no_tax).to_not have_tax
|
||||
end
|
||||
end
|
||||
|
||||
it "returns false otherwise" do
|
||||
li_no_tax.should_not have_tax
|
||||
context "calculating the amount of included tax" do
|
||||
it "returns the included tax when present" do
|
||||
expect(li_tax.included_tax).to eq 10.00
|
||||
end
|
||||
|
||||
it "returns 0.00 otherwise" do
|
||||
expect(li_no_tax.included_tax).to eq 0.00
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user