Example #1
0
    def test_loan_account_match_then_change_account(self):
        """
        Does match between loan_account_deposit and loan_account_withdraw then change account
        """
        test_account1 = Account.objects.create(name='Test Account1',
                                               currency=CURRENCY_CUC,
                                               balance=1000)
        test_account2 = Account.objects.create(name='Test Loan Account',
                                               currency=CURRENCY_CUC,
                                               balance=1000)
        test_loan_account = LoanAccount.objects.create(account=test_account2)

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        loan_account_deposit = LoanAccountDeposit(
            date=test_date,
            account=test_account1,
            amount=test_amount,
            loan_account=test_loan_account,
            status=test_status)

        loan_account_deposit = FinanceService.save_loan_account_deposit(
            user=self.test_user, loan_account_deposit=loan_account_deposit)

        loan_account_withdraw = LoanAccountWithdraw(
            date=test_date,
            account=test_account1,
            amount=test_amount,
            loan_account=test_loan_account,
            status=test_status)

        loan_account_withdraw = FinanceService.save_loan_account_withdraw(
            user=self.test_user, loan_account_withdraw=loan_account_withdraw)

        loan_account_match = LoanAccountMatch(
            loan_account_deposit=loan_account_deposit,
            loan_account_withdraw=loan_account_withdraw,
            matched_amount=test_amount)

        loan_account_match = FinanceService.save_loan_account_match(
            loan_account_match)

        loan_account_deposit.refresh_from_db()
        loan_account_withdraw.refresh_from_db()

        self.assertEqual(loan_account_deposit.matched_amount, test_amount)
        self.assertEqual(loan_account_withdraw.matched_amount, test_amount)

        test_account2 = Account.objects.create(name='Test Account2',
                                               currency=CURRENCY_CUC,
                                               balance=500)

        loan_account_withdraw.account = test_account2

        with self.assertRaisesMessage(ValidationError, ERROR_MATCH_ACCOUNT):
            loan_account_withdraw = FinanceService.save_loan_account_withdraw(
                user=self.test_user,
                loan_account_withdraw=loan_account_withdraw)
Example #2
0
    def test_loan_entity_match_then_change_loan_entity(self):
        """
        Does match between loan_entity_deposit and loan_entity_withdraw then change loan_entity
        """
        test_account = Account.objects.create(
            name='Test Account',
            currency=CURRENCY_CUC,
            balance=1000)

        test_loan_entity1 = LoanEntity.objects.create(
            name='Test Loan Entity1')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        loan_entity_deposit = LoanEntityDeposit(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_entity=test_loan_entity1,
            status=test_status)

        loan_entity_deposit = FinanceService.save_loan_entity_deposit(
            user=self.test_user,
            loan_entity_deposit=loan_entity_deposit)

        loan_entity_withdraw = LoanEntityWithdraw(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_entity=test_loan_entity1,
            status=test_status)

        loan_entity_withdraw = FinanceService.save_loan_entity_withdraw(
            user=self.test_user,
            loan_entity_withdraw=loan_entity_withdraw)

        loan_entity_match = LoanEntityMatch(
            loan_entity_deposit=loan_entity_deposit,
            loan_entity_withdraw=loan_entity_withdraw,
            matched_amount=test_amount)

        loan_entity_match = FinanceService.save_loan_entity_match(loan_entity_match)

        loan_entity_deposit.refresh_from_db()
        loan_entity_withdraw.refresh_from_db()

        self.assertEqual(loan_entity_deposit.matched_amount, test_amount)
        self.assertEqual(loan_entity_withdraw.matched_amount, test_amount)

        test_loan_entity2 = LoanEntity.objects.create(
            name='Test Loan Entity2')

        loan_entity_withdraw.loan_entity = test_loan_entity2

        with self.assertRaisesMessage(ValidationError, ERROR_MATCH_LOAN_ENTITY):
            loan_entity_withdraw = FinanceService.save_loan_entity_withdraw(
                user=self.test_user,
                loan_entity_withdraw=loan_entity_withdraw)
