Fix: Campo product a Many2One
This commit is contained in:
parent
6f4ac50a58
commit
e9e64f58db
@ -0,0 +1,19 @@
|
|||||||
|
# Generated by Django 5.0.7 on 2024-08-03 15:01
|
||||||
|
|
||||||
|
import django.db.models.deletion
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('don_confiao', '0001_initial'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='saleline',
|
||||||
|
name='product',
|
||||||
|
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='don_confiao.product'),
|
||||||
|
),
|
||||||
|
]
|
@ -0,0 +1,14 @@
|
|||||||
|
# Generated by Django 5.0.7 on 2024-08-03 15:04
|
||||||
|
|
||||||
|
from django.db import migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('don_confiao', '0002_alter_saleline_product'),
|
||||||
|
('don_confiao', '0022_alter_payment_reconciliation_jar'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
]
|
@ -0,0 +1,18 @@
|
|||||||
|
# Generated by Django 5.0.7 on 2024-08-03 15:14
|
||||||
|
|
||||||
|
from django.db import migrations, models
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('don_confiao', '0023_merge_20240803_1504'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='product',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(max_length=100),
|
||||||
|
),
|
||||||
|
]
|
@ -5,6 +5,30 @@ from django.core.exceptions import ValidationError
|
|||||||
from decimal import Decimal
|
from decimal import Decimal
|
||||||
|
|
||||||
|
|
||||||
|
class MeasuringUnits(models.TextChoices):
|
||||||
|
UNIT = 'UNIT', _('Unit')
|
||||||
|
|
||||||
|
|
||||||
|
class ProductCategory(models.Model):
|
||||||
|
name = models.CharField(max_length=100, unique=True)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
|
class Product(models.Model):
|
||||||
|
name = models.CharField(max_length=100, unique=False)
|
||||||
|
price = models.DecimalField(max_digits=9, decimal_places=2)
|
||||||
|
measuring_unit = models.CharField(
|
||||||
|
max_length=20,
|
||||||
|
choices=MeasuringUnits.choices,
|
||||||
|
default=MeasuringUnits.UNIT
|
||||||
|
)
|
||||||
|
categories = models.ManyToManyField(ProductCategory)
|
||||||
|
|
||||||
|
def __str__(self):
|
||||||
|
return self.name
|
||||||
|
|
||||||
|
|
||||||
class Sale(models.Model):
|
class Sale(models.Model):
|
||||||
|
|
||||||
@ -20,7 +44,7 @@ class Sale(models.Model):
|
|||||||
class SaleLine(models.Model):
|
class SaleLine(models.Model):
|
||||||
|
|
||||||
sale = models.ForeignKey(Sale, on_delete=models.CASCADE)
|
sale = models.ForeignKey(Sale, on_delete=models.CASCADE)
|
||||||
product = models.CharField(max_length=100)
|
product = models.ForeignKey(Product, on_delete=models.CASCADE)
|
||||||
quantity = models.IntegerField(null=True)
|
quantity = models.IntegerField(null=True)
|
||||||
unit_price = models.DecimalField(max_digits=9, decimal_places=2)
|
unit_price = models.DecimalField(max_digits=9, decimal_places=2)
|
||||||
description = models.CharField(max_length=255, null=True, blank=True)
|
description = models.CharField(max_length=255, null=True, blank=True)
|
||||||
@ -29,31 +53,6 @@ class SaleLine(models.Model):
|
|||||||
return f"{self.sale} - {self.product}"
|
return f"{self.sale} - {self.product}"
|
||||||
|
|
||||||
|
|
||||||
class MeasuringUnits(models.TextChoices):
|
|
||||||
UNIT = 'UNIT', _('Unit')
|
|
||||||
|
|
||||||
|
|
||||||
class ProductCategory(models.Model):
|
|
||||||
name = models.CharField(max_length=100, unique=True)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
|
|
||||||
class Product(models.Model):
|
|
||||||
name = models.CharField(max_length=100, unique=True)
|
|
||||||
price = models.DecimalField(max_digits=9, decimal_places=2)
|
|
||||||
measuring_unit = models.CharField(
|
|
||||||
max_length=20,
|
|
||||||
choices=MeasuringUnits.choices,
|
|
||||||
default=MeasuringUnits.UNIT
|
|
||||||
)
|
|
||||||
categories = models.ManyToManyField(ProductCategory)
|
|
||||||
|
|
||||||
def __str__(self):
|
|
||||||
return self.name
|
|
||||||
|
|
||||||
|
|
||||||
class PaymentMethods(models.TextChoices):
|
class PaymentMethods(models.TextChoices):
|
||||||
CASH = 'CASH', _('Cash')
|
CASH = 'CASH', _('Cash')
|
||||||
CONFIAR = 'CONFIAR', _('Confiar')
|
CONFIAR = 'CONFIAR', _('Confiar')
|
||||||
@ -108,6 +107,7 @@ class ReconciliationJar(models.Model):
|
|||||||
self.payment_set.add(payment)
|
self.payment_set.add(payment)
|
||||||
self.is_valid = True
|
self.is_valid = True
|
||||||
|
|
||||||
|
|
||||||
class Payment(models.Model):
|
class Payment(models.Model):
|
||||||
date_time = models.DateTimeField()
|
date_time = models.DateTimeField()
|
||||||
type_payment = models.CharField(
|
type_payment = models.CharField(
|
||||||
|
@ -2,6 +2,7 @@ from django.test import Client, TestCase
|
|||||||
|
|
||||||
from ..models import Payment, Sale
|
from ..models import Payment, Sale
|
||||||
|
|
||||||
|
|
||||||
class TestPurchaseWithPayment(TestCase):
|
class TestPurchaseWithPayment(TestCase):
|
||||||
def setUp(self):
|
def setUp(self):
|
||||||
self.client = Client()
|
self.client = Client()
|
||||||
|
@ -1,8 +1,13 @@
|
|||||||
from django.test import TestCase
|
from django.test import TestCase
|
||||||
from ..models import Sale, SaleLine
|
from ..models import Product, Sale, SaleLine
|
||||||
|
|
||||||
|
|
||||||
class ConfiaoTest(TestCase):
|
class ConfiaoTest(TestCase):
|
||||||
|
def setUp(self):
|
||||||
|
self.product = Product()
|
||||||
|
self.product.name = "Pepino"
|
||||||
|
self.product.price = 5000
|
||||||
|
self.product.save()
|
||||||
|
|
||||||
def test_create_sale(self):
|
def test_create_sale(self):
|
||||||
sale = Sale()
|
sale = Sale()
|
||||||
@ -23,7 +28,7 @@ class ConfiaoTest(TestCase):
|
|||||||
|
|
||||||
line = SaleLine()
|
line = SaleLine()
|
||||||
line.sale = sale
|
line.sale = sale
|
||||||
line.product = 'papaya'
|
line.product = self.product
|
||||||
line.quantity = 2
|
line.quantity = 2
|
||||||
line.unit_price = 2500
|
line.unit_price = 2500
|
||||||
line.amount = 5000
|
line.amount = 5000
|
||||||
@ -40,14 +45,14 @@ class ConfiaoTest(TestCase):
|
|||||||
|
|
||||||
line1 = SaleLine()
|
line1 = SaleLine()
|
||||||
line1.sale = sale
|
line1.sale = sale
|
||||||
line1.product = 'papaya'
|
line1.product = self.product
|
||||||
line1.quantity = 2
|
line1.quantity = 2
|
||||||
line1.unit_price = 2500
|
line1.unit_price = 2500
|
||||||
line1.amount = 5000
|
line1.amount = 5000
|
||||||
|
|
||||||
line2 = SaleLine()
|
line2 = SaleLine()
|
||||||
line2.sale = sale
|
line2.sale = sale
|
||||||
line2.product = 'papaya'
|
line2.product = self.product
|
||||||
line2.quantity = 2
|
line2.quantity = 2
|
||||||
line2.unit_price = 2500
|
line2.unit_price = 2500
|
||||||
line2.amount = 5000
|
line2.amount = 5000
|
||||||
|
Loading…
Reference in New Issue
Block a user