Merge pull request 'make customer name required field #17' (#19) from make_customer_name_required_#17 into main

Reviewed-on: OneTeam/don_confiao#19
This commit is contained in:
mono 2024-08-17 10:30:30 -05:00
commit efad80970b
3 changed files with 31 additions and 3 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 5.0.6 on 2024-08-17 14:22
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('don_confiao', '0027_alter_product_name'),
]
operations = [
migrations.AlterField(
model_name='customer',
name='address',
field=models.CharField(blank=True, max_length=100, null=True),
),
]

View File

@ -6,8 +6,11 @@ from decimal import Decimal
class Customer(models.Model):
name = models.CharField(max_length=100)
address = models.CharField(max_length=100)
name = models.CharField(max_length=100, default=None, null=False, blank=False)
address = models.CharField(max_length=100, null=True, blank=True)
def __str__(self):
return self.name
class MeasuringUnits(models.TextChoices):
@ -53,7 +56,7 @@ class Sale(models.Model):
class SaleLine(models.Model):
sale = models.ForeignKey(Sale, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
product = models.ForeignKey(Product, null=False, blank=False, on_delete=models.CASCADE)
quantity = models.IntegerField(null=True)
unit_price = models.DecimalField(max_digits=9, decimal_places=2)
description = models.CharField(max_length=255, null=True, blank=True)

View File

@ -1,5 +1,7 @@
#!/usr/bin/env python3
from django.test import TestCase
from django.db.utils import IntegrityError
from ..models import Customer
@ -12,3 +14,8 @@ class TestCustomer(TestCase):
customer.save()
self.assertIsInstance(customer, Customer)
def test_don_create_customer_without_name(self):
customer = Customer()
with self.assertRaises(IntegrityError):
customer.save()