Example #3
0
    def test_save_agency_invoice_ready_then_draft_currency(self):
        """
        Does ready agency_invoice and then change to draft and currency
        """
        test_currency1 = CURRENCY_CUC
        test_date = timezone.now()
        test_amount = 100
        test_status1 = STATUS_READY

        agency_invoice = AgencyInvoice(agency=self.test_agency,
                                       date=test_date,
                                       currency=test_currency1,
                                       amount=test_amount,
                                       status=test_status1)

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        # document data auto filled
        self.assertDocument(agency_invoice, DOC_TYPE_AGENCY_INVOICE,
                            test_currency1)

        # one finantial history created
        finantials = agency_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_invoice,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status1)

        test_status2 = STATUS_DRAFT
        test_currency2 = CURRENCY_USD

        agency_invoice.status = test_status2
        agency_invoice.currency = test_currency2

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        # document data auto filled
        self.assertDocument(agency_invoice, DOC_TYPE_AGENCY_INVOICE,
                            test_currency2)

        # now two finantial history created
        finantials = agency_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 2)

        # new finantial history info
        finantial = finantials.last()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_invoice,
                                    test_user=self.test_user,
                                    test_old_status=test_status1,
                                    test_new_status=test_status2)
Example #4
0
    def test_loan_entity_match_then_increase_amount(self):
        """
        Does match between loan_entity_deposit and loan_entity_withdraw then increase amount
        """
        test_account = Account.objects.create(
            name='Test Account',
            currency=CURRENCY_CUC,
            balance=1000)

        test_loan_entity = LoanEntity.objects.create(
            name='Test Loan Entity')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        loan_entity_deposit = LoanEntityDeposit(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_entity=test_loan_entity,
            status=test_status)

        loan_entity_deposit = FinanceService.save_loan_entity_deposit(
            user=self.test_user,
            loan_entity_deposit=loan_entity_deposit)

        loan_entity_withdraw = LoanEntityWithdraw(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_entity=test_loan_entity,
            status=test_status)

        loan_entity_withdraw = FinanceService.save_loan_entity_withdraw(
            user=self.test_user,
            loan_entity_withdraw=loan_entity_withdraw)

        loan_entity_match = LoanEntityMatch(
            loan_entity_deposit=loan_entity_deposit,
            loan_entity_withdraw=loan_entity_withdraw,
            matched_amount=test_amount)

        loan_entity_match = FinanceService.save_loan_entity_match(loan_entity_match)

        loan_entity_deposit.refresh_from_db()
        loan_entity_withdraw.refresh_from_db()

        self.assertEqual(loan_entity_deposit.matched_amount, test_amount)
        self.assertEqual(loan_entity_withdraw.matched_amount, test_amount)

        loan_entity_withdraw.amount = loan_entity_withdraw.amount + 20

        loan_entity_withdraw = FinanceService.save_loan_entity_withdraw(
            user=self.test_user,
            loan_entity_withdraw=loan_entity_withdraw)

        self.assertEqual(loan_entity_withdraw.matched_amount, test_amount)
    def test_provider_match_then_delete(self):
        """
        Does match between provider_payment and provider_invoice then delete
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)

        test_provider = Provider.objects.create(name='Test Provider')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        provider_payment = ProviderPayment(date=test_date,
                                           account=test_account,
                                           amount=test_amount,
                                           provider=test_provider,
                                           status=test_status)

        provider_payment = FinanceService.save_provider_payment(
            user=self.test_user, provider_payment=provider_payment)

        provider_invoice = ProviderInvoice(date=test_date,
                                           amount=test_amount,
                                           provider=test_provider,
                                           status=test_status)

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        provider_match = ProviderDocumentMatch(
            credit_document=provider_payment,
            debit_document=provider_invoice,
            matched_amount=test_amount)

        provider_match = FinanceService.save_provider_match(provider_match)

        # entity matched incremented
        self.assertProviderCurrencyMatchedAmount(provider=test_provider,
                                                 currency=CURRENCY_CUC,
                                                 amount=test_amount)

        provider_payment.refresh_from_db()
        provider_invoice.refresh_from_db()

        self.assertEqual(provider_payment.matched_amount, test_amount)
        self.assertEqual(provider_invoice.matched_amount, test_amount)

        # delete
        FinanceService.delete_provider_match(provider_match.pk)

        provider_payment.refresh_from_db()
        provider_invoice.refresh_from_db()

        self.assertEqual(provider_payment.matched_amount, 0)
        self.assertEqual(provider_invoice.matched_amount, 0)
    def test_save_agency_discount_draft_then_ready(self):
        """
        Does draft agency_discount and then change to ready
        """
        test_currency = CURRENCY_CUC
        test_date = timezone.now()
        test_amount = 100
        test_status1 = STATUS_DRAFT

        agency_discount = AgencyDiscount(agency=self.test_agency,
                                         date=test_date,
                                         currency=test_currency,
                                         amount=test_amount,
                                         status=test_status1)

        agency_discount = FinanceService.save_agency_discount(
            user=self.test_user, agency_discount=agency_discount)

        # document data auto filled
        self.assertDocument(agency_discount, DOC_TYPE_AGENCY_DISCOUNT,
                            test_currency)

        # one finantial history created
        finantials = agency_discount.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_discount,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status1)

        test_status2 = STATUS_READY

        agency_discount.status = test_status2

        agency_discount = FinanceService.save_agency_discount(
            user=self.test_user, agency_discount=agency_discount)

        # document data auto filled
        self.assertDocument(agency_discount, DOC_TYPE_AGENCY_DISCOUNT,
                            test_currency)

        # now two finantial history created
        finantials = agency_discount.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 2)

        # new finantial history info
        finantial = finantials.last()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_discount,
                                    test_user=self.test_user,
                                    test_old_status=test_status1,
                                    test_new_status=test_status2)
Example #7
0
    def test_agency_match_then_delete(self):
        """
        Does match between agency_payment and agency_invoice then delete
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)

        test_agency = Agency.objects.create(name='Test Agency')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        agency_payment = AgencyPayment(date=test_date,
                                       account=test_account,
                                       amount=test_amount,
                                       agency=test_agency,
                                       status=test_status)

        agency_payment = FinanceService.save_agency_payment(
            user=self.test_user, agency_payment=agency_payment)

        agency_invoice = AgencyInvoice(date=test_date,
                                       amount=test_amount,
                                       agency=test_agency,
                                       status=test_status)

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        agency_match = AgencyDocumentMatch(credit_document=agency_payment,
                                           debit_document=agency_invoice,
                                           matched_amount=test_amount)

        agency_match = FinanceService.save_agency_match(agency_match)

        # entity matched incremented
        self.assertAgencyCurrencyMatchedAmount(agency=test_agency,
                                               currency=CURRENCY_CUC,
                                               amount=test_amount)

        agency_payment.refresh_from_db()
        agency_invoice.refresh_from_db()

        self.assertEqual(agency_payment.matched_amount, test_amount)
        self.assertEqual(agency_invoice.matched_amount, test_amount)

        # delete
        FinanceService.delete_agency_match(agency_match.pk)

        agency_payment.refresh_from_db()
        agency_invoice.refresh_from_db()

        self.assertEqual(agency_payment.matched_amount, 0)
        self.assertEqual(agency_invoice.matched_amount, 0)
    def test_save_provider_invoice_draft_then_ready(self):
        """
        Does draft provider_invoice and then change to ready
        """
        test_currency = CURRENCY_CUC
        test_date = timezone.now()
        test_amount = 100
        test_status1 = STATUS_DRAFT

        provider_invoice = ProviderInvoice(provider=self.test_provider,
                                           date=test_date,
                                           currency=test_currency,
                                           amount=test_amount,
                                           status=test_status1)

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        # document data auto filled
        self.assertDocument(provider_invoice, DOC_TYPE_PROVIDER_INVOICE,
                            test_currency)

        # one finantial history created
        finantials = provider_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=provider_invoice,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status1)

        test_status2 = STATUS_READY

        provider_invoice.status = test_status2

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        # document data auto filled
        self.assertDocument(provider_invoice, DOC_TYPE_PROVIDER_INVOICE,
                            test_currency)

        # now two finantial history created
        finantials = provider_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 2)

        # new finantial history info
        finantial = finantials.last()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=provider_invoice,
                                    test_user=self.test_user,
                                    test_old_status=test_status1,
                                    test_new_status=test_status2)
