| 
                                
                                    @@ 454-487 (lines=34) @@
                                 | 
                            
                                                            
                                    | 451 | 
                                     | 
                                     | 
                                
                                                            
                                    | 452 | 
                                     | 
                                     | 
                                
                                                            
                                    | 453 | 
                                     | 
                                    # Call this when the cash box gets emptied  | 
                                
                                                            
                                    | 454 | 
                                     | 
                                    def reconcile_safe(amount, admin):  | 
                                
                                                            
                                    | 455 | 
                                     | 
                                        assert(amount>=0)  | 
                                
                                                            
                                    | 456 | 
                                     | 
                                     | 
                                
                                                            
                                    | 457 | 
                                     | 
                                        e = event.EmptySafe(admin)  | 
                                
                                                            
                                    | 458 | 
                                     | 
                                        DBSession.add(e)  | 
                                
                                                            
                                    | 459 | 
                                     | 
                                        DBSession.flush()  | 
                                
                                                            
                                    | 460 | 
                                     | 
                                     | 
                                
                                                            
                                    | 461 | 
                                     | 
                                        safe_c = account.get_cash_account("safe") | 
                                
                                                            
                                    | 462 | 
                                     | 
                                        expected_amount = safe_c.balance  | 
                                
                                                            
                                    | 463 | 
                                     | 
                                        amount_missing = expected_amount - amount  | 
                                
                                                            
                                    | 464 | 
                                     | 
                                     | 
                                
                                                            
                                    | 465 | 
                                     | 
                                        if amount_missing != 0.0:  | 
                                
                                                            
                                    | 466 | 
                                     | 
                                            # If the amount in the safe doesn't match what we expected there to  | 
                                
                                                            
                                    | 467 | 
                                     | 
                                            # be, we need to adjust the amount in the cash box be transferring  | 
                                
                                                            
                                    | 468 | 
                                     | 
                                            # to or from a null account  | 
                                
                                                            
                                    | 469 | 
                                     | 
                                     | 
                                
                                                            
                                    | 470 | 
                                     | 
                                            if amount_missing > 0:  | 
                                
                                                            
                                    | 471 | 
                                     | 
                                                # We got less in the box than we expected  | 
                                
                                                            
                                    | 472 | 
                                     | 
                                                # Move money from the safe account to null with transaction type  | 
                                
                                                            
                                    | 473 | 
                                     | 
                                                # "lost"  | 
                                
                                                            
                                    | 474 | 
                                     | 
                                                t1 = transaction.Lost(e, account.get_cash_account("safe"), amount_missing) | 
                                
                                                            
                                    | 475 | 
                                     | 
                                                DBSession.add(t1)  | 
                                
                                                            
                                    | 476 | 
                                     | 
                                     | 
                                
                                                            
                                    | 477 | 
                                     | 
                                            else:  | 
                                
                                                            
                                    | 478 | 
                                     | 
                                                # We got more in the box than expected! Use a found transaction  | 
                                
                                                            
                                    | 479 | 
                                     | 
                                                # to reconcile the difference  | 
                                
                                                            
                                    | 480 | 
                                     | 
                                                t1 = transaction.Found(e, account.get_cash_account("safe"), abs(amount_missing)) | 
                                
                                                            
                                    | 481 | 
                                     | 
                                                DBSession.add(t1)  | 
                                
                                                            
                                    | 482 | 
                                     | 
                                     | 
                                
                                                            
                                    | 483 | 
                                     | 
                                     | 
                                
                                                            
                                    | 484 | 
                                     | 
                                        # Now move all the money from the safe to chezbetty  | 
                                
                                                            
                                    | 485 | 
                                     | 
                                        t2 = transaction.EmptySafe(e, amount)  | 
                                
                                                            
                                    | 486 | 
                                     | 
                                        DBSession.add(t2)  | 
                                
                                                            
                                    | 487 | 
                                     | 
                                        return e  | 
                                
                                                            
                                    | 488 | 
                                     | 
                                     | 
                                
                                                            
                                    | 489 | 
                                     | 
                                     | 
                                
                                                            
                                    | 490 | 
                                     | 
                                    # Call this to move all of the money from the cash box to the safe.  | 
                                
                                                                                
                                 | 
                                
                                    @@ 517-549 (lines=33) @@
                                 | 
                            
                                                            
                                    | 514 | 
                                     | 
                                     | 
                                
                                                            
                                    | 515 | 
                                     | 
                                     | 
                                
                                                            
                                    | 516 | 
                                     | 
                                    # Call this when bitcoins are converted to USD  | 
                                
                                                            
                                    | 517 | 
                                     | 
                                    def reconcile_bitcoins(amount, admin, expected_amount=None):  | 
                                
                                                            
                                    | 518 | 
                                     | 
                                        assert(amount>0)  | 
                                
                                                            
                                    | 519 | 
                                     | 
                                     | 
                                
                                                            
                                    | 520 | 
                                     | 
                                        e = event.EmptyBitcoin(admin)  | 
                                
                                                            
                                    | 521 | 
                                     | 
                                        DBSession.add(e)  | 
                                
                                                            
                                    | 522 | 
                                     | 
                                        DBSession.flush()  | 
                                
                                                            
                                    | 523 | 
                                     | 
                                     | 
                                
                                                            
                                    | 524 | 
                                     | 
                                        btcbox_c = account.get_cash_account("btcbox") | 
                                
                                                            
                                    | 525 | 
                                     | 
                                        if expected_amount == None:  | 
                                
                                                            
                                    | 526 | 
                                     | 
                                            expected_amount = btcbox_c.balance  | 
                                
                                                            
                                    | 527 | 
                                     | 
                                        amount_missing = expected_amount - amount  | 
                                
                                                            
                                    | 528 | 
                                     | 
                                     | 
                                
                                                            
                                    | 529 | 
                                     | 
                                        if amount_missing != 0.0:  | 
                                
                                                            
                                    | 530 | 
                                     | 
                                            # Value of bitcoins fluctated and we didn't make as much as we expected  | 
                                
                                                            
                                    | 531 | 
                                     | 
                                     | 
                                
                                                            
                                    | 532 | 
                                     | 
                                            if amount_missing > 0:  | 
                                
                                                            
                                    | 533 | 
                                     | 
                                                # We got less in bitcoins than we expected  | 
                                
                                                            
                                    | 534 | 
                                     | 
                                                # Move money from the btcbox account to null with transaction type  | 
                                
                                                            
                                    | 535 | 
                                     | 
                                                # "lost"  | 
                                
                                                            
                                    | 536 | 
                                     | 
                                                t1 = transaction.Lost(e, account.get_cash_account("btcbox"), amount_missing) | 
                                
                                                            
                                    | 537 | 
                                     | 
                                                DBSession.add(t1)  | 
                                
                                                            
                                    | 538 | 
                                     | 
                                     | 
                                
                                                            
                                    | 539 | 
                                     | 
                                            else:  | 
                                
                                                            
                                    | 540 | 
                                     | 
                                                # We got more in bitcoins than expected! Use a found transaction  | 
                                
                                                            
                                    | 541 | 
                                     | 
                                                # to reconcile the difference  | 
                                
                                                            
                                    | 542 | 
                                     | 
                                                t1 = transaction.Found(e, account.get_cash_account("btcbox"), abs(amount_missing)) | 
                                
                                                            
                                    | 543 | 
                                     | 
                                                DBSession.add(t1)  | 
                                
                                                            
                                    | 544 | 
                                     | 
                                     | 
                                
                                                            
                                    | 545 | 
                                     | 
                                     | 
                                
                                                            
                                    | 546 | 
                                     | 
                                        # Now move all the money from the bitcoin box to chezbetty  | 
                                
                                                            
                                    | 547 | 
                                     | 
                                        t2 = transaction.EmptyBitcoin(e, amount)  | 
                                
                                                            
                                    | 548 | 
                                     | 
                                        DBSession.add(t2)  | 
                                
                                                            
                                    | 549 | 
                                     | 
                                        return expected_amount  | 
                                
                                                            
                                    | 550 | 
                                     | 
                                     | 
                                
                                                            
                                    | 551 | 
                                     | 
                                     | 
                                
                                                            
                                    | 552 | 
                                     | 
                                    # Call this to make a miscellaneous adjustment to the chezbetty account  |