Commit 27d533ff authored by Jérome Perrin's avatar Jérome Perrin

pdm: tolerate getEffectiveModel errors during indexation

it can happen that getEffectiveModel does not find a model, this
is currently causing activity failures in indexation of
transformations. Tolerate errors here because this is not an error
but just a sign of invalid user data.
parent f7b7edb6
Pipeline #29965 failed with stage
in 0 seconds
...@@ -111,7 +111,7 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion): ...@@ -111,7 +111,7 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion):
return TestTransformationMixin.getBusinessTemplateList(self) + ( return TestTransformationMixin.getBusinessTemplateList(self) + (
'erp5_apparel', 'erp5_dummy_movement', 'erp5_project') 'erp5_apparel', 'erp5_dummy_movement', 'erp5_project')
def test_01_getAggregatedAmountListSimple(self): def test_getAggregatedAmountListSimple(self):
""" """
Make sure that getAggregatedAmountList return something Make sure that getAggregatedAmountList return something
""" """
...@@ -150,7 +150,7 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion): ...@@ -150,7 +150,7 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion):
[(1, first_component), (2, second_component)] [(1, first_component), (2, second_component)]
) )
def test_01_getAggregatedAmountListWithVariatedProperty(self): def test_getAggregatedAmountListWithVariatedProperty(self):
""" """
Make sure that getAggregatedAmountList is still working properly if we Make sure that getAggregatedAmountList is still working properly if we
have additionnals propertysheets on transformations lines and that used have additionnals propertysheets on transformations lines and that used
...@@ -448,6 +448,44 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion): ...@@ -448,6 +448,44 @@ class TestTransformation(TestTransformationMixin, BaseTestUnitConversion):
'Transformation Transformed Resource') 'Transformation Transformed Resource')
self.assertEqual(transformed_resource.getResource(), None) self.assertEqual(transformed_resource.getResource(), None)
def test_transformation_indexing(self):
target_product = self.portal.product_module.newContent(portal_type='Product')
consumed_product = self.portal.product_module.newContent(portal_type='Product')
self.tic()
transformation = self.portal.transformation_module.newContent(
portal_type='Transformation',
resource_value=target_product,
)
transformation.newContent(
portal_type='Transformation Transformed Resource',
resource_value=consumed_product,
quantity=-2
)
self.tic()
# when target product is reindexed, the corresponding transformations are indexed
target_product.edit()
self.tic()
self.assertEqual(
self.portal.erp5_sql_connection.manage_test(
'SELECT * from transformation where uid=%s' % target_product.getUid()).dictionaries(),
[{
'uid': target_product.getUid(),
'variation_text': '',
'transformed_uid': consumed_product.getUid(),
'transformed_variation_text': '',
'quantity': -2,
}],
)
# non regression: this works even if transformation has a reference
transformation.setReference(self.id())
target_product.edit()
self.tic()
def test_suite(): def test_suite():
import unittest import unittest
suite = unittest.TestSuite() suite = unittest.TestSuite()
......
...@@ -30,7 +30,12 @@ for transformation_relative_url, variation_list_list in transformation_item_list ...@@ -30,7 +30,12 @@ for transformation_relative_url, variation_list_list in transformation_item_list
base_row = dict(uid=resource.getUid(), variation_text=movement.getVariationText()) base_row = dict(uid=resource.getUid(), variation_text=movement.getVariationText())
row_dict_list = [] row_dict_list = []
for amount in movement.getAggregatedAmountList(): try:
# this can fail if getEffectiveModel transformation can not be found
aggregated_amount_list = movement.getAggregatedAmountList()
except KeyError:
aggregated_amount_list = []
for amount in aggregated_amount_list:
transformed_resource_uid = amount.getResourceUid() transformed_resource_uid = amount.getResourceUid()
quantity = amount.getQuantity() quantity = amount.getQuantity()
if transformed_resource_uid is not None and quantity is not None: if transformed_resource_uid is not None and quantity is not None:
......
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