Example #9
0
    def test_save_agency_invoice_ready_then_date(self):
        """
        Does ready agency_invoice and then change to draft
        """
        test_currency = CURRENCY_CUC
        test_date1 = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        agency_invoice = AgencyInvoice(agency=self.test_agency,
                                       date=test_date1,
                                       currency=test_currency,
                                       amount=test_amount,
                                       status=test_status)

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        test_name1 = agency_invoice.name

        # document data auto filled
        self.assertDocument(agency_invoice, DOC_TYPE_AGENCY_INVOICE,
                            test_currency)

        # one finantial history created
        finantials = agency_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_invoice,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        test_date2 = test_date1 - timedelta(days=5)

        agency_invoice.date = test_date2

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        test_name2 = agency_invoice.name

        # name changed
        self.assertNotEqual(test_name1, test_name2)

        # document data auto filled
        self.assertDocument(agency_invoice, DOC_TYPE_AGENCY_INVOICE,
                            test_currency)

        # same finantial history
        finantials = agency_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)
    def test_save_agency_discount_draft_then_date(self):
        """
        Does draft agency_discount and then change date
        """
        test_currency = CURRENCY_CUC
        test_date1 = timezone.now()
        test_amount = 100
        test_status = STATUS_DRAFT

        agency_discount = AgencyDiscount(agency=self.test_agency,
                                         date=test_date1,
                                         currency=test_currency,
                                         amount=test_amount,
                                         status=test_status)

        agency_discount = FinanceService.save_agency_discount(
            user=self.test_user, agency_discount=agency_discount)

        test_name1 = agency_discount.name

        # document data auto filled
        self.assertDocument(agency_discount, DOC_TYPE_AGENCY_DISCOUNT,
                            test_currency)

        # one finantial history created
        finantials = agency_discount.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_discount,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        test_date2 = test_date1 - timedelta(days=5)

        agency_discount.date = test_date2

        agency_discount = FinanceService.save_agency_discount(
            user=self.test_user, agency_discount=agency_discount)

        test_name2 = agency_discount.name

        # name changed
        self.assertNotEqual(test_name1, test_name2)

        # document data auto filled
        self.assertDocument(agency_discount, DOC_TYPE_AGENCY_DISCOUNT,
                            test_currency)

        # no finantial history created
        finantials = agency_discount.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)
    def test_save_provider_invoice_draft_then_date(self):
        """
        Does draft provider_invoice and then change date
        """
        test_currency = CURRENCY_CUC
        test_date1 = timezone.now()
        test_amount = 100
        test_status = STATUS_DRAFT

        provider_invoice = ProviderInvoice(provider=self.test_provider,
                                           date=test_date1,
                                           currency=test_currency,
                                           amount=test_amount,
                                           status=test_status)

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        test_name1 = provider_invoice.name

        # document data auto filled
        self.assertDocument(provider_invoice, DOC_TYPE_PROVIDER_INVOICE,
                            test_currency)

        # one finantial history created
        finantials = provider_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=provider_invoice,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        test_date2 = test_date1 - timedelta(days=5)

        provider_invoice.date = test_date2

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        test_name2 = provider_invoice.name

        # name changed
        self.assertNotEqual(test_name1, test_name2)

        # document data auto filled
        self.assertDocument(provider_invoice, DOC_TYPE_PROVIDER_INVOICE,
                            test_currency)

        # no finantial history created
        finantials = provider_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)
