Fix balance and order paying
This commit is contained in:
parent
11097ccfb9
commit
f6a37a80cf
3 changed files with 13 additions and 3 deletions
|
@ -33,7 +33,7 @@ class Order < ActiveRecord::Base
|
|||
def price
|
||||
price = 0
|
||||
products.each do |p|
|
||||
price += p.price * p.count(self)
|
||||
price += p.read_attribute(:price) * p.count(self)
|
||||
end
|
||||
price
|
||||
end
|
||||
|
|
|
@ -39,6 +39,16 @@ class User < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def pay(amount)
|
||||
self.increment!(:balance, - amount)
|
||||
write_attribute(:balance, read_attribute(:balance) - amount)
|
||||
self.save
|
||||
end
|
||||
|
||||
def balance
|
||||
(read_attribute(:balance) || 0) / 100.0
|
||||
end
|
||||
|
||||
def balance=(value)
|
||||
if value.is_a? String then value.sub!(',', '.') end
|
||||
write_attribute(:balance, (value.to_f * 100).to_int)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
<p><strong>Name:</strong> <%= user.name %></p>
|
||||
<p><strong>Last name:</strong> <%= user.last_name %></p>
|
||||
<p><strong>Nickname:</strong> <%= user.nickname %></p>
|
||||
<p><strong>Balance:</strong> <%= user.balance %></p>
|
||||
<p><strong>Balance:</strong> <%= euro(user.balance) %></p>
|
||||
</div>
|
||||
<div class="footer">
|
||||
<p>
|
||||
|
|
Loading…
Reference in a new issue