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 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(Sale)
|
||||||
admin.site.register(SaleLine)
|
admin.site.register(SaleLine)
|
||||||
admin.site.register(Product)
|
admin.site.register(Product)
|
||||||
|
@ -7,6 +7,7 @@ from .models import Sale, SaleLine, ReconciliationJar, PaymentMethods
|
|||||||
|
|
||||||
readonly_number_widget = forms.NumberInput(attrs={'readonly': 'readonly'})
|
readonly_number_widget = forms.NumberInput(attrs={'readonly': 'readonly'})
|
||||||
|
|
||||||
|
|
||||||
class ImportProductsForm(forms.Form):
|
class ImportProductsForm(forms.Form):
|
||||||
csv_file = forms.FileField()
|
csv_file = forms.FileField()
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ class PurchaseSummaryForm(forms.Form):
|
|||||||
widget=forms.Select(attrs={'disabled': 'disabled'})
|
widget=forms.Select(attrs={'disabled': 'disabled'})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
LineaFormSet = inlineformset_factory(
|
LineaFormSet = inlineformset_factory(
|
||||||
Sale,
|
Sale,
|
||||||
SaleLine,
|
SaleLine,
|
||||||
@ -60,6 +62,7 @@ LineaFormSet = inlineformset_factory(
|
|||||||
fields='__all__'
|
fields='__all__'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
class ReconciliationJarForm(forms.ModelForm):
|
class ReconciliationJarForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = ReconciliationJar
|
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
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|
||||||
|
class Customer(models.Model):
|
||||||
|
name = models.CharField(max_length=100)
|
||||||
|
address = models.CharField(max_length=100)
|
||||||
|
|
||||||
|
|
||||||
class MeasuringUnits(models.TextChoices):
|
class MeasuringUnits(models.TextChoices):
|
||||||
UNIT = 'UNIT', _('Unit')
|
UNIT = 'UNIT', _('Unit')
|
||||||
|
|
||||||
@ -31,8 +36,7 @@ class Product(models.Model):
|
|||||||
|
|
||||||
|
|
||||||
class Sale(models.Model):
|
class Sale(models.Model):
|
||||||
|
customer = models.ForeignKey(Customer, on_delete=models.PROTECT)
|
||||||
customer = models.CharField(max_length=100)
|
|
||||||
date = models.DateField("Date")
|
date = models.DateField("Date")
|
||||||
phone = models.CharField(max_length=13, null=True, blank=True)
|
phone = models.CharField(max_length=13, null=True, blank=True)
|
||||||
description = models.CharField(max_length=255, 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 django.test import TestCase
|
||||||
from ..models import Product, Sale, SaleLine
|
from ..models import Customer, Product, Sale, SaleLine
|
||||||
|
|
||||||
|
|
||||||
class ConfiaoTest(TestCase):
|
class ConfiaoTest(TestCase):
|
||||||
@ -9,9 +9,14 @@ class ConfiaoTest(TestCase):
|
|||||||
self.product.price = 5000
|
self.product.price = 5000
|
||||||
self.product.save()
|
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):
|
def test_create_sale(self):
|
||||||
sale = Sale()
|
sale = Sale()
|
||||||
sale.customer = "Alejandro"
|
sale.customer = self.customer
|
||||||
sale.date = "2024-06-22"
|
sale.date = "2024-06-22"
|
||||||
sale.phone = '666666666'
|
sale.phone = '666666666'
|
||||||
sale.description = "Description"
|
sale.description = "Description"
|
||||||
@ -21,7 +26,7 @@ class ConfiaoTest(TestCase):
|
|||||||
|
|
||||||
def test_create_sale_line(self):
|
def test_create_sale_line(self):
|
||||||
sale = Sale()
|
sale = Sale()
|
||||||
sale.customer = "Alejandro"
|
sale.customer = self.customer
|
||||||
sale.date = "2024-06-22"
|
sale.date = "2024-06-22"
|
||||||
sale.phone = '666666666'
|
sale.phone = '666666666'
|
||||||
sale.description = "Description"
|
sale.description = "Description"
|
||||||
@ -38,7 +43,7 @@ class ConfiaoTest(TestCase):
|
|||||||
|
|
||||||
def test_create_sale_with_lines(self):
|
def test_create_sale_with_lines(self):
|
||||||
sale = Sale()
|
sale = Sale()
|
||||||
sale.customer = "Alejandro"
|
sale.customer = self.customer
|
||||||
sale.date = "2024-06-22"
|
sale.date = "2024-06-22"
|
||||||
sale.phone = '666666666'
|
sale.phone = '666666666'
|
||||||
sale.description = "Description"
|
sale.description = "Description"
|
||||||
@ -69,7 +74,7 @@ class ConfiaoTest(TestCase):
|
|||||||
|
|
||||||
def test_allow_sale_without_description(self):
|
def test_allow_sale_without_description(self):
|
||||||
sale = Sale()
|
sale = Sale()
|
||||||
sale.customer = "Alejandro"
|
sale.customer = self.customer
|
||||||
sale.date = "2024-06-22"
|
sale.date = "2024-06-22"
|
||||||
sale.phone = '666666666'
|
sale.phone = '666666666'
|
||||||
sale.description = None
|
sale.description = None
|
||||||
|
@ -1,33 +1,44 @@
|
|||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from ..forms import PurchaseForm
|
from ..forms import PurchaseForm
|
||||||
# from ..models import Sale, SaleLine
|
from ..models import Customer
|
||||||
|
|
||||||
_csrf_token = \
|
_csrf_token = \
|
||||||
"bVjBevJRavxRPFOlVgAWiyh9ceuiwPlyEcmbPZprNuCGHjFZRKZrBeunJvKTRgOx"
|
"bVjBevJRavxRPFOlVgAWiyh9ceuiwPlyEcmbPZprNuCGHjFZRKZrBeunJvKTRgOx"
|
||||||
|
|
||||||
|
|
||||||
class PurchaseFormTest(TestCase):
|
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):
|
def test_add_purchase(self):
|
||||||
form_data = {
|
form_data = {
|
||||||
"csrfmiddlewaretoken": _csrf_token,
|
"csrfmiddlewaretoken": _csrf_token,
|
||||||
"customer": "San Judas de Asis",
|
"customer": self.customer.id,
|
||||||
"date": "2024-07-12",
|
"date": "2024-08-03",
|
||||||
"phone": "3010101000",
|
"phone": "sfasfd",
|
||||||
"description": "Esta es una Venta",
|
"description": "dasdadad",
|
||||||
"saleline_set-TOTAL_FORMS": "1",
|
"saleline_set-TOTAL_FORMS": "1",
|
||||||
"saleline_set-INITIAL_FORMS": "0",
|
"saleline_set-INITIAL_FORMS": "0",
|
||||||
"saleline_set-MIN_NUM_FORMS": "0",
|
"saleline_set-MIN_NUM_FORMS": "0",
|
||||||
"saleline_set-MAX_NUM_FORMS": "1000",
|
"saleline_set-MAX_NUM_FORMS": "1000",
|
||||||
"saleline_set-0-product": "Papayita",
|
"saleline_set-0-product": "5",
|
||||||
"saleline_set-0-quantity": "1",
|
"saleline_set-0-quantity": "1",
|
||||||
"saleline_set-0-unit_price": "22030",
|
"saleline_set-0-unit_price": "500",
|
||||||
"saleline_set-0-description": "Linea de Venta",
|
"saleline_set-0-description": "afasdfasdf",
|
||||||
"saleline_set-0-sale": "",
|
"saleline_set-0-sale": "",
|
||||||
"saleline_set-0-id": "",
|
"saleline_set-0-id": "",
|
||||||
|
"quantity_lines": "1",
|
||||||
|
"quantity_products": "1",
|
||||||
|
"ammount": "500",
|
||||||
"form": ""
|
"form": ""
|
||||||
}
|
}
|
||||||
|
|
||||||
purchase_form = PurchaseForm(data=form_data)
|
purchase_form = PurchaseForm(data=form_data)
|
||||||
|
purchase_form.is_valid()
|
||||||
|
|
||||||
|
# raise Exception(purchase_form)
|
||||||
self.assertTrue(purchase_form.is_valid())
|
self.assertTrue(purchase_form.is_valid())
|
||||||
|
Loading…
Reference in New Issue
Block a user