Example #12
0
    def test_loan_account_match(self):
        """
        Does match between loan_account_deposit and loan_account_withdraw
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)
        test_account2 = Account.objects.create(name='Test Loan Account',
                                               currency=CURRENCY_CUC,
                                               balance=1000)
        test_loan_account = LoanAccount.objects.create(account=test_account2)

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        loan_account_deposit = LoanAccountDeposit(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_account=test_loan_account,
            status=test_status)

        loan_account_deposit = FinanceService.save_loan_account_deposit(
            user=self.test_user, loan_account_deposit=loan_account_deposit)

        loan_account_withdraw = LoanAccountWithdraw(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_account=test_loan_account,
            status=test_status)

        loan_account_withdraw = FinanceService.save_loan_account_withdraw(
            user=self.test_user, loan_account_withdraw=loan_account_withdraw)

        loan_account_match = LoanAccountMatch(
            loan_account_deposit=loan_account_deposit,
            loan_account_withdraw=loan_account_withdraw,
            matched_amount=test_amount)

        loan_account_match = FinanceService.save_loan_account_match(
            loan_account_match)

        test_loan_account = LoanAccount.objects.get(pk=test_loan_account.pk)
        # entity matched incremented
        self.assertEqual(test_loan_account.matched_amount, test_amount)

        loan_account_deposit.refresh_from_db()
        loan_account_withdraw.refresh_from_db()

        self.assertEqual(loan_account_deposit.matched_amount, test_amount)
        self.assertEqual(loan_account_withdraw.matched_amount, test_amount)
    def test_provider_match_then_change_provider(self):
        """
        Does match between provider_payment and provider_invoice then change provider
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)

        test_provider1 = Provider.objects.create(name='Test Provider1')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        provider_payment = ProviderPayment(date=test_date,
                                           account=test_account,
                                           amount=test_amount,
                                           provider=test_provider1,
                                           status=test_status)

        provider_payment = FinanceService.save_provider_payment(
            user=self.test_user, provider_payment=provider_payment)

        provider_invoice = ProviderInvoice(date=test_date,
                                           amount=test_amount,
                                           provider=test_provider1,
                                           status=test_status)

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        provider_match = ProviderDocumentMatch(
            credit_document=provider_payment,
            debit_document=provider_invoice,
            matched_amount=test_amount)

        provider_match = FinanceService.save_provider_match(provider_match)

        provider_payment.refresh_from_db()
        provider_invoice.refresh_from_db()

        self.assertEqual(provider_payment.matched_amount, test_amount)
        self.assertEqual(provider_invoice.matched_amount, test_amount)

        test_provider2 = Provider.objects.create(name='Test Provider2')

        provider_invoice.provider = test_provider2

        with self.assertRaisesMessage(ValidationError, ERROR_MATCH_PROVIDER):
            provider_invoice = FinanceService.save_provider_invoice(
                user=self.test_user, provider_invoice=provider_invoice)
    def test_save_provider_invoice_ready_then_amount_currency(self):
        """
        Does ready provider_invoice and then change amount and currency
        """
        test_currency1 = CURRENCY_CUC
        test_date = timezone.now()
        test_amount1 = 100
        test_status = STATUS_READY

        provider_invoice = ProviderInvoice(provider=self.test_provider,
                                           date=test_date,
                                           currency=test_currency1,
                                           amount=test_amount1,
                                           status=test_status)

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        # document data auto filled
        self.assertDocument(provider_invoice, DOC_TYPE_PROVIDER_INVOICE,
                            test_currency1)

        # one finantial history created
        finantials = provider_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=provider_invoice,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        test_currency2 = CURRENCY_USD
        test_amount2 = 50

        provider_invoice.currency = test_currency2
        provider_invoice.amount = test_amount2

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        # document data auto filled
        self.assertDocument(provider_invoice, DOC_TYPE_PROVIDER_INVOICE,
                            test_currency2)

        # no aditional finantial history
        finantials = provider_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)
    def test_save_agency_discount_ready_then_amount_currency(self):
        """
        Does ready agency_discount and then change amount and currency
        """
        test_currency1 = CURRENCY_CUC
        test_date = timezone.now()
        test_amount1 = 100
        test_status = STATUS_READY

        agency_discount = AgencyDiscount(agency=self.test_agency,
                                         date=test_date,
                                         currency=test_currency1,
                                         amount=test_amount1,
                                         status=test_status)

        agency_discount = FinanceService.save_agency_discount(
            user=self.test_user, agency_discount=agency_discount)

        # document data auto filled
        self.assertDocument(agency_discount, DOC_TYPE_AGENCY_DISCOUNT,
                            test_currency1)

        # one finantial history created
        finantials = agency_discount.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_discount,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        test_currency2 = CURRENCY_USD
        test_amount2 = 50

        agency_discount.currency = test_currency2
        agency_discount.amount = test_amount2

        agency_discount = FinanceService.save_agency_discount(
            user=self.test_user, agency_discount=agency_discount)

        # document data auto filled
        self.assertDocument(agency_discount, DOC_TYPE_AGENCY_DISCOUNT,
                            test_currency2)

        # no aditional finantial history
        finantials = agency_discount.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)
