Commit 27525363 authored by Łukasz Nowak's avatar Łukasz Nowak

Drop wrong date manipulation.

Add dates safely using DateUtils.
Round up start_date to next midnight.
In case if after rounding this date would go higher then minimum number of day
in month set it to next month beginning date.
parent d86c8931
......@@ -52,7 +52,7 @@
<key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[
from Products.ERP5Type.DateUtils import getNumberOfDayInMonth\n
from Products.ERP5Type.DateUtils import addToDate, getClosestDate\n
from DateTime import DateTime\n
\n
person = context\n
......@@ -87,29 +87,30 @@ for add_kw in add_kw_list:\n
\n
modify_kw_kw = {}\n
for start_date_tuple in start_date_tuple_list:\n
start_date = getClosestDate(target_date=addToDate(start_date_tuple[1], to_add={\'day\': 1}), precision=\'day\')\n
if start_date.day() >= 29:\n
start_date = getClosestDate(target_date=addToDate(start_date, to_add={\'month\': 1}))\n
if start_date_tuple[0] in hosting_subscription_mapping:\n
line_id = hosting_subscription_mapping[start_date_tuple[0]]\n
line = previous_open_sale_order[line_id]\n
if line.getStartDate() != start_date_tuple[1]:\n
if line.getStartDate() != start_date:\n
modify_kw_kw[line.getAggregate(portal_type=\'Hosting Subscription\')] = {\'start_date\': start_date_tuple[1]}\n
elif start_date_tuple[0] in add_kw_kw:\n
add_kw_kw[start_date_tuple[0]][\'start_date\'] = start_date_tuple[1]\n
add_kw_kw[start_date_tuple[0]][\'start_date\'] = start_date\n
\n
next_month = now + getNumberOfDayInMonth(now)\n
if previous_open_sale_order is not None:\n
for line in previous_open_sale_order.contentValues(portal_type=\'Open Sale Order Line\'):\n
old_stop_date = line.getStopDate()\n
if old_stop_date is not None:\n
if stop_date is not None and old_stop_date < stop_date:\n
modify_kw_kw[line.getAggregate(portal_type=\'Hosting Subscription\')][\'stop_date\'] = stop_date\n
else:\n
new_stop_date = old_stop_date + getNumberOfDayInMonth(old_stop_date)\n
elif old_stop_date < now:\n
new_stop_date = addToDate(old_stop_date, to_add={\'month\': 1})\n
while new_stop_date < now:\n
new_stop_date += getNumberOfDayInMonth(new_stop_date)\n
if new_stop_date < next_month and new_stop_date != stop_date:\n
hosting_id = line.getAggregate(portal_type=\'Hosting Subscription\')\n
modify_kw_kw.setdefault(hosting_id, {})\n
modify_kw_kw[line.getAggregate(portal_type=\'Hosting Subscription\')][\'stop_date\'] = new_stop_date\n
new_stop_date = addToDate(new_stop_date, to_add={\'month\': 1})\n
hosting_id = line.getAggregate(portal_type=\'Hosting Subscription\')\n
modify_kw_kw.setdefault(hosting_id, {})\n
modify_kw_kw[line.getAggregate(portal_type=\'Hosting Subscription\')][\'stop_date\'] = new_stop_date\n
\n
for (key, value) in add_kw_kw.copy().iteritems():\n
if stop_date is not None:\n
......@@ -117,11 +118,10 @@ for (key, value) in add_kw_kw.copy().iteritems():\n
else:\n
start_date = add_kw_kw[key].get(\'start_date\')\n
if start_date is not None:\n
new_stop_date = start_date + getNumberOfDayInMonth(start_date)\n
new_stop_date = addToDate(start_date, to_add={\'month\': 1})\n
while new_stop_date < now:\n
new_stop_date += getNumberOfDayInMonth(new_stop_date)\n
if new_stop_date < next_month:\n
add_kw_kw[key][\'stop_date\'] = new_stop_date\n
new_stop_date = addToDate(new_stop_date, to_add={\'month\': 1})\n
add_kw_kw[key][\'stop_date\'] = new_stop_date\n
\n
remove_id_list = set()\n
if previous_open_sale_order is not None:\n
......
648
\ No newline at end of file
649
\ No newline at end of file
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