Пример #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)
Пример #2
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)
Пример #3
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)
Пример #4
0
    def test_agency_match_then_increase_amount(self):
        """
        Does match between agency_payment and agency_invoice then increase amount
        """
        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.amount = agency_invoice.amount + 20

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

        self.assertEqual(agency_invoice.matched_amount, test_amount)
Пример #5
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)
Пример #6
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)
Пример #7
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)
Пример #8
0
 def save_model(self, request, obj, form, change):
     # overrides base class method
     return FinanceService.save_agency_invoice(request.user, obj)