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