Exemple #1
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)
Exemple #2
0
    def test_agency_match_then_change_status(self):
        """
        Does match between agency_payment and agency_invoice then change status
        """
        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)

        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)

        agency_invoice.status = STATUS_DRAFT

        with self.assertRaisesMessage(ValidationError, ERROR_MATCH_STATUS):
            agency_invoice = FinanceService.save_agency_invoice(
                user=self.test_user, agency_invoice=agency_invoice)