Fix RecurMixin
This commit is contained in:
parent
4dc0b86378
commit
50ccd9f0a5
2 changed files with 8 additions and 4 deletions
|
@ -1,5 +1,7 @@
|
||||||
from django.db.models import PositiveIntegerField, DateField, IntegerChoices, Model
|
from django.db.models import PositiveIntegerField, DateField, IntegerChoices, Model
|
||||||
|
|
||||||
|
from dateutil.relativedelta import relativedelta
|
||||||
|
|
||||||
class ActionChoices(IntegerChoices):
|
class ActionChoices(IntegerChoices):
|
||||||
WAIT = 0, "Do not invoice for now"
|
WAIT = 0, "Do not invoice for now"
|
||||||
NEXT = 1, "Add to client's next invoice"
|
NEXT = 1, "Add to client's next invoice"
|
||||||
|
@ -25,11 +27,15 @@ class RecurMixin(Model):
|
||||||
def next_invoicing(self):
|
def next_invoicing(self):
|
||||||
from core.models.invoices import InvoiceItem, Invoice
|
from core.models.invoices import InvoiceItem, Invoice
|
||||||
|
|
||||||
if not self.recur_action == ActionChoices.DATE:
|
if not (self.recur_action == ActionChoices.DATE) or self.recur_cycle:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
invoiceitems = InvoiceItem.objects.filter(billable=self)
|
invoiceitems = InvoiceItem.objects.filter(billable=self)
|
||||||
|
|
||||||
|
if invoiceitems and not self.recur_cycle:
|
||||||
|
return False
|
||||||
|
|
||||||
invoice = Invoice.objects.filter(invoiceitem_set__contains=invoiceitems).latest("created")
|
invoice = Invoice.objects.filter(invoiceitem_set__contains=invoiceitems).latest("created")
|
||||||
delta = relativedelta(days=self.recur_count if self.recur_cycle == CycleChoices.DAYS else 0,
|
delta = relativedelta(days=self.recur_count if self.recur_cycle == CycleChoices.DAYS else 0,
|
||||||
weeks=self.recur_count if self.recur_cycle == CycleChoices.WEEKS else 0,
|
weeks=self.recur_count if self.recur_cycle == CycleChoices.WEEKS else 0,
|
||||||
|
@ -37,6 +43,5 @@ class RecurMixin(Model):
|
||||||
years=self.recur_count if self.recur_cycle == CycleChoices.YEARS else 0)
|
years=self.recur_count if self.recur_cycle == CycleChoices.YEARS else 0)
|
||||||
|
|
||||||
return invoice.created + delta
|
return invoice.created + delta
|
||||||
|
except InvoiceItem.DoesNotExist:
|
||||||
except:
|
|
||||||
return self.date
|
return self.date
|
|
@ -8,7 +8,6 @@ from core.fields.numbers import CostField
|
||||||
from core.models.local import Currency
|
from core.models.local import Currency
|
||||||
from core.mixins.billable import RecurMixin
|
from core.mixins.billable import RecurMixin
|
||||||
|
|
||||||
from dateutil.relativedelta import relativedelta
|
|
||||||
from polymorphic.models import PolymorphicModel
|
from polymorphic.models import PolymorphicModel
|
||||||
|
|
||||||
class BaseBillable(PolymorphicModel):
|
class BaseBillable(PolymorphicModel):
|
||||||
|
|
Loading…
Reference in a new issue