Class: Item
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Item
- Defined in:
- app/models/item.rb
Instance Method Summary collapse
-
#discount ⇒ Object
relation of price to product price down from 100 %.
- #product ⇒ Object
-
#profit ⇒ Object
profit is off course the sale price minus the cost but .
- #single_item_tax ⇒ Object
-
#tax_amount ⇒ Object
tax included in the total.
-
#total ⇒ Object
total price, ie quantity times price.
Instance Method Details
#discount ⇒ Object
relation of price to product price down from 100 %
29 30 31 32 |
# File 'app/models/item.rb', line 29 def discount return 0 unless product.price and product.price != 0 (100 - (price/product.price)*100).round(0) end |
#product ⇒ Object
12 13 14 |
# File 'app/models/item.rb', line 12 def product Product.unscoped.find self.product_id end |
#profit ⇒ Object
profit is off course the sale price minus the cost but . .. while the sale price is copied to the item and thus remains correct when the cost changes over time, so does this “profit”.
24 25 26 |
# File 'app/models/item.rb', line 24 def profit (self.price - self.product.cost) * self.quantity end |
#single_item_tax ⇒ Object
34 35 36 |
# File 'app/models/item.rb', line 34 def single_item_tax (self.price * self.tax / ( 100.0 + self.tax)).round(4) end |
#tax_amount ⇒ Object
tax included in the total
17 18 19 |
# File 'app/models/item.rb', line 17 def tax_amount self.quantity * single_item_tax end |
#total ⇒ Object
total price, ie quantity times price
8 9 10 |
# File 'app/models/item.rb', line 8 def total self.price * self.quantity end |