Example #16
0
    def test_agency_match_then_change_agency(self):
        """
        Does match between agency_payment and agency_invoice then change agency
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)

        test_agency1 = Agency.objects.create(name='Test Agency1')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        agency_payment = AgencyPayment(date=test_date,
                                       account=test_account,
                                       amount=test_amount,
                                       agency=test_agency1,
                                       status=test_status)

        agency_payment = FinanceService.save_agency_payment(
            user=self.test_user, agency_payment=agency_payment)

        agency_invoice = AgencyInvoice(date=test_date,
                                       amount=test_amount,
                                       agency=test_agency1,
                                       status=test_status)

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        agency_match = AgencyDocumentMatch(credit_document=agency_payment,
                                           debit_document=agency_invoice,
                                           matched_amount=test_amount)

        agency_match = FinanceService.save_agency_match(agency_match)

        agency_payment.refresh_from_db()
        agency_invoice.refresh_from_db()

        self.assertEqual(agency_payment.matched_amount, test_amount)
        self.assertEqual(agency_invoice.matched_amount, test_amount)

        test_agency2 = Agency.objects.create(name='Test Agency2')

        agency_invoice.agency = test_agency2

        with self.assertRaisesMessage(ValidationError, ERROR_MATCH_AGENCY):
            agency_invoice = FinanceService.save_agency_invoice(
                user=self.test_user, agency_invoice=agency_invoice)
Example #17
0
    def test_loan_entity_match_different_accounts(self):
        """
        Does match between loan_entity_deposit and loan_entity_withdraw with different accounts
        """
        test_account1 = Account.objects.create(
            name='Test Account1',
            currency=CURRENCY_CUC,
            balance=1000)

        test_loan_entity = LoanEntity.objects.create(
            name='Test Loan Entity')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        loan_entity_deposit = LoanEntityDeposit(
            date=test_date,
            account=test_account1,
            amount=test_amount,
            loan_entity=test_loan_entity,
            status=test_status)

        loan_entity_deposit = FinanceService.save_loan_entity_deposit(
            user=self.test_user,
            loan_entity_deposit=loan_entity_deposit)

        test_account2 = Account.objects.create(
            name='Test Account2',
            currency=CURRENCY_CUC,
            balance=500)

        loan_entity_withdraw = LoanEntityWithdraw(
            date=test_date,
            account=test_account2,
            amount=test_amount,
            loan_entity=test_loan_entity,
            status=test_status)

        loan_entity_withdraw = FinanceService.save_loan_entity_withdraw(
            user=self.test_user,
            loan_entity_withdraw=loan_entity_withdraw)

        loan_entity_match = LoanEntityMatch(
            loan_entity_deposit=loan_entity_deposit,
            loan_entity_withdraw=loan_entity_withdraw,
            matched_amount=test_amount)

        with self.assertRaises(ValidationError):
            loan_entity_match = FinanceService.save_loan_entity_match(loan_entity_match)
Example #18
0
    def test_save_agency_invoice_ready_then_amount(self):
        """
        Does ready agency_invoice and then change amount
        """
        test_currency = CURRENCY_CUC
        test_date = timezone.now()
        test_amount1 = 100
        test_status = STATUS_READY

        agency_invoice = AgencyInvoice(agency=self.test_agency,
                                       date=test_date,
                                       currency=test_currency,
                                       amount=test_amount1,
                                       status=test_status)

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        # document data auto filled
        self.assertDocument(agency_invoice, DOC_TYPE_AGENCY_INVOICE,
                            test_currency)

        # one finantial history created
        finantials = agency_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_invoice,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        test_amount2 = 50

        agency_invoice.amount = test_amount2

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        # document data auto filled
        self.assertDocument(agency_invoice, DOC_TYPE_AGENCY_INVOICE,
                            test_currency)

        # no aditional finantial history
        finantials = agency_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)
Example #19
0
    def test_save_agency_invoice_status_draft(self):
        """
        Does draft agency_invoice
        """
        test_currency = CURRENCY_CUC
        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_DRAFT

        agency_invoice = AgencyInvoice(agency=self.test_agency,
                                       date=test_date,
                                       currency=test_currency,
                                       amount=test_amount,
                                       status=test_status)

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        # document data auto filled
        self.assertDocument(agency_invoice, DOC_TYPE_AGENCY_INVOICE,
                            test_currency)

        # one finantial history created
        finantials = agency_invoice.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_invoice,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)
Example #20
0
    def test_save_withdraw_status_ready(self):
        """
        Does ready withdraw
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)
        test_balance = test_account.balance

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        withdraw = Withdraw(date=test_date,
                            account=test_account,
                            amount=test_amount,
                            status=test_status)

        withdraw = FinanceService.save_withdraw(user=self.test_user,
                                                withdraw=withdraw)

        # account balance decremented
        self.assertAccount(test_account=test_account,
                           test_balance=test_balance - test_amount)

        # document data auto filled
        self.assertDocument(withdraw, DOC_TYPE_WITHDRAW, test_account.currency)

        # one finantial history created
        finantials = withdraw.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=withdraw,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # one accounting history created
        accountings = withdraw.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_account,
                            test_movement_type=MOVEMENT_TYPE_OUTPUT,
                            test_amount=test_amount)
    def test_save_provider_devolution_status_ready(self):
        """
        Does ready provider_devolution
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC)
        test_balance = test_account.balance

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        provider_devolution = ProviderDevolution(provider=self.test_provider,
                                                 date=test_date,
                                                 account=test_account,
                                                 amount=test_amount,
                                                 status=test_status)

        provider_devolution = FinanceService.save_provider_devolution(
            user=self.test_user, provider_devolution=provider_devolution)

        # account balance incremented
        self.assertAccount(test_account=test_account,
                           test_balance=test_balance + test_amount)

        # document data auto filled
        self.assertDocument(provider_devolution, DOC_TYPE_PROVIDER_DEVOLUTION,
                            test_account.currency)

        # one finantial history created
        finantials = provider_devolution.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=provider_devolution,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # one accounting history created
        accountings = provider_devolution.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_account,
                            test_movement_type=MOVEMENT_TYPE_INPUT,
                            test_amount=test_amount)
Example #22
0
    def test_save_agency_payment_status_ready(self):
        """
        Does ready agency_payment
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC)
        test_balance = test_account.balance

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        agency_payment = AgencyPayment(agency=self.test_agency,
                                       date=test_date,
                                       account=test_account,
                                       amount=test_amount,
                                       status=test_status)

        agency_payment = FinanceService.save_agency_payment(
            user=self.test_user, agency_payment=agency_payment)

        # account balance incremented
        self.assertAccount(test_account=test_account,
                           test_balance=test_balance + test_amount)

        # document data auto filled
        self.assertDocument(agency_payment, DOC_TYPE_AGENCY_PAYMENT,
                            test_account.currency)

        # one finantial history created
        finantials = agency_payment.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_payment,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # one accounting history created
        accountings = agency_payment.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_account,
                            test_movement_type=MOVEMENT_TYPE_INPUT,
                            test_amount=test_amount)
