Commit 70d0b993 authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: use the same hosting subscription periodicity per user

Ensure all invoices for one user will be created at the same date.

Ensure all users do not use the same periodicity, to NOT generated all system invoices on the same date.
parent 566aee5e
......@@ -22,8 +22,12 @@ if hosting_subscription.getPeriodicityHour() is None:
if hosting_subscription.getPeriodicityMinute() is None:
edit_kw['periodicity_minute_list'] = [0]
if hosting_subscription.getPeriodicityMonthDay() is None:
start_date = hosting_subscription.HostingSubscription_calculateSubscriptionStartDate()
start_date = getClosestDate(target_date=start_date, precision='day')
# do not use the same date for every users
# to prevent overload of the server at this date
# Use the person creation date for now, as this document is always accessible
# without relying on portal_catalog / serialize
customer_person = subscription_request.getSourceSectionValue()
start_date = getClosestDate(target_date=customer_person.getCreationDate(), precision='day')
while start_date.day() >= 29:
start_date = addToDate(start_date, to_add={'day': -1})
edit_kw['periodicity_month_day_list'] = [start_date.day()]
......@@ -39,6 +43,8 @@ current_date = getClosestDate(target_date=hosting_subscription.getCreationDate()
next_period_date = hosting_subscription.getNextPeriodicalDate(current_date)
if subscription_request.getQuantityUnit() == 'time/month':
# This start_date calculation ensures the first invoices period
# will be merged in the user monthly invoice
start_date = addToDate(next_period_date, to_add={'month': -1})
assert hosting_subscription.getNextPeriodicalDate(start_date) == next_period_date
else:
......
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