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 @@ ...@@ -52,7 +52,7 @@
<key> <string>_body</string> </key> <key> <string>_body</string> </key>
<value> <string encoding="cdata"><![CDATA[ <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 from DateTime import DateTime\n
\n \n
person = context\n person = context\n
...@@ -87,26 +87,27 @@ for add_kw in add_kw_list:\n ...@@ -87,26 +87,27 @@ for add_kw in add_kw_list:\n
\n \n
modify_kw_kw = {}\n modify_kw_kw = {}\n
for start_date_tuple in start_date_tuple_list:\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 if start_date_tuple[0] in hosting_subscription_mapping:\n
line_id = hosting_subscription_mapping[start_date_tuple[0]]\n line_id = hosting_subscription_mapping[start_date_tuple[0]]\n
line = previous_open_sale_order[line_id]\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 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 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 \n
next_month = now + getNumberOfDayInMonth(now)\n
if previous_open_sale_order is not None:\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 for line in previous_open_sale_order.contentValues(portal_type=\'Open Sale Order Line\'):\n
old_stop_date = line.getStopDate()\n old_stop_date = line.getStopDate()\n
if old_stop_date is not None:\n if old_stop_date is not None:\n
if stop_date is not None and old_stop_date < stop_date:\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 modify_kw_kw[line.getAggregate(portal_type=\'Hosting Subscription\')][\'stop_date\'] = stop_date\n
else:\n elif old_stop_date < now:\n
new_stop_date = old_stop_date + getNumberOfDayInMonth(old_stop_date)\n new_stop_date = addToDate(old_stop_date, to_add={\'month\': 1})\n
while new_stop_date < now:\n while new_stop_date < now:\n
new_stop_date += getNumberOfDayInMonth(new_stop_date)\n new_stop_date = addToDate(new_stop_date, to_add={\'month\': 1})\n
if new_stop_date < next_month and new_stop_date != stop_date:\n
hosting_id = line.getAggregate(portal_type=\'Hosting Subscription\')\n hosting_id = line.getAggregate(portal_type=\'Hosting Subscription\')\n
modify_kw_kw.setdefault(hosting_id, {})\n modify_kw_kw.setdefault(hosting_id, {})\n
modify_kw_kw[line.getAggregate(portal_type=\'Hosting Subscription\')][\'stop_date\'] = new_stop_date\n modify_kw_kw[line.getAggregate(portal_type=\'Hosting Subscription\')][\'stop_date\'] = new_stop_date\n
...@@ -117,10 +118,9 @@ for (key, value) in add_kw_kw.copy().iteritems():\n ...@@ -117,10 +118,9 @@ for (key, value) in add_kw_kw.copy().iteritems():\n
else:\n else:\n
start_date = add_kw_kw[key].get(\'start_date\')\n start_date = add_kw_kw[key].get(\'start_date\')\n
if start_date is not None:\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 while new_stop_date < now:\n
new_stop_date += getNumberOfDayInMonth(new_stop_date)\n new_stop_date = addToDate(new_stop_date, to_add={\'month\': 1})\n
if new_stop_date < next_month:\n
add_kw_kw[key][\'stop_date\'] = new_stop_date\n add_kw_kw[key][\'stop_date\'] = new_stop_date\n
\n \n
remove_id_list = set()\n remove_id_list = set()\n
......
648 649
\ No newline at end of file \ 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