Class: Effective::OrderItem
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Effective::OrderItem
- Defined in:
- app/models/effective/order_item.rb
Overview
An Order Item
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
65 66 67 |
# File 'app/models/effective/order_item.rb', line 65 def amount_owing total end |
#assign_purchasable_attributes ⇒ Object
This method is called in a before_validation in order.assign_order_values()
39 40 41 |
# File 'app/models/effective/order_item.rb', line 39 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
43 44 45 |
# File 'app/models/effective/order_item.rb', line 43 def build_purchasable(atts = {}) (self.purchasable ||= Effective::Product.new).tap { |purchasable| purchasable.assign_attributes(atts) } end |
#price=(value) ⇒ Object
75 76 77 78 |
# File 'app/models/effective/order_item.rb', line 75 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
47 48 49 |
# File 'app/models/effective/order_item.rb', line 47 def purchased_download_url purchasable&.purchased_download_url end |
#qb_item_name ⇒ Object
first or build
81 82 83 84 |
# File 'app/models/effective/order_item.rb', line 81 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
55 56 57 |
# File 'app/models/effective/order_item.rb', line 55 def quantity self[:quantity] || 1 end |
#subtotal ⇒ Object
51 52 53 |
# File 'app/models/effective/order_item.rb', line 51 def subtotal price * quantity end |
#tax ⇒ Object
59 60 61 62 63 |
# File 'app/models/effective/order_item.rb', line 59 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
34 35 36 |
# File 'app/models/effective/order_item.rb', line 34 def to_s ((quantity || 0) > 1 ? "#{quantity}x #{name}" : name) || 'order item' end |
#total ⇒ Object
69 70 71 72 73 |
# File 'app/models/effective/order_item.rb', line 69 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 |