#69 feat(ReconciliationJar): add purchases to list.
This commit is contained in:
parent
f0201a86b2
commit
ef721a6b53
@ -4,6 +4,7 @@ from ..models import Sale, Product, SaleLine, Customer, ReconciliationJar
|
|||||||
|
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
class TestJarReconcliation(TestCase):
|
class TestJarReconcliation(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
customer = Customer()
|
customer = Customer()
|
||||||
@ -114,12 +115,18 @@ class TestJarReconcliation(TestCase):
|
|||||||
|
|
||||||
def test_create_reconciliation_with_purchases(self):
|
def test_create_reconciliation_with_purchases(self):
|
||||||
url = '/don_confiao/reconciliation_jar/create'
|
url = '/don_confiao/reconciliation_jar/create'
|
||||||
|
total_purchases = (11 * 72500) + (27 * 72500)
|
||||||
data = {
|
data = {
|
||||||
'date_time': '2024-12-02T21:07',
|
'date_time': '2024-12-02T21:07',
|
||||||
'cashman': 'carlos',
|
'cashman': 'carlos',
|
||||||
'total_cash_purchases': 45000,
|
'total_cash_purchases': total_purchases,
|
||||||
'cash_taken': 44000,
|
'cash_taken': total_purchases,
|
||||||
'cash_discrepancy': 1000,
|
'cash_discrepancy': 0,
|
||||||
|
'purchases': json.dumps([#machete por error al codificar el json en el request
|
||||||
|
self.purchase.id,
|
||||||
|
self.purchase2.id,
|
||||||
|
self.purchase.id,
|
||||||
|
]),
|
||||||
}
|
}
|
||||||
response = self.client.post(url, data, format='json')
|
response = self.client.post(url, data, format='json')
|
||||||
rawContent = response.content.decode('utf-8')
|
rawContent = response.content.decode('utf-8')
|
||||||
@ -128,6 +135,9 @@ class TestJarReconcliation(TestCase):
|
|||||||
self.assertEqual(response.status_code, 200)
|
self.assertEqual(response.status_code, 200)
|
||||||
self.assertIn('id', content)
|
self.assertIn('id', content)
|
||||||
|
|
||||||
|
purchases = Sale.objects.filter(reconciliation_id=content['id'])
|
||||||
|
self.assertEqual(len(purchases), 2)
|
||||||
|
|
||||||
def _create_simple_reconciliation(self):
|
def _create_simple_reconciliation(self):
|
||||||
reconciliation = ReconciliationJar()
|
reconciliation = ReconciliationJar()
|
||||||
reconciliation.date_time = "2024-07-30"
|
reconciliation.date_time = "2024-07-30"
|
||||||
|
@ -113,14 +113,25 @@ def reconciliate_jar(request):
|
|||||||
date_format = '%Y-%m-%dT%H:%M'
|
date_format = '%Y-%m-%dT%H:%M'
|
||||||
if request.method == 'POST':
|
if request.method == 'POST':
|
||||||
content = request.POST.dict()
|
content = request.POST.dict()
|
||||||
|
content['purchases'] = json.loads(content.get('purchases'))#machete por error al codificar el json en el test
|
||||||
reconciliation = ReconciliationJar()
|
reconciliation = ReconciliationJar()
|
||||||
reconciliation.date_time = content.get('date_time')
|
reconciliation.date_time = content.get('date_time')
|
||||||
reconciliation.cashman = content.get('cashman')
|
reconciliation.cashman = content.get('cashman')
|
||||||
reconciliation.total_cash_purchases = float(content.get('total_cash_purchases'))
|
reconciliation.total_cash_purchases = float(content.get('total_cash_purchases'))
|
||||||
reconciliation.cash_taken = float(content.get('cash_taken'))
|
reconciliation.cash_taken = float(content.get('cash_taken'))
|
||||||
reconciliation.cash_discrepancy = float(content.get('cash_discrepancy'))
|
reconciliation.cash_discrepancy = float(content.get('cash_discrepancy'))
|
||||||
|
purchases = Sale.objects.filter(pk__in=content.get('purchases'))
|
||||||
|
if reconciliation.total_cash_purchases != sum(p.get_total() for p in purchases):
|
||||||
|
return JsonResponse(
|
||||||
|
{'error': 'total_cash_purchases not equal to sum of all purchases.'},
|
||||||
|
status=400
|
||||||
|
)
|
||||||
reconciliation.clean()
|
reconciliation.clean()
|
||||||
reconciliation.save()
|
reconciliation.save()
|
||||||
|
for purchase in purchases:
|
||||||
|
purchase.reconciliation = reconciliation
|
||||||
|
purchase.clean()
|
||||||
|
purchase.save()
|
||||||
return JsonResponse(
|
return JsonResponse(
|
||||||
{'id': reconciliation.id},
|
{'id': reconciliation.id},
|
||||||
safe=False
|
safe=False
|
||||||
|
Loading…
Reference in New Issue
Block a user