Example #23
0
    def test_loan_account_match_excesive_amount(self):
        """
        Does match between loan_account_deposit and loan_account_withdraw with excesive amount
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)
        test_account2 = Account.objects.create(name='Test Loan Account',
                                               currency=CURRENCY_CUC,
                                               balance=1000)
        test_loan_account = LoanAccount.objects.create(account=test_account2)

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        loan_account_deposit = LoanAccountDeposit(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_account=test_loan_account,
            status=test_status)

        loan_account_deposit = FinanceService.save_loan_account_deposit(
            user=self.test_user, loan_account_deposit=loan_account_deposit)

        loan_account_withdraw = LoanAccountWithdraw(
            date=test_date,
            account=test_account,
            amount=test_amount,
            loan_account=test_loan_account,
            status=test_status)

        loan_account_withdraw = FinanceService.save_loan_account_withdraw(
            user=self.test_user, loan_account_withdraw=loan_account_withdraw)

        loan_account_match = LoanAccountMatch(
            loan_account_deposit=loan_account_deposit,
            loan_account_withdraw=loan_account_withdraw,
            matched_amount=test_amount + 0.01)

        with self.assertRaises(ValidationError):
            loan_account_match = FinanceService.save_loan_account_match(
                loan_account_match)
    def test_provider_match_different_provider(self):
        """
        Does match between provider_payment and provider_invoice with different loan_entities
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)

        test_provider1 = Provider.objects.create(name='Test Provider1')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        provider_payment = ProviderPayment(date=test_date,
                                           account=test_account,
                                           amount=test_amount,
                                           provider=test_provider1,
                                           status=test_status)

        provider_payment = FinanceService.save_provider_payment(
            user=self.test_user, provider_payment=provider_payment)

        test_provider2 = Provider.objects.create(name='Test Provider2')

        provider_invoice = ProviderInvoice(date=test_date,
                                           amount=test_amount,
                                           provider=test_provider2,
                                           status=test_status)

        provider_invoice = FinanceService.save_provider_invoice(
            user=self.test_user, provider_invoice=provider_invoice)

        provider_match = ProviderDocumentMatch(
            credit_document=provider_payment,
            debit_document=provider_invoice,
            matched_amount=test_amount)

        with self.assertRaises(ValidationError):
            provider_match = FinanceService.save_provider_match(provider_match)
