Class: Bodega::OrderProduct
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Bodega::OrderProduct
- Defined in:
- app/models/bodega/order_product.rb
Instance Method Summary collapse
- #identifier ⇒ Object
- #name ⇒ Object
- #quantity_and_name ⇒ Object
- #subtotal ⇒ Object
- #update_stock ⇒ Object
Instance Method Details
#identifier ⇒ Object
22 23 24 |
# File 'app/models/bodega/order_product.rb', line 22 def identifier "#{product_type}.#{product_id}" end |
#name ⇒ Object
26 27 28 |
# File 'app/models/bodega/order_product.rb', line 26 def name product.respond_to?(:name) ? product.name : "#{product_type.titleize} ##{product_id}" end |
#quantity_and_name ⇒ Object
37 38 39 |
# File 'app/models/bodega/order_product.rb', line 37 def quantity_and_name "#{quantity} x #{name.pluralize(quantity)}" end |
#subtotal ⇒ Object
41 42 43 |
# File 'app/models/bodega/order_product.rb', line 41 def subtotal price * quantity end |
#update_stock ⇒ Object
30 31 32 33 34 35 |
# File 'app/models/bodega/order_product.rb', line 30 def update_stock if keep_stock? product.number_in_stock = product.number_in_stock - quantity product.save(validate: false) end end |