Class: Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Item
- Includes:
- Ext::Integrations::Item, OhNoes::Destroy
- Defined in:
- app/models/item.rb
Instance Attribute Summary collapse
-
#per_item_processing_charge ⇒ Object
This is a lambda used to by the items to calculate their net.
Class Method Summary collapse
- .find_by_order(order) ⇒ Object
- .find_by_product(product) ⇒ Object
- .for(prod, per_item_lambda = lambda { |item| 0 }) ⇒ Object
- .settle(items, settlement) ⇒ Object
Instance Method Summary collapse
- #comped? ⇒ Boolean
- #donation? ⇒ Boolean
- #dup! ⇒ Object
- #exchange!(return_items_to_inventory = true) ⇒ Object
- #exchangeable? ⇒ Boolean
- #exchanged? ⇒ Boolean
-
#exchangee? ⇒ Boolean
TODO: This isn’t used anymore.
- #modified? ⇒ Boolean
-
#polarity ⇒ Object
Convenience method for use when shooting down a list if items to total things up.
- #product=(product) ⇒ Object
- #purchased? ⇒ Boolean
-
#refund! ⇒ Object
This looks bad, but here’s what’s going on the item that gets refunded is state=“refunded” then we create a new item to signify the negative amount, state=“refund” Should all be pulled out into state machine.
- #refund? ⇒ Boolean
- #refundable? ⇒ Boolean
- #refunded? ⇒ Boolean
- #return!(return_items_to_inventory = true) ⇒ Object
- #return? ⇒ Boolean
- #returnable? ⇒ Boolean
-
#settled? ⇒ Boolean
state=“settled” means that obligations to thie producer are all done.
- #ticket? ⇒ Boolean
- #to_comp! ⇒ Object
- #to_exchange!(item_that_this_is_being_exchanged_for) ⇒ Object
- #to_refund ⇒ Object
-
#total_price ⇒ Object
Donations stored in the FA DB are stored like so: $100 sent amount = $50 nongift = $50.
Methods included from OhNoes::Destroy
Methods included from Ext::Integrations::Item
Instance Attribute Details
#per_item_processing_charge ⇒ Object
This is a lambda used to by the items to calculate their net
19 20 21 |
# File 'app/models/item.rb', line 19 def per_item_processing_charge @per_item_processing_charge end |
Class Method Details
.find_by_order(order) ⇒ Object
236 237 238 239 240 241 242 |
# File 'app/models/item.rb', line 236 def self.find_by_order(order) return [] unless order.id? self.find_by_order_id(order.id).tap do |items| items.each { |item| item.order = order } end end |
.find_by_product(product) ⇒ Object
100 101 102 |
# File 'app/models/item.rb', line 100 def self.find_by_product(product) where(:product_type => product.class.to_s).where(:product_id => product.id) end |
.for(prod, per_item_lambda = lambda { |item| 0 }) ⇒ Object
93 94 95 96 97 98 |
# File 'app/models/item.rb', line 93 def self.for(prod, per_item_lambda=lambda { |item| 0 }) Item.new.tap do |i| i.per_item_processing_charge = per_item_lambda i.product = prod end end |
.settle(items, settlement) ⇒ Object
244 245 246 247 248 249 250 251 252 |
# File 'app/models/item.rb', line 244 def self.settle(items, settlement) if items.blank? logger.debug("Item.settle: No items to settle, returning") return end logger.debug("Settling items #{items.collect(&:id).join(',')}") self.update_all({:settlement_id => settlement.id, :state => :settled }, { :id => items.collect(&:id)}) end |
Instance Method Details
#comped? ⇒ Boolean
214 215 216 |
# File 'app/models/item.rb', line 214 def comped? state.eql? "comped" end |
#donation? ⇒ Boolean
66 67 68 |
# File 'app/models/item.rb', line 66 def donation? product_type == "Donation" end |
#dup! ⇒ Object
114 115 116 117 118 |
# File 'app/models/item.rb', line 114 def dup! new_item = self.dup new_item.state = nil new_item end |
#exchange!(return_items_to_inventory = true) ⇒ Object
184 185 186 187 188 189 190 191 192 193 |
# File 'app/models/item.rb', line 184 def exchange!(return_items_to_inventory = true) product.return!(return_items_to_inventory) if product.returnable? self.state = "exchanged" self.original_price = 0 self.price = 0 self.realized_price = 0 self.net = 0 self.discount = nil save end |
#exchangeable? ⇒ Boolean
124 125 126 |
# File 'app/models/item.rb', line 124 def exchangeable? (not settlement_issued?) and product and product.exchangeable? end |
#exchanged? ⇒ Boolean
227 228 229 |
# File 'app/models/item.rb', line 227 def exchanged? state.eql? "exchanged" end |
#exchangee? ⇒ Boolean
TODO: This isn’t used anymore. It needs to go
232 233 234 |
# File 'app/models/item.rb', line 232 def exchangee? state.eql? "exchangee" end |
#modified? ⇒ Boolean
195 196 197 |
# File 'app/models/item.rb', line 195 def modified? not %w( purchased comped ).include?(state) end |
#polarity ⇒ Object
Convenience method for use when shooting down a list if items to total things up
87 88 89 90 91 |
# File 'app/models/item.rb', line 87 def polarity return -1 if refund? return 0 if exchanged? 1 end |
#product=(product) ⇒ Object
104 105 106 107 108 109 110 111 112 |
# File 'app/models/item.rb', line 104 def product=(product) set_product_details_from product set_prices_from product set_discount_from product if product.respond_to? :discount set_show_from product if product.respond_to? :show_id self.state = "purchased" self.product_id = if product then product.id end self.product_type = if product then product.class.name end end |
#purchased? ⇒ Boolean
210 211 212 |
# File 'app/models/item.rb', line 210 def purchased? state.eql? "purchased" end |
#refund! ⇒ Object
This looks bad, but here’s what’s going on the item that gets refunded is state=“refunded” then we create a new item to signify the negative amount, state=“refund” Should all be pulled out into state machine
138 139 140 141 142 143 144 145 |
# File 'app/models/item.rb', line 138 def refund! self.state = "refunded" if self.ticket? product.remove_from_cart product.reset_price! end self.save end |
#refund? ⇒ Boolean
218 219 220 |
# File 'app/models/item.rb', line 218 def refund? state.eql? "refund" end |
#refundable? ⇒ Boolean
120 121 122 |
# File 'app/models/item.rb', line 120 def refundable? (not settlement_issued?) and product and product.refundable? end |
#refunded? ⇒ Boolean
222 223 224 |
# File 'app/models/item.rb', line 222 def refunded? state.eql? "refunded" end |
#return!(return_items_to_inventory = true) ⇒ Object
179 180 181 182 |
# File 'app/models/item.rb', line 179 def return!(return_items_to_inventory = true) update_attribute(:state, "returned") product.return!(return_items_to_inventory) if product.returnable? end |
#return? ⇒ Boolean
199 200 201 |
# File 'app/models/item.rb', line 199 def return? state.eql? "returned" end |
#returnable? ⇒ Boolean
128 129 130 |
# File 'app/models/item.rb', line 128 def returnable? product and product.returnable? end |
#settled? ⇒ Boolean
state=“settled” means that obligations to thie producer are all done
206 207 208 |
# File 'app/models/item.rb', line 206 def settled? state.eql? "settled" end |
#ticket? ⇒ Boolean
62 63 64 |
# File 'app/models/item.rb', line 62 def ticket? product_type == "Ticket" end |
#to_comp! ⇒ Object
172 173 174 175 176 177 |
# File 'app/models/item.rb', line 172 def to_comp! self.price = 0 self.realized_price = 0 self.net = 0 self.state = "comped" end |
#to_exchange!(item_that_this_is_being_exchanged_for) ⇒ Object
157 158 159 160 161 162 163 164 165 166 167 168 169 170 |
# File 'app/models/item.rb', line 157 def to_exchange!(item_that_this_is_being_exchanged_for) self.original_price = item_that_this_is_being_exchanged_for.original_price self.price = item_that_this_is_being_exchanged_for.price self.realized_price = item_that_this_is_being_exchanged_for.realized_price self.net = item_that_this_is_being_exchanged_for.net if self.ticket? self.discount = item_that_this_is_being_exchanged_for.discount product.remove_from_cart product.exchange_prices_from(item_that_this_is_being_exchanged_for.product) end self.state = item_that_this_is_being_exchanged_for.state end |
#to_refund ⇒ Object
147 148 149 150 151 152 153 154 155 |
# File 'app/models/item.rb', line 147 def to_refund dup!.tap do |item| item.original_price = item.original_price.to_i * -1 item.price = item.price.to_i * -1 item.realized_price = item.realized_price.to_i * -1 item.net = item.net.to_i * -1 item.state = "refund" end end |
#total_price ⇒ Object
Donations stored in the FA DB are stored like so: $100 sent amount = $50 nongift = $50
So, unfortunately, they arrive at artfully in the same manner. That means, for donations, an item’s “price” is actually the gift amount of the donation and the “total_price” is the amount that was transacted (amount + nongift)
80 81 82 |
# File 'app/models/item.rb', line 80 def total_price price + (nongift_amount.nil? ? 0 : nongift_amount.to_i) end |