Add extra details to the order report.

This commit is contained in:
Andrew Spinks
2012-07-20 20:25:53 +10:00
parent 7172fe0c87
commit 2826f62497
3 changed files with 29 additions and 30 deletions

View File

@@ -1,4 +1,21 @@
= form_for @search, :url => spree.orders_and_distributors_admin_reports_path do |s|
= label_tag nil, t(:date_range)
%br
.date-range-filter
%div{"class" => "left sub-field"}
= s.text_field :created_at_gt, :class => 'datepicker'
%br
= label_tag nil, t(:start), :class => 'sub'
%div{"class" => "right sub-field"}
= s.text_field :created_at_lt, :class => 'datepicker'
%br
= label_tag nil, t(:stop)
= check_box_tag :csv
= label_tag :csv, "Download as csv"
%br
= button t(:search)
%br
%br
%table#listing_orders.index
%thead
%tr{'data-hook' => "orders_header"}
@@ -13,20 +30,3 @@
%tr
%td{:colspan => "2"}= t(:none)
- content_for :sidebar do
= form_for @search, :url => spree.orders_and_distributors_admin_reports_path do |s|
= label_tag nil, t(:date_range)
%br
.date-range-filter
%div{"class" => "left sub-field"}
= s.text_field :created_at_gt, :class => 'datepicker'
%br
= label_tag nil, t(:start), :class => 'sub'
%div{"class" => "right sub-field"}
= s.text_field :created_at_lt, :class => 'datepicker'
%br
= label_tag nil, t(:stop)
= check_box_tag :csv
= label_tag :csv, "Download as csv"
%br
= button t(:search)

View File

@@ -1,3 +1,4 @@
module OpenFoodWeb
class OrderAndDistributorReport
@@ -10,7 +11,7 @@ module OpenFoodWeb
"Customer Name","Customer Email", "Customer Phone", "Customer City",
"SKU", "Item name", "Variant", "Quantity", "Cost", "Shipping cost",
"Payment method",
"Distributor", "Distributor address", "Distributor city", "Distributor postcode"]
"Distributor", "Distributor address", "Distributor city", "Distributor postcode", "Shipping instructions"]
end
def table
@@ -18,10 +19,10 @@ module OpenFoodWeb
@orders.each do |order|
order.line_items.each do |line_item|
order_and_distributor_details << [order.created_at, order.id,
order.bill_address.full_name, order.user.email, order.bill_address.phone, order.bill_address.city,
line_item.product.sku, line_item.product.name, line_item.variant.name, line_item.quantity, line_item.price * line_item.quantity, line_item.itemwise_shipping_cost,
order.bill_address.full_name, order.email, order.bill_address.phone, order.bill_address.city,
line_item.product.sku, line_item.product.name, line_item.variant.options_text, line_item.quantity, line_item.price * line_item.quantity, line_item.itemwise_shipping_cost,
order.payments.first.payment_method.name,
order.distributor.name, order.distributor.pickup_address.address1, order.distributor.pickup_address.city, order.distributor.pickup_address.zipcode ]
order.distributor.name, order.distributor.pickup_address.address1, order.distributor.pickup_address.city, order.distributor.pickup_address.zipcode, order.special_instructions ]
end
end
order_and_distributor_details

View File

@@ -12,7 +12,8 @@ module OpenFoodWeb
@distributor = create(:distributor, :pickup_address => @distributor_address)
product = create(:product)
product_distribution = create(:product_distribution, :product => product, :distributor => @distributor, :shipping_method => create(:shipping_method))
@order = create(:order, :distributor => @distributor, :bill_address => @bill_address)
@shipping_instructions = "pick up on thursday please!"
@order = create(:order, :distributor => @distributor, :bill_address => @bill_address, :special_instructions => @shipping_instructions)
@payment_method = create(:payment_method)
payment = create(:payment, :payment_method => @payment_method, :order => @order )
@order.payments << payment
@@ -28,22 +29,19 @@ module OpenFoodWeb
"Customer Name","Customer Email", "Customer Phone", "Customer City",
"SKU", "Item name", "Variant", "Quantity", "Cost", "Shipping cost",
"Payment method",
"Distributor", "Distributor address", "Distributor city", "Distributor postcode"]
"Distributor", "Distributor address", "Distributor city", "Distributor postcode", "Shipping instructions"]
end
it "should denormalise order and distributor details for display as csv" do
# ap [line_item, payment]
# line_item.reload
# payment.reload
subject = OrderAndDistributorReport.new [@order]
table = subject.table
table[0].should == [@order.created_at, @order.id,
@bill_address.full_name, @order.user.email, @bill_address.phone, @bill_address.city,
@line_item.product.sku, @line_item.product.name, @line_item.variant.name, @line_item.quantity, @line_item.price * @line_item.quantity, @line_item.itemwise_shipping_cost,
@bill_address.full_name, @order.email, @bill_address.phone, @bill_address.city,
@line_item.product.sku, @line_item.product.name, @line_item.variant.options_text, @line_item.quantity, @line_item.price * @line_item.quantity, @line_item.itemwise_shipping_cost,
@payment_method.name,
@distributor.name, @distributor.pickup_address.address1, @distributor.pickup_address.city, @distributor.pickup_address.zipcode ]
@distributor.name, @distributor.pickup_address.address1, @distributor.pickup_address.city, @distributor.pickup_address.zipcode, @shipping_instructions ]
end
it "should include breakdown an order into each line item"