Commit 0202f80a authored by Nico Schottelius's avatar Nico Schottelius

in between pay commit

parent caedf874
Pipeline #1532 failed with stage
in 43 seconds
......@@ -31,14 +31,17 @@ logger = logging.getLogger(__name__)
# See
class RecurringPeriod(models.TextChoices):
ONE_TIME = 'ONCE', _('Onetime')
PER_YEAR = 'YEAR', _('Per Year')
PER_MONTH = 'MONTH', _('Per Month')
PER_WEEK = 'WEEK', _('Per Week')
PER_DAY = 'DAY', _('Per Day')
PER_HOUR = 'HOUR', _('Per Hour')
PER_MINUTE = 'MINUTE', _('Per Minute')
PER_SECOND = 'SECOND', _('Per Second')
PER_YEAR = 'YEAR', _('Per Year') # this is broken - we can make it 365 days
PER_MONTH = 'MONTH', _('Per Month') # this is broken - varying times
ONE_TIME = 'ONCE', _('Onetime') # this is ok
PER_365D = '365D', _('Per 365 days') # this is ok
PER_30D = '30D', _('Per 30 days') # this is ok
PER_WEEK = 'WEEK', _('Per Week') # this is ok
PER_DAY = 'DAY', _('Per Day') # this is ok
PER_HOUR = 'HOUR', _('Per Hour') # this is ok
PER_MINUTE = 'MINUTE', _('Per Minute') # this is ok
PER_SECOND = 'SECOND', _('Per Second') # this is ok
class CountryField(models.CharField):
def __init__(self, *args, **kwargs):
......@@ -245,6 +248,10 @@ class VATRate(models.Model):
return 0
class BillNico(models.Model):
""" FIXME:
Bill needs to be unique in the triple (owner, year, month)
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(),
......@@ -256,6 +263,54 @@ class BillNico(models.Model):
valid = models.BooleanField(default=True)
def create_all_bills():
for owner in get_user_model().objects.all():
# mintime = time of first order
# maxtime = time of last order
# iterate month based through it
def assign_orders_to_bill(self, owner, year, month):
Generate a bill for the specific month of a user.
First handle all one time orders
Find all one time orders that have a starting date that falls into this month
Can we do this even for recurring / all of them
for order in Order.objects.filter(owner=owner,
Find all recurring orders that did not start in this time frame, but need
to be billed in this time frame.
This is:
- order starting time before our starting time
- order start time + (x * (the_period)) is inside our time frame, x must be integer
test cases:
+ 365days:
time_since_last_billed = self.starting_or_ending_date - order.last_bill_date
periods =
[ we could in theory add this as a property to the order: next
for order in Order.objects.filter(owner=owner,
class Bill(models.Model):
uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False)
owner = models.ForeignKey(get_user_model(),
......@@ -488,7 +543,7 @@ class BillRecord():
def __init__(self, bill, order):
self.bill = bill
self.order = order
self.recurring_price = order.recurring_price
yep self.recurring_price = order.recurring_price
self.recurring_period = order.recurring_period
self.description = order.description
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment