diff --git a/files/classes/user.py b/files/classes/user.py index 7940c607a..70c333704 100644 --- a/files/classes/user.py +++ b/files/classes/user.py @@ -172,20 +172,22 @@ class User(Base): g.db.flush() - def charge_account(self, currency, amount): + def charge_account(self, currency, amount, **kwargs): in_db = g.db.query(User).filter(User.id == self.id).with_for_update().one() succeeded = False + should_check_balance = kwargs.get('should_check_balance', True) + if currency == 'coins': account_balance = in_db.coins - if account_balance >= amount: + if not should_check_balance or account_balance >= amount: g.db.query(User).filter(User.id == self.id).update({ User.coins: User.coins - amount }) succeeded = True elif currency == 'procoins': account_balance = in_db.procoins - if account_balance >= amount: + if not should_check_balance or account_balance >= amount: g.db.query(User).filter(User.id == self.id).update({ User.procoins: User.procoins - amount }) succeeded = True diff --git a/files/routes/votes.py b/files/routes/votes.py index 32c7f6f65..0b58db8d9 100644 --- a/files/routes/votes.py +++ b/files/routes/votes.py @@ -86,7 +86,7 @@ def vote_post_comment(target_id, new, v, cls, vote_cls): existing.coins = coin_value g.db.add(existing) elif existing.vote_type != 0 and new == 0: - target.author.charge_account('coins', existing.coins) + target.author.charge_account('coins', existing.coins, should_check_balance=False) target.author.truecoins -= coin_delta g.db.add(target.author) g.db.delete(existing)