from django.db.models import Model, ForeignKey, CASCADE, PositiveIntegerField, TextField, BooleanField, DateField, SET_NULL, PROTECT, ManyToManyField from core.fields.base import LongCharField from core.fields.numbers import CostField from core.models.profiles import ClientProfile from core.models.local import Currency from core.models.brands import Brand from core.models.billable import BaseBillable from core.models.products import ProductGroup class Invoice(Model): client = ForeignKey(ClientProfile, on_delete=PROTECT) brand = ForeignKey(Brand, on_delete=PROTECT) number = LongCharField() created = DateField() due = DateField() payment_method = LongCharField() currency = ForeignKey(Currency, on_delete=PROTECT) class InvoiceItem(Model): invoice = ForeignKey(Invoice, on_delete=CASCADE) sort = PositiveIntegerField() name = LongCharField() description = TextField(blank=True, null=True) product_groups = ManyToManyField(ProductGroup) price = CostField() discount = CostField() taxable = BooleanField() billable = ForeignKey(BaseBillable, on_delete=SET_NULL, null=True)