A generic ‘bill’ for resource usage over a period of time
Includes billing information for a particular time period Should not be instantiated, instead instantiate child classes for the particular instance types. Child classes will include whatever provider-specific billing information is available
Backend identifier for this bill
Whether all bills for this period have been incorporated into this bill. Normally means the bill covers the entire billing period, but if the instance was created or destroyed during the period, it would be true iff the bill incorporates all sub-bills after creation and before destruction.
Currency of the bill
Instance covered by this bill
Billing period represented: hourly|daily|monthly. Daily and monthly bills are created by aggregating hourly bills across the billing period.
Id of the resource owning the associated instance
Start of the billing period
Id of the supplier owning the associated instance
Cost for the entire billing period. If complete is false, this value may not include all bills for the period, and may increase in future.
Id of the trader owning the associated instance
# File lib/onapp_market/bill.rb, line 55 def self.namespace Bill::TYPE end
Create a new bill, defaults to an incomplete bill with zero #total_cost
# File lib/onapp_market/bill.rb, line 45 def initialize(hash, type = nil) @currency = 'USD' @total_cost = 0 type = TYPE if type == nil super(hash, type) restrict [:bill_id, :db_id], :admin end
Sums the total cost with one or more other bills. Child classes should override this method to sum any other fields required
# File lib/onapp_market/bill.rb, line 61 def +(other) if other.kind_of? Enumerable other.inject(self) { |sum, bill| sum + bill } else @total_cost += other.total_cost self end end
Round total cost to 4 DP
# File lib/onapp_market/bill.rb, line 76 def round @total_cost = @total_cost.round(4) end
Zero the total cost
# File lib/onapp_market/bill.rb, line 71 def zero @total_cost = 0 end