Feat: Se agrega modelo de terceros closed #15
This commit is contained in:
parent
e9e64f58db
commit
19a1ba29d7
@ -1,6 +1,9 @@
|
||||
from django.contrib import admin
|
||||
from .models import Sale, SaleLine, Product, ProductCategory, Payment, ReconciliationJar
|
||||
from .models import (
|
||||
Customer, Sale, SaleLine, Product, ProductCategory, Payment,
|
||||
ReconciliationJar)
|
||||
|
||||
admin.site.register(Customer)
|
||||
admin.site.register(Sale)
|
||||
admin.site.register(SaleLine)
|
||||
admin.site.register(Product)
|
||||
|
@ -7,6 +7,7 @@ from .models import Sale, SaleLine, ReconciliationJar, PaymentMethods
|
||||
|
||||
readonly_number_widget = forms.NumberInput(attrs={'readonly': 'readonly'})
|
||||
|
||||
|
||||
class ImportProductsForm(forms.Form):
|
||||
csv_file = forms.FileField()
|
||||
|
||||
@ -53,6 +54,7 @@ class PurchaseSummaryForm(forms.Form):
|
||||
widget=forms.Select(attrs={'disabled': 'disabled'})
|
||||
)
|
||||
|
||||
|
||||
LineaFormSet = inlineformset_factory(
|
||||
Sale,
|
||||
SaleLine,
|
||||
@ -60,6 +62,7 @@ LineaFormSet = inlineformset_factory(
|
||||
fields='__all__'
|
||||
)
|
||||
|
||||
|
||||
class ReconciliationJarForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = ReconciliationJar
|
||||
|
21
tienda_ilusion/don_confiao/migrations/0025_customer.py
Normal file
21
tienda_ilusion/don_confiao/migrations/0025_customer.py
Normal file
@ -0,0 +1,21 @@
|
||||
# Generated by Django 5.0.7 on 2024-08-03 15:40
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('don_confiao', '0024_alter_product_name'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.CreateModel(
|
||||
name='Customer',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('name', models.CharField(max_length=100)),
|
||||
('address', models.CharField(max_length=100)),
|
||||
],
|
||||
),
|
||||
]
|
@ -0,0 +1,19 @@
|
||||
# Generated by Django 5.0.7 on 2024-08-03 15:55
|
||||
|
||||
import django.db.models.deletion
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('don_confiao', '0025_customer'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='sale',
|
||||
name='customer',
|
||||
field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='don_confiao.customer'),
|
||||
),
|
||||
]
|
@ -5,6 +5,11 @@ from django.core.exceptions import ValidationError
|
||||
from decimal import Decimal
|
||||
|
||||
|
||||
class Customer(models.Model):
|
||||
name = models.CharField(max_length=100)
|
||||
address = models.CharField(max_length=100)
|
||||
|
||||
|
||||
class MeasuringUnits(models.TextChoices):
|
||||
UNIT = 'UNIT', _('Unit')
|
||||
|
||||
@ -31,8 +36,7 @@ class Product(models.Model):
|
||||
|
||||
|
||||
class Sale(models.Model):
|
||||
|
||||
customer = models.CharField(max_length=100)
|
||||
customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
|
||||
date = models.DateField("Date")
|
||||
phone = models.CharField(max_length=13, null=True, blank=True)
|
||||
description = models.CharField(max_length=255, null=True, blank=True)
|
||||
|
14
tienda_ilusion/don_confiao/tests/test_party.py
Normal file
14
tienda_ilusion/don_confiao/tests/test_party.py
Normal file
@ -0,0 +1,14 @@
|
||||
#!/usr/bin/env python3
|
||||
from django.test import TestCase
|
||||
from ..models import Customer
|
||||
|
||||
|
||||
class TestCustomer(TestCase):
|
||||
|
||||
def test_create_customer(self):
|
||||
customer = Customer()
|
||||
customer.name = "Don Confiado Gonzalez"
|
||||
customer.address = "Pueblo Bonito"
|
||||
customer.save()
|
||||
|
||||
self.assertIsInstance(customer, Customer)
|
@ -1,5 +1,5 @@
|
||||
from django.test import TestCase
|
||||
from ..models import Product, Sale, SaleLine
|
||||
from ..models import Customer, Product, Sale, SaleLine
|
||||
|
||||
|
||||
class ConfiaoTest(TestCase):
|
||||
@ -9,9 +9,14 @@ class ConfiaoTest(TestCase):
|
||||
self.product.price = 5000
|
||||
self.product.save()
|
||||
|
||||
self.customer = Customer()
|
||||
self.customer.name = "Don Confiao Gonzalez"
|
||||
self.customer.address = "Patio Bonito"
|
||||
self.customer.save()
|
||||
|
||||
def test_create_sale(self):
|
||||
sale = Sale()
|
||||
sale.customer = "Alejandro"
|
||||
sale.customer = self.customer
|
||||
sale.date = "2024-06-22"
|
||||
sale.phone = '666666666'
|
||||
sale.description = "Description"
|
||||
@ -21,7 +26,7 @@ class ConfiaoTest(TestCase):
|
||||
|
||||
def test_create_sale_line(self):
|
||||
sale = Sale()
|
||||
sale.customer = "Alejandro"
|
||||
sale.customer = self.customer
|
||||
sale.date = "2024-06-22"
|
||||
sale.phone = '666666666'
|
||||
sale.description = "Description"
|
||||
@ -38,7 +43,7 @@ class ConfiaoTest(TestCase):
|
||||
|
||||
def test_create_sale_with_lines(self):
|
||||
sale = Sale()
|
||||
sale.customer = "Alejandro"
|
||||
sale.customer = self.customer
|
||||
sale.date = "2024-06-22"
|
||||
sale.phone = '666666666'
|
||||
sale.description = "Description"
|
||||
@ -69,7 +74,7 @@ class ConfiaoTest(TestCase):
|
||||
|
||||
def test_allow_sale_without_description(self):
|
||||
sale = Sale()
|
||||
sale.customer = "Alejandro"
|
||||
sale.customer = self.customer
|
||||
sale.date = "2024-06-22"
|
||||
sale.phone = '666666666'
|
||||
sale.description = None
|
||||
|
@ -1,33 +1,44 @@
|
||||
#!/usr/bin/env python3
|
||||
from django.test import TestCase
|
||||
from ..forms import PurchaseForm
|
||||
# from ..models import Sale, SaleLine
|
||||
from ..models import Customer
|
||||
|
||||
_csrf_token = \
|
||||
"bVjBevJRavxRPFOlVgAWiyh9ceuiwPlyEcmbPZprNuCGHjFZRKZrBeunJvKTRgOx"
|
||||
|
||||
|
||||
class PurchaseFormTest(TestCase):
|
||||
def setUp(self):
|
||||
self.customer = Customer()
|
||||
self.customer.name = "Don Confiao Gonzalez"
|
||||
self.customer.address = "Patio Bonito"
|
||||
self.customer.save()
|
||||
|
||||
def test_add_purchase(self):
|
||||
form_data = {
|
||||
"csrfmiddlewaretoken": _csrf_token,
|
||||
"customer": "San Judas de Asis",
|
||||
"date": "2024-07-12",
|
||||
"phone": "3010101000",
|
||||
"description": "Esta es una Venta",
|
||||
"customer": self.customer.id,
|
||||
"date": "2024-08-03",
|
||||
"phone": "sfasfd",
|
||||
"description": "dasdadad",
|
||||
"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-product": "5",
|
||||
"saleline_set-0-quantity": "1",
|
||||
"saleline_set-0-unit_price": "22030",
|
||||
"saleline_set-0-description": "Linea de Venta",
|
||||
"saleline_set-0-unit_price": "500",
|
||||
"saleline_set-0-description": "afasdfasdf",
|
||||
"saleline_set-0-sale": "",
|
||||
"saleline_set-0-id": "",
|
||||
"quantity_lines": "1",
|
||||
"quantity_products": "1",
|
||||
"ammount": "500",
|
||||
"form": ""
|
||||
}
|
||||
|
||||
purchase_form = PurchaseForm(data=form_data)
|
||||
purchase_form.is_valid()
|
||||
|
||||
# raise Exception(purchase_form)
|
||||
self.assertTrue(purchase_form.is_valid())
|
||||
|
Loading…
Reference in New Issue
Block a user