Example #25
0
    def test_agency_match_different_agency(self):
        """
        Does match between agency_payment and agency_invoice with different loan_entities
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)

        test_agency1 = Agency.objects.create(name='Test Agency1')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_READY

        agency_payment = AgencyPayment(date=test_date,
                                       account=test_account,
                                       amount=test_amount,
                                       agency=test_agency1,
                                       status=test_status)

        agency_payment = FinanceService.save_agency_payment(
            user=self.test_user, agency_payment=agency_payment)

        test_agency2 = Agency.objects.create(name='Test Agency2')

        agency_invoice = AgencyInvoice(date=test_date,
                                       amount=test_amount,
                                       agency=test_agency2,
                                       status=test_status)

        agency_invoice = FinanceService.save_agency_invoice(
            user=self.test_user, agency_invoice=agency_invoice)

        agency_match = AgencyDocumentMatch(credit_document=agency_payment,
                                           debit_document=agency_invoice,
                                           matched_amount=test_amount)

        with self.assertRaises(ValidationError):
            agency_match = FinanceService.save_agency_match(agency_match)
    def test_save_loan_entity_deposit_status_draft(self):
        """
        Does draft loan_entity_deposit
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC)
        test_balance = test_account.balance

        test_loan_entity = LoanEntity.objects.create(name='Test Loan Entity')

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_DRAFT

        loan_entity_deposit = LoanEntityDeposit(date=test_date,
                                                account=test_account,
                                                amount=test_amount,
                                                loan_entity=test_loan_entity,
                                                status=test_status)

        loan_entity_deposit = FinanceService.save_loan_entity_deposit(
            user=self.test_user, loan_entity_deposit=loan_entity_deposit)

        # account balance unchanged
        self.assertAccount(test_account=test_account,
                           test_balance=test_balance)

        # document data auto filled
        self.assertDocument(loan_entity_deposit, DOC_TYPE_LOAN_ENTITY_DEPOSIT,
                            test_account.currency)

        # one finantial history created
        finantials = loan_entity_deposit.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=loan_entity_deposit,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # no accounting history created
        accountings = loan_entity_deposit.accountingdocumenthistory_set
        self.assertEqual(accountings.count(), 0)
    def test_save_provider_devolution_status_draft(self):
        """
        Does draft provider_devolution
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC)
        test_balance = test_account.balance

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_DRAFT

        provider_devolution = ProviderDevolution(provider=self.test_provider,
                                                 date=test_date,
                                                 account=test_account,
                                                 amount=test_amount,
                                                 status=test_status)

        provider_devolution = FinanceService.save_provider_devolution(
            user=self.test_user, provider_devolution=provider_devolution)

        # account balance unchanged
        self.assertAccount(test_account=test_account,
                           test_balance=test_balance)

        # document data auto filled
        self.assertDocument(provider_devolution, DOC_TYPE_PROVIDER_DEVOLUTION,
                            test_account.currency)

        # one finantial history created
        finantials = provider_devolution.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=provider_devolution,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # no accounting history created
        accountings = provider_devolution.accountingdocumenthistory_set
        self.assertEqual(accountings.count(), 0)
Example #28
0
    def test_save_agency_payment_status_draft(self):
        """
        Does draft agency_payment
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC)
        test_balance = test_account.balance

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_DRAFT

        agency_payment = AgencyPayment(agency=self.test_agency,
                                       date=test_date,
                                       account=test_account,
                                       amount=test_amount,
                                       status=test_status)

        agency_payment = FinanceService.save_agency_payment(
            user=self.test_user, agency_payment=agency_payment)

        # account balance unchanged
        self.assertAccount(test_account=test_account,
                           test_balance=test_balance)

        # document data auto filled
        self.assertDocument(agency_payment, DOC_TYPE_AGENCY_PAYMENT,
                            test_account.currency)

        # one finantial history created
        finantials = agency_payment.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_payment,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # no accounting history created
        accountings = agency_payment.accountingdocumenthistory_set
        self.assertEqual(accountings.count(), 0)
Example #29
0
    def test_save_withdraw_status_draft(self):
        """
        Does draft withdraw
        """
        test_account = Account.objects.create(name='Test Account',
                                              currency=CURRENCY_CUC,
                                              balance=1000)
        test_balance = test_account.balance

        test_date = timezone.now()
        test_amount = 100
        test_status = STATUS_DRAFT

        withdraw = Withdraw(date=test_date,
                            account=test_account,
                            amount=test_amount,
                            status=test_status)

        withdraw = FinanceService.save_withdraw(user=self.test_user,
                                                withdraw=withdraw)

        # account balance unchanged
        self.assertAccount(test_account=test_account,
                           test_balance=test_balance)

        # document data auto filled
        self.assertDocument(withdraw, DOC_TYPE_WITHDRAW, test_account.currency)

        # one finantial history created
        finantials = withdraw.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=withdraw,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # no accounting history created
        accountings = withdraw.accountingdocumenthistory_set
        self.assertEqual(accountings.count(), 0)
Example #30
0
    def test_save_agency_payment_ready_then_amount_account(self):
        """
        Does ready agency_payment 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

        agency_payment = AgencyPayment(agency=self.test_agency,
                                       date=test_date,
                                       account=test_account1,
                                       amount=test_amount1,
                                       status=test_status)

        agency_payment = FinanceService.save_agency_payment(
            user=self.test_user, agency_payment=agency_payment)

        # account balance incremented
        self.assertAccount(test_account=test_account1,
                           test_balance=test_balance1 + test_amount1)

        # document data auto filled
        self.assertDocument(agency_payment, DOC_TYPE_AGENCY_PAYMENT,
                            test_account1.currency)

        # one finantial history created
        finantials = agency_payment.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # finantial history info
        finantial = finantials.first()
        self.assertFinantialHistory(test_finantial_history=finantial,
                                    test_document=agency_payment,
                                    test_user=self.test_user,
                                    test_old_status=None,
                                    test_new_status=test_status)

        # one accounting history created
        accountings = agency_payment.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

        agency_payment.account = test_account2
        agency_payment.amount = test_amount2

        agency_payment = FinanceService.save_agency_payment(
            user=self.test_user, agency_payment=agency_payment)

        # 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(agency_payment, DOC_TYPE_AGENCY_PAYMENT,
                            test_account2.currency)

        # no aditional finantial history
        finantials = agency_payment.finantialdocumenthistory_set
        self.assertEqual(finantials.count(), 1)

        # two accounting history created
        accountings = agency_payment.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)