-
Notifications
You must be signed in to change notification settings - Fork 2
/
stock.rb
46 lines (32 loc) · 844 Bytes
/
stock.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
class Stock < ActiveRecord::Base
belongs_to :product
validates_numericality_of :quantity, :greater_than_or_equal_to =>:minimum_quantity, :on => :create
def product_code
product.code if product
end
def product_code=(code)
self.product= Product.find_by_code(code) unless code.blank?
end
def product_name
product.name if product
end
def product_name=(name)
self.product= Product.find_by_name(name) unless name.blank?
end
def product_size
product.size if product
end
def product_size=(size)
self.product= Product.find_by_size(size) unless size.blank?
end
def minimum_quantity
return 0
end
def as_xls(options = {})
{
"Product Name" =>product_name,
"Product Size" =>product_size,
"Quantity" => quantity.to_s
}
end
end