Commit aaeff4af authored by Romain Courteaud's avatar Romain Courteaud

slapos_subscription_request: fixup the packing list start_date

parent bcdbc917
...@@ -72,7 +72,7 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe ...@@ -72,7 +72,7 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# compute_node # compute_node
self.logout() self.logout()
with PinnedDateTime(self, DateTime('2024/01/29')): with PinnedDateTime(self, DateTime('2023/12/29')):
public_reference = 'public-%s' % self.generateNewId() public_reference = 'public-%s' % self.generateNewId()
self.joinSlapOS(self.web_site, public_reference) self.joinSlapOS(self.web_site, public_reference)
with PinnedDateTime(self, DateTime('2024/02/01')): with PinnedDateTime(self, DateTime('2024/02/01')):
...@@ -95,7 +95,7 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe ...@@ -95,7 +95,7 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
public_instance_title = 'Public title %s' % self.generateNewId() public_instance_title = 'Public title %s' % self.generateNewId()
self.login(person_user_id) self.login(person_user_id)
with PinnedDateTime(self, DateTime('2024/02/10')): with PinnedDateTime(self, DateTime('2024/01/10')):
self.personRequestInstanceNotReady( self.personRequestInstanceNotReady(
software_release=software_release, software_release=software_release,
software_type=software_type, software_type=software_type,
...@@ -150,8 +150,8 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe ...@@ -150,8 +150,8 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
} }
inventory_list = self.portal.portal_simulation.getCurrentInventoryList(**inventory_list_kw) inventory_list = self.portal.portal_simulation.getCurrentInventoryList(**inventory_list_kw)
self.assertEquals(1, len(inventory_list)) self.assertEquals(1, len(inventory_list))
# 1 - 0.42 (13 days of 31) - 0.1 (3 days of 31) + 1 - 0.83 (24 days of 29) # 2 - 0.42 (13 days of 31) - 0.1 (3 days of 31) + 1 - 0.83 (24 days of 29)
self.assertAlmostEquals(-0.65, inventory_list[0].total_quantity) self.assertAlmostEquals(-1.65, inventory_list[0].total_quantity)
inventory_list_kw = { inventory_list_kw = {
'group_by_section': False, 'group_by_section': False,
...@@ -172,14 +172,14 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe ...@@ -172,14 +172,14 @@ class TestSlapOSSubscriptionChangeRequestScenario(TestSlapOSSubscriptionChangeRe
# 1 instance tree # 1 instance tree
# 7 open sale order # 7 open sale order
# 4 assignment # 4 assignment
# 3 simulation movement # 4 simulation movement
# 6 sale packing list / line # 7 sale packing list / line
# 2 sale trade condition ( a 3rd trade condition is not linked to the project) # 2 sale trade condition ( a 3rd trade condition is not linked to the project)
# 1 software instance # 1 software instance
# 1 software product # 1 software product
# 1 subscription change request # 1 subscription change request
# 2 subscription request # 2 subscription request
self.assertRelatedObjectCount(project, 30) self.assertRelatedObjectCount(project, 32)
with PinnedDateTime(self, DateTime('2024/02/15')): with PinnedDateTime(self, DateTime('2024/02/15')):
self.checkERP5StateBeforeExit() self.checkERP5StateBeforeExit()
......
...@@ -12,9 +12,13 @@ if open_sale_order_cell.getPortalType() == 'Open Sale Order Cell': ...@@ -12,9 +12,13 @@ if open_sale_order_cell.getPortalType() == 'Open Sale Order Cell':
start_date = open_sale_order.getStartDate() start_date = open_sale_order.getStartDate()
next_period_date = hosting_subscription.getNextPeriodicalDate(current_date) next_period_date = hosting_subscription.getNextPeriodicalDate(current_date)
# Calculate the start_date of the monthly packing list
previous_period_date = start_date
while hosting_subscription.getNextPeriodicalDate(previous_period_date) < next_period_date:
previous_period_date = hosting_subscription.getNextPeriodicalDate(previous_period_date)
if open_sale_order.getValidationState() == 'validated': if open_sale_order.getValidationState() == 'validated':
unused_day_count = current_date - start_date unused_day_count = current_date - previous_period_date
elif open_sale_order.getValidationState() == 'archived': elif open_sale_order.getValidationState() == 'archived':
unused_day_count = next_period_date - current_date unused_day_count = next_period_date - current_date
else: else:
...@@ -22,7 +26,7 @@ else: ...@@ -22,7 +26,7 @@ else:
sale_packing_list_edit_kw = dict( sale_packing_list_edit_kw = dict(
title=title, title=title,
start_date=start_date, start_date=previous_period_date,
# It should match the first open order invoice # It should match the first open order invoice
stop_date=next_period_date, stop_date=next_period_date,
specialise_value=open_sale_order.getSpecialiseValue(), specialise_value=open_sale_order.getSpecialiseValue(),
...@@ -49,7 +53,7 @@ if (0 < unused_day_count): ...@@ -49,7 +53,7 @@ if (0 < unused_day_count):
sale_packing_list = portal.sale_packing_list_module.newContent( sale_packing_list = portal.sale_packing_list_module.newContent(
portal_type="Sale Packing List", portal_type="Sale Packing List",
comment="%s unused days of %s" % (unused_day_count, next_period_date-start_date), comment="%s unused days of %s" % (unused_day_count, next_period_date-previous_period_date),
**sale_packing_list_edit_kw **sale_packing_list_edit_kw
) )
...@@ -82,7 +86,7 @@ if (0 < unused_day_count): ...@@ -82,7 +86,7 @@ if (0 < unused_day_count):
else: else:
sale_packing_list_cell = sale_packing_list_line sale_packing_list_cell = sale_packing_list_line
quantity = open_sale_order_cell.getQuantity() * (unused_day_count / (next_period_date - start_date)) quantity = open_sale_order_cell.getQuantity() * (unused_day_count / (next_period_date - previous_period_date))
# precision = context.getQuantityPrecisionFromResource(open_sale_order_cell.getResourceValue()) # precision = context.getQuantityPrecisionFromResource(open_sale_order_cell.getResourceValue())
# XXX Stock does not seem to use quantity unit precision... # XXX Stock does not seem to use quantity unit precision...
precision = 2 precision = 2
......
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