|
@@ -184,7 +184,8 @@ def send_ownable(from_user_id, to_user_id, ownable_id, amount):
|
|
|
if amount < 0:
|
|
|
raise AssertionError('Can not send negative amount')
|
|
|
|
|
|
- if from_user_id != bank_id():
|
|
|
+ bank_id_ = bank_id()
|
|
|
+ if from_user_id != bank_id_:
|
|
|
execute('''
|
|
|
UPDATE ownership
|
|
|
SET amount = amount - ?
|
|
@@ -194,12 +195,13 @@ def send_ownable(from_user_id, to_user_id, ownable_id, amount):
|
|
|
|
|
|
own(to_user_id, ownable_name_by_id(ownable_id))
|
|
|
|
|
|
- execute('''
|
|
|
- UPDATE ownership
|
|
|
- SET amount = amount + ?
|
|
|
- WHERE user_id = ?
|
|
|
- AND ownable_id = ?
|
|
|
- ''', (amount, to_user_id, ownable_id,))
|
|
|
+ if from_user_id != bank_id_ or ownable_id != currency_id():
|
|
|
+ execute('''
|
|
|
+ UPDATE ownership
|
|
|
+ SET amount = amount + ?
|
|
|
+ WHERE user_id = ?
|
|
|
+ AND ownable_id = ?
|
|
|
+ ''', (amount, to_user_id, ownable_id,))
|
|
|
return True
|
|
|
|
|
|
|
|
@@ -988,6 +990,7 @@ def user_wealth(user_id):
|
|
|
connect()
|
|
|
|
|
|
execute('''
|
|
|
+ SELECT (
|
|
|
SELECT COALESCE(SUM(
|
|
|
CASE -- sum score for each of the users ownables
|
|
|
WHEN ownership.ownable_id = ? THEN ownership.amount
|
|
@@ -997,9 +1000,15 @@ def user_wealth(user_id):
|
|
|
ORDER BY rowid DESC -- equivalent to ordering by dt
|
|
|
LIMIT 1)
|
|
|
END
|
|
|
- ), 0) score
|
|
|
+ ), 0)
|
|
|
FROM ownership
|
|
|
- WHERE ownership.user_id = ?
|
|
|
+ WHERE ownership.user_id = ?)
|
|
|
+ -
|
|
|
+ ( SELECT COALESCE(SUM(
|
|
|
+ amount
|
|
|
+ ), 0)
|
|
|
+ FROM loans
|
|
|
+ WHERE loans.user_id = ?)
|
|
|
''', (currency_id(), user_id,))
|
|
|
|
|
|
return current_cursor.fetchone()[0]
|
|
@@ -1345,6 +1354,11 @@ def repay_loan(loan_id, amount, known_user_id=None):
|
|
|
SET amount = amount - ?
|
|
|
WHERE rowid = ?
|
|
|
''', (amount, loan_id,))
|
|
|
+ if loan_remaining_amount(loan_id) == 0:
|
|
|
+ execute('''
|
|
|
+ DELETE FROM loans
|
|
|
+ WHERE rowid = ?
|
|
|
+ ''', (loan_id, ))
|
|
|
|
|
|
|
|
|
def take_out_personal_loan(user_id, amount):
|