From 204bdbcb33b29e2f4b8b49fc667b7346d1bc8b29 Mon Sep 17 00:00:00 2001 From: Mono Mono Date: Sat, 17 Aug 2024 12:51:38 -0500 Subject: [PATCH] limit to CASH methods type in purchases. --- tienda_ilusion/don_confiao/forms.py | 3 +- .../tests/test_purchase_with_payment.py | 68 +++++++++++-------- 2 files changed, 40 insertions(+), 31 deletions(-) diff --git a/tienda_ilusion/don_confiao/forms.py b/tienda_ilusion/don_confiao/forms.py index 0e877ea..0142b04 100644 --- a/tienda_ilusion/don_confiao/forms.py +++ b/tienda_ilusion/don_confiao/forms.py @@ -50,8 +50,7 @@ class PurchaseSummaryForm(forms.Form): widget=readonly_number_widget ) payment_method = forms.ChoiceField( - choices=PaymentMethods.choices, - widget=forms.Select(attrs={'disabled': 'disabled'}) + choices=[(PaymentMethods.CASH, PaymentMethods.CASH)], ) diff --git a/tienda_ilusion/don_confiao/tests/test_purchase_with_payment.py b/tienda_ilusion/don_confiao/tests/test_purchase_with_payment.py index a27904c..bee9de2 100644 --- a/tienda_ilusion/don_confiao/tests/test_purchase_with_payment.py +++ b/tienda_ilusion/don_confiao/tests/test_purchase_with_payment.py @@ -1,37 +1,47 @@ from django.test import Client, TestCase -from ..models import Payment, Sale +from ..models import Payment, Sale, Product, Customer class TestPurchaseWithPayment(TestCase): def setUp(self): self.client = Client() + self.product = Product() + self.product.name = "Arroz" + self.product.price = 5000 + self.product.save() + customer = Customer() + customer.name = "Noelba Lopez" + customer.save() + self.customer = customer - # def test_generate_payment_when_it_has_payment(self): - # quantity = 2 - # unit_price = 2500 - # total = 5000 - # response = self.client.post( - # '/don_confiao/comprar', - # { - # "customer": "Noelba Lopez", - # "date": "2024-07-27", - # "phone": "3010101000", - # "description": "Venta de contado", - # "saleline_set-TOTAL_FORMS": "1", - # "saleline_set-INITIAL_FORMS": "0", - # "saleline_set-MIN_NUM_FORMS": "0", - # "saleline_set-MAX_NUM_FORMS": "1000", - # "saleline_set-0-product": "Papayita", - # "saleline_set-0-quantity": str(quantity), - # "saleline_set-0-unit_price": str(unit_price), - # "saleline_set-0-description": "Linea de Venta", - # "saleline_set-0-sale": "", - # "saleline_set-0-id": "", - # } - # ) - # purchases = Sale.objects.all() - # self.assertEqual(1, len(purchases)) - # payments = Payment.objects.all() - # self.assertEqual(1, len(payments)) - # self.assertEqual(total, payments[0].ammount) + def test_generate_payment_when_it_has_payment(self): + quantity = 2 + unit_price = 2500 + total = 5000 + response = self.client.post( + '/don_confiao/comprar', + { + "customer": str(self.customer.id), + "date": "2024-07-27", + "phone": "3010101000", + "description": "Venta de contado", + "saleline_set-TOTAL_FORMS": "1", + "saleline_set-INITIAL_FORMS": "0", + "saleline_set-MIN_NUM_FORMS": "0", + "saleline_set-MAX_NUM_FORMS": "1000", + "saleline_set-0-product": str(self.product.id), + "saleline_set-0-quantity": str(quantity), + "saleline_set-0-unit_price": str(unit_price), + "saleline_set-0-description": "Linea de Venta", + "saleline_set-0-sale": "", + "saleline_set-0-id": "", + "quantity_lines": "1", + "quantity_products": str(quantity), + "ammount": str(quantity * unit_price), + "payment_method": "CASH", + } + ) + purchases = Sale.objects.all() + self.assertEqual(1, len(purchases)) + payments = Payment.objects.all()