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
- .donations_by(person) ⇒ Object
- .find_by_order(order) ⇒ Object
- .find_by_product(product) ⇒ Object
- .for(prod, per_item_lambda = lambda { |item| 0 }) ⇒ Object
- .settle(items, settlement) ⇒ Object
- .total_price_sql_sum ⇒ Object
Instance Method Summary collapse
- #assign_person(person) ⇒ Object
- #comped? ⇒ Boolean
- #dead? ⇒ Boolean
- #donation? ⇒ Boolean
- #dup! ⇒ Object
- #exchange!(return_items_to_inventory = true) ⇒ Object
- #exchangeable? ⇒ Boolean
- #exchanged? ⇒ Boolean
-
#exchangee? ⇒ Boolean
TODO: This isn’t used anymore.
- #membership? ⇒ Boolean
- #modified? ⇒ Boolean
-
#order_summary_description ⇒ Object
If the product that this item points to (a ticket, for instance) gets refunded or returned then re-sold to someone else, this item will still show up on the original purchaser’s action feed.
- #pass? ⇒ 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 the producer are all done.
-
#ticket? ⇒ Boolean
If you’re exporting ticket sales or donations, use ItemView.
- #to_comp! ⇒ Object
- #to_exchange!(item_that_this_is_being_exchanged_for) ⇒ Object
- #to_refund ⇒ Object
- #total_discount ⇒ 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
20 21 22 |
# File 'app/models/item.rb', line 20 def per_item_processing_charge @per_item_processing_charge end |
Class Method Details
.donations_by(person) ⇒ Object
51 52 53 |
# File 'app/models/item.rb', line 51 def self.donations_by(person) Item.donation.joins(:order).where('orders.person_id' => person.id) end |
.find_by_order(order) ⇒ Object
234 235 236 237 238 239 240 |
# File 'app/models/item.rb', line 234 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
98 99 100 |
# File 'app/models/item.rb', line 98 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
91 92 93 94 95 96 |
# File 'app/models/item.rb', line 91 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
242 243 244 245 246 247 248 249 250 |
# File 'app/models/item.rb', line 242 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 |
.total_price_sql_sum ⇒ Object
78 79 80 |
# File 'app/models/item.rb', line 78 def self.total_price_sql_sum "price + nongift_amount" end |
Instance Method Details
#assign_person(person) ⇒ Object
252 253 254 255 |
# File 'app/models/item.rb', line 252 def assign_person(person) product.buyer = person if ticket? product.save! end |
#comped? ⇒ Boolean
213 214 215 |
# File 'app/models/item.rb', line 213 def comped? state.eql? "comped" end |
#dead? ⇒ Boolean
194 195 196 |
# File 'app/models/item.rb', line 194 def dead? refunded? || refund? || exchanged? || return? end |
#donation? ⇒ Boolean
39 40 41 |
# File 'app/models/item.rb', line 39 def donation? product_type == "Donation" end |
#dup! ⇒ Object
113 114 115 116 117 |
# File 'app/models/item.rb', line 113 def dup! new_item = self.dup new_item.state = nil new_item end |
#exchange!(return_items_to_inventory = true) ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 |
# File 'app/models/item.rb', line 178 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.service_fee = 0 self.discount = nil save end |
#exchangeable? ⇒ Boolean
123 124 125 |
# File 'app/models/item.rb', line 123 def exchangeable? (not settlement_issued?) and (not dead?) and product and product.exchangeable? end |
#exchanged? ⇒ Boolean
225 226 227 |
# File 'app/models/item.rb', line 225 def exchanged? state.eql? "exchanged" end |
#exchangee? ⇒ Boolean
TODO: This isn’t used anymore. It needs to go
230 231 232 |
# File 'app/models/item.rb', line 230 def exchangee? state.eql? "exchangee" end |
#membership? ⇒ Boolean
43 44 45 |
# File 'app/models/item.rb', line 43 def membership? product_type == "Membership" end |
#modified? ⇒ Boolean
190 191 192 |
# File 'app/models/item.rb', line 190 def modified? not %w( purchased comped ).include?(state) end |
#order_summary_description ⇒ Object
If the product that this item points to (a ticket, for instance) gets refunded or returned then re-sold to someone else, this item will still show up on the original purchaser’s action feed
60 61 62 |
# File 'app/models/item.rb', line 60 def order_summary_description dead? ? self.state.capitalize : "#{product.order_summary_description}" end |
#pass? ⇒ Boolean
47 48 49 |
# File 'app/models/item.rb', line 47 def pass? product_type == "Pass" end |
#polarity ⇒ Object
Convenience method for use when shooting down a list if items to total things up
85 86 87 88 89 |
# File 'app/models/item.rb', line 85 def polarity return -1 if refund? return 0 if exchanged? 1 end |
#product=(product) ⇒ Object
102 103 104 105 106 107 108 109 110 111 |
# File 'app/models/item.rb', line 102 def product=(product) set_product_details_from product set_prices_from product set_discount_from product set_pass_from product 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
209 210 211 |
# File 'app/models/item.rb', line 209 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
137 138 139 140 141 142 143 144 |
# File 'app/models/item.rb', line 137 def refund! self.state = "refunded" if self.ticket? product.remove_from_cart product.reset_price! end self.save end |
#refund? ⇒ Boolean
217 218 219 |
# File 'app/models/item.rb', line 217 def refund? state.eql? "refund" end |
#refundable? ⇒ Boolean
119 120 121 |
# File 'app/models/item.rb', line 119 def refundable? (not settlement_issued?) and (not dead?) and product and product.refundable? end |
#refunded? ⇒ Boolean
221 222 223 |
# File 'app/models/item.rb', line 221 def refunded? state.eql? "refunded" end |
#return!(return_items_to_inventory = true) ⇒ Object
173 174 175 176 |
# File 'app/models/item.rb', line 173 def return!(return_items_to_inventory = true) update_attribute(:state, "returned") product.return!(return_items_to_inventory) if product.returnable? end |
#return? ⇒ Boolean
198 199 200 |
# File 'app/models/item.rb', line 198 def return? state.eql? "returned" end |
#returnable? ⇒ Boolean
127 128 129 |
# File 'app/models/item.rb', line 127 def returnable? (not dead?) and product and product.returnable? end |
#settled? ⇒ Boolean
state=“settled” means that obligations to the producer are all done
205 206 207 |
# File 'app/models/item.rb', line 205 def settled? state.eql? "settled" end |
#ticket? ⇒ Boolean
If you’re exporting ticket sales or donations, use ItemView
35 36 37 |
# File 'app/models/item.rb', line 35 def ticket? product_type == "Ticket" end |
#to_comp! ⇒ Object
166 167 168 169 170 171 |
# File 'app/models/item.rb', line 166 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 |
# 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 self.service_fee = item_that_this_is_being_exchanged_for.service_fee self.state = item_that_this_is_being_exchanged_for.state end |
#to_refund ⇒ Object
146 147 148 149 150 151 152 153 154 155 |
# File 'app/models/item.rb', line 146 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.service_fee = item.service_fee.to_i * -1 item.state = "refund" end end |
#total_discount ⇒ Object
257 258 259 |
# File 'app/models/item.rb', line 257 def total_discount original_price - price 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)
74 75 76 |
# File 'app/models/item.rb', line 74 def total_price price + (nongift_amount.nil? ? 0 : nongift_amount.to_i) end |