#69 feat(Reconciliation):get purchases for reconciliation endpoint.
This commit is contained in:
		
							
								
								
									
										111
									
								
								tienda_ilusion/don_confiao/tests/test_jar_reconciliation.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										111
									
								
								tienda_ilusion/don_confiao/tests/test_jar_reconciliation.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,111 @@ | ||||
| from django.test import TestCase, Client | ||||
| from ..models import Sale, Product, SaleLine, Customer, ReconciliationJar | ||||
|  | ||||
| import json | ||||
|  | ||||
| class TestJarReconcliation(TestCase): | ||||
|     def setUp(self): | ||||
|         customer = Customer() | ||||
|         customer.name = 'Alejo Mono' | ||||
|         customer.save() | ||||
|  | ||||
|         self.client = Client() | ||||
|  | ||||
|         purchase = Sale() | ||||
|         purchase.customer = customer | ||||
|         purchase.date = "2024-07-30" | ||||
|         purchase.payment_method = 'CASH' | ||||
|         purchase.clean() | ||||
|         purchase.save() | ||||
|  | ||||
|         product = Product() | ||||
|         product.name = "cafe" | ||||
|         product.price = "72500" | ||||
|         product.save() | ||||
|  | ||||
|         line = SaleLine() | ||||
|         line.sale = purchase | ||||
|         line.product = product | ||||
|         line.quantity = "11" | ||||
|         line.unit_price = "72500" | ||||
|         line.save() | ||||
|         self.purchase = purchase | ||||
|  | ||||
|         purchase2 = Sale() | ||||
|         purchase2.customer = customer | ||||
|         purchase2.date = "2024-07-30" | ||||
|         purchase.payment_method = 'CASH' | ||||
|         purchase2.clean() | ||||
|         purchase2.save() | ||||
|  | ||||
|         line2 = SaleLine() | ||||
|         line2.sale = purchase2 | ||||
|         line2.product = product | ||||
|         line2.quantity = "27" | ||||
|         line2.unit_price = "72500" | ||||
|         line2.save() | ||||
|         self.purchase2 = purchase2 | ||||
|  | ||||
|         purchase3 = Sale() | ||||
|         purchase3.customer = customer | ||||
|         purchase3.date = "2024-07-30" | ||||
|         purchase3.payment_method = 'CASH' | ||||
|         purchase3.clean() | ||||
|         purchase3.save() | ||||
|  | ||||
|         line3 = SaleLine() | ||||
|         line3.sale = purchase3 | ||||
|         line3.product = product | ||||
|         line3.quantity = "37" | ||||
|         line3.unit_price = "72500" | ||||
|         line3.save() | ||||
|         self.purchase3 = purchase3 | ||||
|  | ||||
|         purchase4 = Sale() | ||||
|         purchase4.customer = customer | ||||
|         purchase4.date = "2024-07-30" | ||||
|         purchase4.payment_method = 'CONFIAR' | ||||
|         purchase4.clean() | ||||
|         purchase4.save() | ||||
|  | ||||
|         line4 = SaleLine() | ||||
|         line4.sale = purchase4 | ||||
|         line4.product = product | ||||
|         line4.quantity = "47" | ||||
|         line4.unit_price = "72500" | ||||
|         line4.save() | ||||
|         self.purchase4 = purchase4 | ||||
|  | ||||
|     def test_create_reconciliation_jar(self): | ||||
|         reconciliation = self._create_reconciliation() | ||||
|         self.assertTrue(isinstance(reconciliation, ReconciliationJar)) | ||||
|  | ||||
|     def test_get_purchases_for_reconciliation(self): | ||||
|         # link purchase to reconciliation to exclude from list | ||||
|         reconciliation = self._create_reconciliation() | ||||
|         self.purchase3.reconciliation = reconciliation | ||||
|         self.purchase3.clean() | ||||
|         self.purchase3.save() | ||||
|  | ||||
|         url = '/don_confiao/purchases/for_reconciliation' | ||||
|         response = self.client.get(url) | ||||
|         self.assertEqual(response.status_code, 200) | ||||
|  | ||||
|         rawContent = response.content.decode('utf-8') | ||||
|         content = json.loads(rawContent) | ||||
|  | ||||
|         self.assertIn('CASH', content.keys()) | ||||
|         self.assertIn('CONFIAR', content.keys()) | ||||
|         self.assertEqual(2, len(content.get('CASH'))) | ||||
|         self.assertEqual(1, len(content.get('CONFIAR'))) | ||||
|         self.assertNotIn(str(37*72500), rawContent) | ||||
|         self.assertIn(str(47*72500), rawContent) | ||||
|  | ||||
|     def _create_reconciliation(self): | ||||
|         reconciliation = ReconciliationJar() | ||||
|         reconciliation.date_time = "2024-07-30" | ||||
|         reconciliation.cash_taken = 0 | ||||
|         reconciliation.cash_discrepancy = 0 | ||||
|         reconciliation.clean() | ||||
|         reconciliation.save() | ||||
|         return reconciliation | ||||
		Reference in New Issue
	
	Block a user