fix syntax errors

This commit is contained in:
Nico Schottelius 2020-05-23 23:08:59 +02:00
parent b8652c921e
commit 18b862c2e1

View file

@ -31,8 +31,8 @@ logger = logging.getLogger(__name__)
# See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types # See https://docs.djangoproject.com/en/dev/ref/models/fields/#field-choices-enum-types
class RecurringPeriod(models.TextChoices): class RecurringPeriod(models.TextChoices):
PER_YEAR = 'YEAR', _('Per Year') # this is broken - we can make it 365 days PER_YEAR = 'YEAR', _('Per Year') # this is broken - we can make it 365 days - REMOVE ME
PER_MONTH = 'MONTH', _('Per Month') # this is broken - varying times PER_MONTH = 'MONTH', _('Per Month') # this is broken - varying times - REMOVE ME
ONE_TIME = 'ONCE', _('Onetime') # this is ok ONE_TIME = 'ONCE', _('Onetime') # this is ok
PER_365D = '365D', _('Per 365 days') # this is ok PER_365D = '365D', _('Per 365 days') # this is ok
@ -43,6 +43,8 @@ class RecurringPeriod(models.TextChoices):
PER_MINUTE = 'MINUTE', _('Per Minute') # this is ok PER_MINUTE = 'MINUTE', _('Per Minute') # this is ok
PER_SECOND = 'SECOND', _('Per Second') # this is ok PER_SECOND = 'SECOND', _('Per Second') # this is ok
class CountryField(models.CharField): class CountryField(models.CharField):
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
kwargs.setdefault('choices', COUNTRIES) kwargs.setdefault('choices', COUNTRIES)
@ -111,6 +113,7 @@ class Payment(models.Model):
for bill in newly_paid_bills: for bill in newly_paid_bills:
bill.activate_products() bill.activate_products()
class PaymentMethod(models.Model): class PaymentMethod(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(), owner = models.ForeignKey(get_user_model(),
@ -276,6 +279,10 @@ class BillNico(models.Model):
Generate a bill for the specific month of a user. Generate a bill for the specific month of a user.
First handle all one time orders First handle all one time orders
FIXME:
- limit this to active users in the future! (2020-05-23)
""" """
""" """
@ -285,10 +292,12 @@ class BillNico(models.Model):
Can we do this even for recurring / all of them Can we do this even for recurring / all of them
""" """
for order in Order.objects.filter(owner=owner, for order in Order.objects.filter(Q(starting_date__gte=self.starting_date),
Q(starting_date__gte=self.starting_date), Q(starting_date__lte=self.ending_date),
Q(starting_date__lte=self.ending_date)): owner=owner):
order.bill.add(this_bill)
# order.bill.add(this_bill)
pass
""" """
@ -304,10 +313,11 @@ class BillNico(models.Model):
periods = periods =
[ we could in theory add this as a property to the order: next [ we could in theory add this as a property to the order: next
""" """
for order in Order.objects.filter(owner=owner, for order in Order.objects.filter(~Q(recurring_period=RecurringPeriod.ONE_TIME),
~Q(recurring_period=RecurringPeriod.ONE_TIME), Q(starting_date__lt=self.starting_date),
Q(starting_date__gte=starting_date), owner=owner):
Q(starting_date__lte=ending_date)): pass
@ -543,7 +553,7 @@ class BillRecord():
def __init__(self, bill, order): def __init__(self, bill, order):
self.bill = bill self.bill = bill
self.order = order self.order = order
yep self.recurring_price = order.recurring_price self.recurring_price = order.recurring_price
self.recurring_period = order.recurring_period self.recurring_period = order.recurring_period
self.description = order.description self.description = order.description
@ -683,6 +693,7 @@ class Order(models.Model):
if self.starting_date <= ending_date: if self.starting_date <= ending_date:
if self.ending_date: if self.ending_date:
if self.ending_date > ending_date: if self.ending_date > ending_date:
pass
@property @property
def is_recurring(self): def is_recurring(self):
@ -700,6 +711,10 @@ class Order(models.Model):
self.ending_date = timezone.now() self.ending_date = timezone.now()
self.save() self.save()
def is_to_be_charged_in(year, month):
if self.recurring_period == RecurringPeriod.PER_YEAR:
pass
# Trigger initial bill generation at order creation. # Trigger initial bill generation at order creation.
def save(self, *args, **kwargs): def save(self, *args, **kwargs):
if self.ending_date and self.ending_date < self.starting_date: if self.ending_date and self.ending_date < self.starting_date: