def test_save_deposit_ready_then_amount_account(self): """ Does ready deposit and then change amount and account """ test_account1 = Account.objects.create(name='Test Account1', currency=CURRENCY_CUC) test_balance1 = test_account1.balance test_date = timezone.now() test_amount1 = 100 test_status = STATUS_READY deposit = Deposit(date=test_date, account=test_account1, amount=test_amount1, status=test_status) deposit = FinanceService.save_deposit(user=self.test_user, deposit=deposit) # account balance incremented self.assertAccount(test_account=test_account1, test_balance=test_balance1 + test_amount1) # document data auto filled self.assertDocument(deposit, DOC_TYPE_DEPOSIT, test_account1.currency) # one finantial history created finantials = deposit.finantialdocumenthistory_set self.assertEqual(finantials.count(), 1) # finantial history info finantial = finantials.first() self.assertFinantialHistory(test_finantial_history=finantial, test_document=deposit, test_user=self.test_user, test_old_status=None, test_new_status=test_status) # one accounting history created accountings = deposit.accountingdocumenthistory_set self.assertEqual(accountings.count(), 1) # accounting history info accounting = accountings.first() operation = Operation.objects.get(pk=accounting.operation_id) # one movement created movements = operation.operationmovement_set self.assertEqual(movements.count(), 1) # movement info movement = movements.first() self.assertMovement(test_movement=movement, test_account=test_account1, test_movement_type=MOVEMENT_TYPE_INPUT, test_amount=test_amount1) test_account2 = Account.objects.create(name='Test Account2', currency=CURRENCY_USD) test_balance2 = test_account2.balance test_amount2 = 50 deposit.account = test_account2 deposit.amount = test_amount2 deposit = FinanceService.save_deposit(user=self.test_user, deposit=deposit) # account balance updated self.assertAccount(test_account=test_account1, test_balance=test_balance1) self.assertAccount(test_account=test_account2, test_balance=test_balance2 + test_amount2) # document data auto filled self.assertDocument(deposit, DOC_TYPE_DEPOSIT, test_account2.currency) # no aditional finantial history finantials = deposit.finantialdocumenthistory_set self.assertEqual(finantials.count(), 1) # two accounting history created accountings = deposit.accountingdocumenthistory_set self.assertEqual(accountings.count(), 3) elements = accountings.all() # accounting history info accounting = elements[1] operation = Operation.objects.get(pk=accounting.operation_id) # one movement created movements = operation.operationmovement_set self.assertEqual(movements.count(), 1) # movement info movement = movements.first() self.assertMovement(test_movement=movement, test_account=test_account2, test_movement_type=MOVEMENT_TYPE_INPUT, test_amount=test_amount2) # accounting history info accounting = elements[2] operation = Operation.objects.get(pk=accounting.operation_id) # one movement created movements = operation.operationmovement_set self.assertEqual(movements.count(), 1) # movement info movement = movements.first() self.assertMovement(test_movement=movement, test_account=test_account1, test_movement_type=MOVEMENT_TYPE_OUTPUT, test_amount=test_amount1)
def test_save_deposit_draft_then_account(self): """ Does draft deposit and then change account """ test_account1 = Account.objects.create(name='Test Account1', currency=CURRENCY_CUC) test_balance1 = test_account1.balance test_date = timezone.now() test_amount = 100 test_status = STATUS_DRAFT deposit = Deposit(date=test_date, account=test_account1, amount=test_amount, status=test_status) deposit = FinanceService.save_deposit(user=self.test_user, deposit=deposit) # account balance unchanged self.assertAccount(test_account=test_account1, test_balance=test_balance1) # document data auto filled self.assertDocument(deposit, DOC_TYPE_DEPOSIT, test_account1.currency) # one finantial history created finantials = deposit.finantialdocumenthistory_set self.assertEqual(finantials.count(), 1) # finantial history info finantial = finantials.first() self.assertFinantialHistory(test_finantial_history=finantial, test_document=deposit, test_user=self.test_user, test_old_status=None, test_new_status=test_status) # no accounting history created accountings = deposit.accountingdocumenthistory_set self.assertEqual(accountings.count(), 0) test_account2 = Account.objects.create(name='Test Account2', currency=CURRENCY_USD) test_balance2 = test_account2.balance deposit.account = test_account2 deposit = FinanceService.save_deposit(user=self.test_user, deposit=deposit) # account balance unchanged self.assertAccount(test_account=test_account2, test_balance=test_balance2) # document data auto filled self.assertDocument(deposit, DOC_TYPE_DEPOSIT, test_account2.currency) # no aditional finantial history finantials = deposit.finantialdocumenthistory_set self.assertEqual(finantials.count(), 1) # no accounting history created accountings = deposit.accountingdocumenthistory_set self.assertEqual(accountings.count(), 0)