mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Rohan's suggested changes
This commit is contained in:
committed by
Rohan Mitchell
parent
3f61a5412c
commit
d194e74eda
@@ -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
|
||||
|
||||
@@ -36,5 +36,5 @@
|
||||
%td= column
|
||||
- if @report.table.empty?
|
||||
%tr
|
||||
%td{:colspan => "2"}= t(:none)
|
||||
%td{:colspan => "12"}= t(:none)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user