Commit bf9f663a authored by Titouan Soulard's avatar Titouan Soulard

erp5_trade: FIXUP variated test

Almost working test, Inventory API still does not process properly.
parent 71589bf2
Pipeline #39054 failed with stage
in 0 seconds
......@@ -78,30 +78,37 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
stop_date=self.default_stock_entry_date,
)
for line in lines:
for product_relative_url, line in lines.items():
purchase_packing_list_line_value = purchase_packing_list_value.newContent(
portal_type="Purchase Packing List Line",
resource=product_relative_url,
)
purchase_packing_list_line_variation_list = []
if len(line) == 2:
(product_value, cells) = line
# When a subdictionary is passed, create cells
if isinstance(line, dict):
purchase_packing_list_line_variation_list = line.keys()
purchase_packing_list_line_cell_range = ["variation/" + variation for variation in purchase_packing_list_line_variation_list]
for (variation_value, quantity, price) in cells:
purchase_packing_list_line_value.newContent(
purchase_packing_list_line_value.setVariationValueList(purchase_packing_list_line_variation_list)
purchase_packing_list_line_value.setCellRange(purchase_packing_list_line_cell_range, base_id="movement")
for variation_relative_url, cell in line.items():
(quantity, price) = cell
purchase_packing_list_line_value.newCell(
"variation/" + variation_relative_url,
portal_type="Purchase Packing List Cell",
variation_value=variation_value,
variation=variation_relative_url,
quantity=quantity,
price=price,
base_id="movement",
)
# Supports tuples
else:
(quantity, price) = line
purchase_packing_list_line_value.edit(
quantity=quantity,
price=price
)
purchase_packing_list_line_variation_list.append(variation_value)
elif len(line) == 3:
(product_value, quantity, price) = line
purchase_packing_list_line_value.setQuantity(quantity)
purchase_packing_list_line_value.setPrice(price)
purchase_packing_list_line_value.setResourceValue(product_value)
purchase_packing_list_line_value.setVariationValueList(purchase_packing_list_line_variation_list)
purchase_packing_list_value.confirm()
self.tic()
......@@ -119,37 +126,35 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
destination_value=self.destination_organisation_value,
start_date=self.default_inventory_date,
)
inventory_line_variation_list = []
for line in lines:
for product_relative_url, line in lines.items():
inventory_line_value = inventory_value.newContent(
portal_type="Inventory Line",
resource=product_relative_url,
)
if len(line) == 2:
(product_value, cells) = line
inventory_line_variation_list = [cell[0] for cell in cells]
inventory_line_cell_range = ["variation/" + variation.getRelativeUrl() for variation in inventory_line_variation_list]
# When a subdictionary is passed, create cells
if isinstance(line, dict):
inventory_line_variation_list = line.keys()
inventory_line_cell_range = ["variation/" + variation for variation in inventory_line_variation_list]
inventory_line_value.setResourceValue(product_value)
inventory_line_value.setVariationValueList(inventory_line_variation_list)
inventory_line_value.setCellRange(inventory_line_cell_range, base_id="movement")
for (variation_value, quantity, price) in cells:
cell_variation_text = "variation/" + variation_value.getRelativeUrl()
for variation_relative_url, cell in line.items():
(quantity, price) = cell
inventory_line_value.newCell(
cell_variation_text,
"variation/" + variation_relative_url,
portal_type="Inventory Cell",
variation_value=variation_value,
variation=variation_relative_url,
inventory=quantity,
price=price,
base_id="movement",
)
inventory_line_variation_list.append(variation_value)
elif len(line) == 3:
(product_value, quantity, price) = line
# Supports tuples
else:
(quantity, price) = line
inventory_line_value.edit(
resource_value=product_value,
inventory=quantity,
price=price
)
......@@ -202,9 +207,9 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
self.unvariated_product.setQuantityUnitList(["unit/piece"])
self.tic()
self._createPurchasePackingList([
(self.unvariated_product, 2.0, 100.0),
])
self._createPurchasePackingList({
self.unvariated_product.getRelativeUrl(): (2.0, 100.0),
})
# Sanity check: ensure Inventory API reports what's expected
(initial_inventory, initial_price) = self._getInventoryAmount(self.unvariated_product)
......@@ -214,9 +219,9 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
# Assert: initial price of stock is 100.0 * 2.0 = 200.0
self.assertEqual(200.0, initial_price)
inventory_value = self._createInventory([
(self.unvariated_product, 3.0, 110.0)
])
inventory_value = self._createInventory({
self.unvariated_product.getRelativeUrl(): (3.0, 110.0),
})
inventory_offset_line_list = inventory_value.objectValues(portal_type="Inventory Offset Line")
......@@ -246,46 +251,41 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
)
self.variated_product.setQuantityUnitList(["unit/piece"])
self.variated_product.setIndividualVariationBaseCategoryList(["variation"])
self.variated_product_variation_list = []
variated_product_variation_dict = {}
for (i, variation_name) in enumerate(["A", "B", "C"]):
variated_product_variation = self.variated_product.newContent(
portal_type=self.default_product_variation_portal_type,
title="Variation " + variation_name,
)
self.variated_product_variation_list.append([variated_product_variation, (i + 1), (i + 1) * 100.0])
variated_product_variation_dict[variated_product_variation.getRelativeUrl()] = ((i + 1) * 1.0, (i + 1) * 100.0)
self.tic()
self._createPurchasePackingList([
(self.variated_product, self.variated_product_variation_list),
])
self._createPurchasePackingList({
self.variated_product.getRelativeUrl(): variated_product_variation_dict,
})
# Sanity check: ensure Inventory API reports what's expected
inventory_dict = self._getInventoryDict(self.variated_product)
# Convert unit prices to total prices for comparison
for variated_product_variation in variated_product_variation_dict.keys():
(quantity, unit_price) = variated_product_variation_dict[variated_product_variation]
variated_product_variation_dict[variated_product_variation] = (quantity, unit_price * quantity)
for variation in self.variated_product_variation_list:
variation_relative_url = variation[0].getRelativeUrl()
# Assert: variation exists in stock
self.assertIn(variation_relative_url, inventory_dict)
(initial_inventory, initial_price) = inventory_dict[variation_relative_url]
# Assert: quantity is correct
self.assertEqual(variation[1], initial_inventory)
# Assert: price is correct
self.assertEqual(variation[1] * variation[2], initial_price)
self.assertEqual(variated_product_variation_dict, inventory_dict)
# We are going to add:
# - 1 variation B at price 100;
# - 2 variations C at price 200.
# Then create an Inventory with the new values.
for (i, variation) in enumerate(self.variated_product_variation_list):
variation[1] += i
variation[2] = i * 100.0
for i, variated_product_variation in enumerate(variated_product_variation_dict.keys()):
(quantity, _) = variated_product_variation_dict[variated_product_variation]
variated_product_variation_dict[variated_product_variation] = (quantity + i, i * 100.0)
inventory_value = self._createInventory([
(self.variated_product, self.variated_product_variation_list),
])
inventory_value = self._createInventory({
self.variated_product.getRelativeUrl(): variated_product_variation_dict,
})
# Assert: one and only one offset line was created
inventory_offset_line_list = inventory_value.objectValues(portal_type="Inventory Offset Line")
......@@ -303,13 +303,10 @@ class TestInventoryModule(TestOrderMixin, ERP5TypeTestCase):
inventory_dict = self._getInventoryDict(self.variated_product)
for (i, variation) in enumerate(self.variated_product_variation_list):
variation_relative_url = variation[0].getRelativeUrl()
# Fix total prices because their computation is weird
for variated_product_variation in variated_product_variation_dict.keys():
(quantity, _) = variated_product_variation_dict[variated_product_variation]
variated_product_variation_dict[variated_product_variation] = (quantity, 100.0)
# Assert: variation exists in stock
self.assertIn(variation_relative_url, inventory_dict)
(final_inventory, final_price) = inventory_dict[variation_relative_url]
# Assert: quantity is correct
self.assertEqual(variation[1], final_inventory)
# Assert: price is correct
#self.assertEqual(i * 100.0 + (i + , final_price)
# Assert: strict equality of inventories
self.assertEqual(variated_product_variation_dict, inventory_dict)
......@@ -43,9 +43,7 @@
<item>
<key> <string>text_content_warning_message</string> </key>
<value>
<tuple>
<string>W:311, 24: Unused variable \'final_price\' (unused-variable)</string>
</tuple>
<tuple/>
</value>
</item>
<item>
......
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