|
@@ 345-378 (lines=34) @@
|
| 342 |
|
|
| 343 |
|
|
| 344 |
|
# Call this when the cash box gets emptied |
| 345 |
|
def reconcile_safe(amount, admin): |
| 346 |
|
assert(amount>=0) |
| 347 |
|
|
| 348 |
|
e = event.EmptySafe(admin) |
| 349 |
|
DBSession.add(e) |
| 350 |
|
DBSession.flush() |
| 351 |
|
|
| 352 |
|
safe_c = account.get_cash_account("safe") |
| 353 |
|
expected_amount = safe_c.balance |
| 354 |
|
amount_missing = expected_amount - amount |
| 355 |
|
|
| 356 |
|
if amount_missing != 0.0: |
| 357 |
|
# If the amount in the safe doesn't match what we expected there to |
| 358 |
|
# be, we need to adjust the amount in the cash box be transferring |
| 359 |
|
# to or from a null account |
| 360 |
|
|
| 361 |
|
if amount_missing > 0: |
| 362 |
|
# We got less in the box than we expected |
| 363 |
|
# Move money from the safe account to null with transaction type |
| 364 |
|
# "lost" |
| 365 |
|
t1 = transaction.Lost(e, account.get_cash_account("safe"), amount_missing) |
| 366 |
|
DBSession.add(t1) |
| 367 |
|
|
| 368 |
|
else: |
| 369 |
|
# We got more in the box than expected! Use a found transaction |
| 370 |
|
# to reconcile the difference |
| 371 |
|
t1 = transaction.Found(e, account.get_cash_account("safe"), abs(amount_missing)) |
| 372 |
|
DBSession.add(t1) |
| 373 |
|
|
| 374 |
|
|
| 375 |
|
# Now move all the money from the safe to chezbetty |
| 376 |
|
t2 = transaction.EmptySafe(e, amount) |
| 377 |
|
DBSession.add(t2) |
| 378 |
|
return e |
| 379 |
|
|
| 380 |
|
|
| 381 |
|
# Call this to move all of the money from the cash box to the safe. |
|
@@ 408-440 (lines=33) @@
|
| 405 |
|
|
| 406 |
|
|
| 407 |
|
# Call this when bitcoins are converted to USD |
| 408 |
|
def reconcile_bitcoins(amount, admin, expected_amount=None): |
| 409 |
|
assert(amount>0) |
| 410 |
|
|
| 411 |
|
e = event.EmptyBitcoin(admin) |
| 412 |
|
DBSession.add(e) |
| 413 |
|
DBSession.flush() |
| 414 |
|
|
| 415 |
|
btcbox_c = account.get_cash_account("btcbox") |
| 416 |
|
if expected_amount == None: |
| 417 |
|
expected_amount = btcbox_c.balance |
| 418 |
|
amount_missing = expected_amount - amount |
| 419 |
|
|
| 420 |
|
if amount_missing != 0.0: |
| 421 |
|
# Value of bitcoins fluctated and we didn't make as much as we expected |
| 422 |
|
|
| 423 |
|
if amount_missing > 0: |
| 424 |
|
# We got less in bitcoins than we expected |
| 425 |
|
# Move money from the btcbox account to null with transaction type |
| 426 |
|
# "lost" |
| 427 |
|
t1 = transaction.Lost(e, account.get_cash_account("btcbox"), amount_missing) |
| 428 |
|
DBSession.add(t1) |
| 429 |
|
|
| 430 |
|
else: |
| 431 |
|
# We got more in bitcoins than expected! Use a found transaction |
| 432 |
|
# to reconcile the difference |
| 433 |
|
t1 = transaction.Found(e, account.get_cash_account("btcbox"), abs(amount_missing)) |
| 434 |
|
DBSession.add(t1) |
| 435 |
|
|
| 436 |
|
|
| 437 |
|
# Now move all the money from the bitcoin box to chezbetty |
| 438 |
|
t2 = transaction.EmptyBitcoin(e, amount) |
| 439 |
|
DBSession.add(t2) |
| 440 |
|
return expected_amount |
| 441 |
|
|
| 442 |
|
|
| 443 |
|
# Call this to make a miscellaneous adjustment to the chezbetty account |