From d194e74edaafe47b882888e50c93bb7404dd98cf Mon Sep 17 00:00:00 2001 From: Matt-Yorkley Date: Thu, 27 Nov 2014 13:38:52 +0000 Subject: [PATCH] Rohan's suggested changes --- .../admin/reports_controller_decorator.rb | 2 +- .../spree/admin/reports/sales_tax.html.haml | 2 +- lib/open_food_network/sales_tax_report.rb | 18 +++++++++--------- spec/models/spree/ability_spec.rb | 2 +- 4 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/controllers/spree/admin/reports_controller_decorator.rb b/app/controllers/spree/admin/reports_controller_decorator.rb index cb07e7245e..931e8bf9ff 100644 --- a/app/controllers/spree/admin/reports_controller_decorator.rb +++ b/app/controllers/spree/admin/reports_controller_decorator.rb @@ -76,7 +76,7 @@ Spree::Admin::ReportsController.class_eval do end def orders_and_distributors - params[:q] = {} unless params[:q] + params[:q] ||= {} if params[:q][:completed_at_gt].blank? params[:q][:completed_at_gt] = Time.zone.now.beginning_of_month diff --git a/app/views/spree/admin/reports/sales_tax.html.haml b/app/views/spree/admin/reports/sales_tax.html.haml index 805f0ae627..9231438588 100644 --- a/app/views/spree/admin/reports/sales_tax.html.haml +++ b/app/views/spree/admin/reports/sales_tax.html.haml @@ -36,5 +36,5 @@ %td= column - if @report.table.empty? %tr - %td{:colspan => "2"}= t(:none) + %td{:colspan => "12"}= t(:none) diff --git a/lib/open_food_network/sales_tax_report.rb b/lib/open_food_network/sales_tax_report.rb index 76b2534a66..cb604ce702 100644 --- a/lib/open_food_network/sales_tax_report.rb +++ b/lib/open_food_network/sales_tax_report.rb @@ -9,37 +9,37 @@ module OpenFoodNetwork def header currency_symbol = Spree::Money.currency_symbol ["Order number", "Date", "Items", "Items total (#{currency_symbol})", "Taxable Items Total (#{currency_symbol})", - "Sales Tax", "Delivery Charge (#{currency_symbol})", "Tax on Delivery (#{currency_symbol})", + "Sales Tax (#{currency_symbol})", "Delivery Charge (#{currency_symbol})", "Tax on Delivery (#{currency_symbol})", "Total Tax (#{currency_symbol})", "Customer", "Distributor"] end def table sales_tax_details = [] @orders.each do |order| - totals = {"items" => 0, "items_total" => 0.0, "taxable_total" => 0.0, "sales_tax" => 0.0} + totals = {items: 0, items_total: 0.0, taxable_total: 0.0, sales_tax: 0.0} order.line_items.each do |line_item| - totals["items"] += line_item.quantity - totals["items_total"] += line_item.price * line_item.quantity + totals[:items] += line_item.quantity + totals[:items_total] += line_item.amount tax_rate = Spree::TaxRate.find_by_tax_category_id(line_item.variant.product.tax_category_id).andand.amount if tax_rate != nil && tax_rate != 0 - totals["taxable_total"] += (line_item.price * line_item.quantity) - totals["sales_tax"] += (line_item.price * line_item.quantity) * tax_rate + totals[:taxable_total] += line_item.amount + totals[:sales_tax] += line_item.amount * tax_rate end end shipping_cost = order.adjustments.find_by_label("Shipping").andand.amount - shipping_cost = (shipping_cost == nil) ? 0.0 : shipping_cost + shipping_cost = shipping_cost.nil? ? 0.0 : shipping_cost if Spree::Config[:shipment_inc_vat] && shipping_cost != nil shipping_tax = shipping_cost * Spree::Config[:shipping_tax_rate] else shipping_tax = 0.0 end - sales_tax_details << [order.number, order.created_at, totals["items"], totals["items_total"], - totals["taxable_total"], totals["sales_tax"], shipping_cost, shipping_tax, totals["sales_tax"] + shipping_tax, + sales_tax_details << [order.number, order.created_at, totals[:items], totals[:items_total], + totals[:taxable_total], totals[:sales_tax], shipping_cost, shipping_tax, totals[:sales_tax] + shipping_tax, order.bill_address.full_name, order.distributor.andand.name] end diff --git a/spec/models/spree/ability_spec.rb b/spec/models/spree/ability_spec.rb index 30fbbd8ab6..19006cbcd1 100644 --- a/spec/models/spree/ability_spec.rb +++ b/spec/models/spree/ability_spec.rb @@ -350,7 +350,7 @@ module Spree end it "should be able to read some reports" do - should have_ability([:admin, :index, :customers, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory], for: :report) + should have_ability([:admin, :index, :customers, :sales_tax, :group_buys, :bulk_coop, :payments, :orders_and_distributors, :orders_and_fulfillment, :products_and_inventory], for: :report) end it "should not be able to read other reports" do