def test_save_provider_invoice_ready_then_draft_currency(self): """ Does ready provider_invoice and then change to draft and currency """ test_currency1 = CURRENCY_CUC test_date = timezone.now() test_amount = 100 test_status1 = STATUS_READY provider_invoice = ProviderInvoice(provider=self.test_provider, date=test_date, currency=test_currency1, 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_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_status1) test_status2 = STATUS_DRAFT test_currency2 = CURRENCY_USD provider_invoice.status = test_status2 provider_invoice.currency = test_currency2 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) # 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)
def test_save_provider_invoice_ready_then_date(self): """ Does ready provider_invoice and then change to draft """ test_currency = CURRENCY_CUC test_date1 = timezone.now() test_amount = 100 test_status = STATUS_READY 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) # same finantial history finantials = provider_invoice.finantialdocumenthistory_set self.assertEqual(finantials.count(), 1)
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_provider_match_then_increase_amount(self): """ Does match between provider_payment and provider_invoice then increase amount """ 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) 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) provider_invoice.amount = provider_invoice.amount + 20 provider_invoice = FinanceService.save_provider_invoice( user=self.test_user, provider_invoice=provider_invoice) self.assertEqual(provider_invoice.matched_amount, test_amount)
def test_save_provider_invoice_ready_then_amount(self): """ Does ready provider_invoice and then change amount """ test_currency = 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_currency, 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_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_amount2 = 50 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_currency) # no aditional finantial history finantials = provider_invoice.finantialdocumenthistory_set self.assertEqual(finantials.count(), 1)
def test_save_provider_invoice_status_draft(self): """ Does draft provider_invoice """ test_currency = CURRENCY_CUC test_date = timezone.now() test_amount = 100 test_status = STATUS_DRAFT provider_invoice = ProviderInvoice(provider=self.test_provider, date=test_date, currency=test_currency, amount=test_amount, 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_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)
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 = FinanceServices.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 = FinanceServices.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 = FinanceServices.save_provider_match( provider_match)