mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-27 01:43:22 +00:00
Specify sort order of enterprise fee totals data
This commit is contained in:
@@ -7,6 +7,23 @@ module OrderManagement
|
||||
class EnterpriseFeeTypeTotal < OpenFoodNetwork::Reports::ReportData::Base
|
||||
attr_accessor :fee_type, :enterprise_name, :fee_name, :customer_name, :fee_placement,
|
||||
:fee_calculated_on_transfer_through_name, :tax_category_name, :total_amount
|
||||
|
||||
def <=>(other)
|
||||
self.class.sortable_data(self) <=> self.class.sortable_data(other)
|
||||
end
|
||||
|
||||
def self.sortable_data(instance)
|
||||
[
|
||||
instance.fee_type,
|
||||
instance.enterprise_name,
|
||||
instance.fee_name,
|
||||
instance.customer_name,
|
||||
instance.fee_placement,
|
||||
instance.fee_calculated_on_transfer_through_name,
|
||||
instance.tax_category_name,
|
||||
instance.total_amount
|
||||
]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
require "spec_helper"
|
||||
|
||||
require "order_management/reports/enterprise_fee_summary/report_data/enterprise_fee_type_total"
|
||||
|
||||
describe OrderManagement::Reports::EnterpriseFeeSummary::ReportData::EnterpriseFeeTypeTotal do
|
||||
it "sorts instances according to their attributes" do
|
||||
instance_a = described_class.new(
|
||||
fee_type: "sales",
|
||||
enterprise_name: "Enterprise A",
|
||||
fee_name: "A Sales",
|
||||
customer_name: "Customer A",
|
||||
fee_placement: "Incoming",
|
||||
fee_calculated_on_transfer_through_name: "Transfer Enterprise B",
|
||||
tax_category_name: "Sales 4%",
|
||||
total_amount: "12.00"
|
||||
)
|
||||
|
||||
instance_b = described_class.new(
|
||||
fee_type: "sales",
|
||||
enterprise_name: "Enterprise A",
|
||||
fee_name: "B Sales",
|
||||
customer_name: "Customer A",
|
||||
fee_placement: "Incoming",
|
||||
fee_calculated_on_transfer_through_name: "Transfer Enterprise B",
|
||||
tax_category_name: "Sales 4%",
|
||||
total_amount: "12.00"
|
||||
)
|
||||
|
||||
instance_c = described_class.new(
|
||||
fee_type: "admin",
|
||||
enterprise_name: "Enterprise A",
|
||||
fee_name: "C Admin",
|
||||
customer_name: "Customer B",
|
||||
fee_placement: "Incoming",
|
||||
fee_calculated_on_transfer_through_name: nil,
|
||||
tax_category_name: "Sales 6%",
|
||||
total_amount: "12.00"
|
||||
)
|
||||
|
||||
list = [
|
||||
instance_a,
|
||||
instance_b,
|
||||
instance_c
|
||||
]
|
||||
|
||||
expect(list.sort).to eq([instance_c, instance_a, instance_b])
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user