Class: Ig3tool::Product
Instance Method Summary
collapse
#attributes_protected_by_default, hash_lookup, set_nonauto_primary_key
Instance Method Details
#decrement_stock(amount) ⇒ Object
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
# File 'lib/sales.rb', line 82
def decrement_stock(amount)
transaction do
if stock >= amount
update_attribute("stock", stock - amount)
save
else
update_attribute("stock", 0)
end
purchases = Purchase.find_all_by_product(barcode,
:conditions => [ "current > 0"],
:order => "time")
while amount > 0
if purchases.empty?
warn "stock corrupt: #{amount} items of #{barcode} - #{name} missing"
break
else
p = purchases.shift
amt = p.current - amount
if amt < 0
amount = amt.abs
amt = 0
else
amount = 0
end
p.current = amt
p.save
end
end
reload
end
end
|
#increase_stock(amount) ⇒ Object
120
121
122
|
# File 'lib/sales.rb', line 120
def increase_stock(amount)
end
|
#price(status, count = 1) ⇒ Object
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/sales.rb', line 66
def price(status, count = 1)
count *
case status
when "member"
mprice
when "debugger"
dprice
when "plebs", "non-member", "non member"
nmprice
else
warn "Invalid status: '#{status}'"
nmprice
end
end
|