diff --git a/core/models/billable.py b/core/models/billable.py index 2f7009f..8c30e19 100644 --- a/core/models/billable.py +++ b/core/models/billable.py @@ -5,7 +5,6 @@ from core.models.profiles import ClientProfile from core.models.brands import Brand from core.fields.base import LongCharField from core.fields.numbers import CostField -from core.models.invoices import InvoiceItem, Invoice from dateutil.relativedelta import relativedelta @@ -38,6 +37,8 @@ class Billable(Model): recur_count = PositiveIntegerField(null=True) def next_invoicing(self): + from core.models.invoices import InvoiceItem, Invoice + try: invoiceitems = InvoiceItem.objects.filter(billable=self) diff --git a/core/models/invoices.py b/core/models/invoices.py index 563dc9f..0fd46b7 100644 --- a/core/models/invoices.py +++ b/core/models/invoices.py @@ -2,13 +2,13 @@ from django.db.models import Model, ForeignKey, CASCADE, PositiveIntegerField, T from core.fields.base import LongCharField from core.fields.numbers import CostField -from core.models.services import Service from core.models.profiles import ClientProfile from core.models.local import Currency -from core.models.billable import Billable +from core.models.brands import Brand class Invoice(Model): - client = ForeignKey(ClientProfile, on_delete=CASCADE) + client = ForeignKey(ClientProfile, on_delete=PROTECT) + brand = ForeignKey(Brand, on_delete=PROTECT) number = LongCharField() created = DateField() due = DateField() @@ -16,6 +16,9 @@ class Invoice(Model): currency = ForeignKey(Currency, on_delete=PROTECT) class InvoiceItem(Model): + from core.models.services import Service + from core.models.billable import Billable + invoice = ForeignKey(Invoice, on_delete=CASCADE) sort = PositiveIntegerField() name = LongCharField() diff --git a/core/models/products.py b/core/models/products.py index bab7de0..1515c1e 100644 --- a/core/models/products.py +++ b/core/models/products.py @@ -1,9 +1,8 @@ -from core.models.billable import CycleChoices from core.fields.base import LongCharField from core.fields.color import ColorField from core.fields.numbers import CostField -from django.db.models import Model, IntegerChoices, PositiveIntegerField, ForeignKey, CASCADE, CharField, TextField, ManyToManyField +from django.db.models import Model, PositiveIntegerField, ForeignKey, CASCADE, CharField, TextField, ManyToManyField from importlib import import_module @@ -34,7 +33,9 @@ class Product(Model): class ProductPlan(Model): product = ForeignKey(Product, on_delete=CASCADE) -class ProductPlanItem(Model): +class ProductPlanItem(Model): + from core.models.billable import CycleChoices + plan = ForeignKey(ProductPlan, on_delete=CASCADE) cycle = PositiveIntegerField(choices=CycleChoices.choices) count = PositiveIntegerField() diff --git a/core/models/services.py b/core/models/services.py index 6f8378d..02b35ed 100644 --- a/core/models/services.py +++ b/core/models/services.py @@ -1,5 +1,3 @@ -from core.models.billable import CycleChoices -from core.models.products import ProductGroup from core.fields.numbers import CostField from django.db.models import Model, TextField, CharField, ManyToManyField, ForeignKey, CASCADE, PositiveIntegerField, OneToOneField @@ -10,6 +8,8 @@ from logging import getLogger logger = getLogger(__name__) class Service(Model): + from core.models.products import ProductGroup + name = CharField(max_length=255) description = TextField(null=True, blank=True) handler_module = CharField(max_length=255, null=True, blank=True) @@ -35,7 +35,9 @@ class ServicePlan(Model): for item in productplan.serviceplanitem_set: ServicePlanItem.objects.create(plan=plan, cycle=item.cycle, count=item.count, cost=item.cost) -class ServicePlanItem(Model): +class ServicePlanItem(Model): + from core.models.billable import CycleChoices + plan = ForeignKey(ServicePlan, on_delete=CASCADE) cycle = PositiveIntegerField(choices=CycleChoices.choices) count = PositiveIntegerField()