Class: Effective::OrderItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::OrderItem
- Defined in:
- app/models/effective/order_item.rb
Instance Method Summary collapse
- #amount_owing ⇒ Object
-
#assign_purchasable_attributes ⇒ Object
This method is called in a before_validation in order.assign_order_values().
- #build_purchasable(atts = {}) ⇒ Object
- #price=(value) ⇒ Object
- #purchased_download_url ⇒ Object
-
#qb_item_name ⇒ Object
first or build.
- #quantity ⇒ Object
- #subtotal ⇒ Object
- #tax ⇒ Object
- #to_s ⇒ Object
- #total ⇒ Object
Instance Method Details
#amount_owing ⇒ Object
62 63 64 |
# File 'app/models/effective/order_item.rb', line 62 def amount_owing total end |
#assign_purchasable_attributes ⇒ Object
This method is called in a before_validation in order.assign_order_values()
36 37 38 |
# File 'app/models/effective/order_item.rb', line 36 def assign_purchasable_attributes assign_attributes(name: purchasable.purchasable_name, price: purchasable.price, tax_exempt: purchasable.tax_exempt) if purchasable end |
#build_purchasable(atts = {}) ⇒ Object
40 41 42 |
# File 'app/models/effective/order_item.rb', line 40 def build_purchasable(atts = {}) (self.purchasable ||= Effective::Product.new).tap { |purchasable| purchasable.assign_attributes(atts) } end |
#price=(value) ⇒ Object
72 73 74 75 |
# File 'app/models/effective/order_item.rb', line 72 def price=(value) raise 'expected price to be an Integer representing the number of cents.' unless value.kind_of?(Integer) super end |
#purchased_download_url ⇒ Object
44 45 46 |
# File 'app/models/effective/order_item.rb', line 44 def purchased_download_url purchasable&.purchased_download_url end |
#qb_item_name ⇒ Object
first or build
78 79 80 81 |
# File 'app/models/effective/order_item.rb', line 78 def qb_item_name raise('expected Effective Quickbooks gem') unless defined?(EffectiveQbSync) || defined?(EffectiveQbOnline) (qb_order_item || build_qb_order_item(name: purchasable&.qb_item_name)).name end |
#quantity ⇒ Object
52 53 54 |
# File 'app/models/effective/order_item.rb', line 52 def quantity self[:quantity] || 1 end |
#subtotal ⇒ Object
48 49 50 |
# File 'app/models/effective/order_item.rb', line 48 def subtotal price * quantity end |
#tax ⇒ Object
56 57 58 59 60 |
# File 'app/models/effective/order_item.rb', line 56 def tax return 0 if tax_exempt? raise 'parent Effective::Order must have a tax_rate to compute order item tax' unless order.try(:tax_rate).present? (subtotal * order.tax_rate / 100.0).round(0).to_i end |
#to_s ⇒ Object
31 32 33 |
# File 'app/models/effective/order_item.rb', line 31 def to_s ((quantity || 0) > 1 ? "#{quantity}x #{name}" : name) || 'order item' end |
#total ⇒ Object
66 67 68 69 70 |
# File 'app/models/effective/order_item.rb', line 66 def total return subtotal if tax_exempt? raise 'parent Effective::Order must have a tax_rate to compute order item total' unless order.try(:tax_rate).present? subtotal + tax end |