Commit 667f16e8 authored by Łukasz Nowak's avatar Łukasz Nowak

erp5_item: Do not update quantity

Since there is constraint on the movement, which requires quantity to
match amount of items it is user responsibility to take decision about
what to do after using dialogs to fill in items.
parent 08e434f9
...@@ -79,7 +79,5 @@ for line in kw.get('listbox'): ...@@ -79,7 +79,5 @@ for line in kw.get('listbox'):
movement_to_update.setAggregateValueList( movement_to_update.setAggregateValueList(
movement_to_update.getAggregateValueList() + [item]) movement_to_update.getAggregateValueList() + [item])
context.Movement_updateQuantityFromAggregateList(at_date=DateTime())
return context.Base_redirect(form_id, keep_items=dict( return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=translateString('Items created'))) portal_status_message=translateString('Items created')))
...@@ -92,7 +92,5 @@ for item_uid in uids: ...@@ -92,7 +92,5 @@ for item_uid in uids:
movement_to_update.setAggregateValueSet( movement_to_update.setAggregateValueSet(
movement_to_update.getAggregateValueList() + [item]) movement_to_update.getAggregateValueList() + [item])
context.Movement_updateQuantityFromAggregateList()
return context.Base_redirect(form_id, keep_items=dict( return context.Base_redirect(form_id, keep_items=dict(
portal_status_message=translateString('Items aggregated'))) portal_status_message=translateString('Items aggregated')))
if context.isMovement():
movement_list = context,
else:
movement_list = context.getCellValueList(base_id='movement')
for movement in movement_list:
quantity = 0
item_list = movement.getAggregateValueList()
for item in item_list:
if item.getQuantityUnit() != movement.getQuantityUnit():
if len(item_list) > 1:
raise NotImplementedError(
'Quantity unit from the movement differs from quantity'
' unit on the item')
else:
movement.setQuantityUnit(item.getQuantityUnit())
quantity += item.getQuantity(at_date=at_date)
movement.setQuantity(quantity)
<?xml version="1.0"?>
<ZopeData>
<record id="1" aka="AAAAAAAAAAE=">
<pickle>
<global name="PythonScript" module="Products.PythonScripts.PythonScript"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>Script_magic</string> </key>
<value> <int>3</int> </value>
</item>
<item>
<key> <string>_bind_names</string> </key>
<value>
<object>
<klass>
<global name="NameAssignments" module="Shared.DC.Scripts.Bindings"/>
</klass>
<tuple/>
<state>
<dictionary>
<item>
<key> <string>_asgns</string> </key>
<value>
<dictionary>
<item>
<key> <string>name_container</string> </key>
<value> <string>container</string> </value>
</item>
<item>
<key> <string>name_context</string> </key>
<value> <string>context</string> </value>
</item>
<item>
<key> <string>name_m_self</string> </key>
<value> <string>script</string> </value>
</item>
<item>
<key> <string>name_subpath</string> </key>
<value> <string>traverse_subpath</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</state>
</object>
</value>
</item>
<item>
<key> <string>_params</string> </key>
<value> <string>at_date=None</string> </value>
</item>
<item>
<key> <string>id</string> </key>
<value> <string>Movement_updateQuantityFromAggregateList</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
...@@ -36,10 +36,39 @@ from Products.ERP5Type.tests.Sequence import SequenceList ...@@ -36,10 +36,39 @@ from Products.ERP5Type.tests.Sequence import SequenceList
from Products.ERP5.tests.testInvoice import TestSaleInvoiceMixin from Products.ERP5.tests.testInvoice import TestSaleInvoiceMixin
from Products.ERP5.tests.utils import newSimulationExpectedFailure from Products.ERP5.tests.utils import newSimulationExpectedFailure
from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod from Products.ERP5Type.UnrestrictedMethod import UnrestrictedMethod
from Products.ERP5Type.Base import Base
def checkMovementAggregateQuantityConstraint(document):
# Base.checkConsistency is used here in order to avoid recursive check
message_list = Base.checkConsistency(
document, filter={'reference': 'movement_aggregate_quantity'})
if len(message_list) == 0:
return True
return False
class TestItemMixin(TestSaleInvoiceMixin): class TestItemMixin(TestSaleInvoiceMixin):
item_portal_type = 'Item' item_portal_type = 'Item'
def afterSetUp(self):
super(TestItemMixin, self).afterSetUp()
self._addPropertySheet(
'Purchase Packing List Line', 'MovementAggregateQuantityConstraint')
self._addPropertySheet(
'Purchase Packing List Cell', 'MovementAggregateQuantityConstraint')
self._addPropertySheet(
'Internal Packing List Line', 'MovementAggregateQuantityConstraint')
self._addPropertySheet(
'Internal Packing List Cell', 'MovementAggregateQuantityConstraint')
self.commit()
def assertMovementAggregateQuantityConstraintConsistent(self, document):
self.assertTrue(checkMovementAggregateQuantityConstraint(document))
def assertMovementAggregateQuantityConstraintInconsistent(self, document):
self.assertFalse(checkMovementAggregateQuantityConstraint(document))
def getBusinessTemplateList(self): def getBusinessTemplateList(self):
""" """
custom list of business templates for testItem custom list of business templates for testItem
...@@ -458,7 +487,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -458,7 +487,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
portal_type='Item', portal_type='Item',
title='Lot C')]), 1) title='Lot C')]), 1)
self.assertEqual(packing_list_line.getTotalQuantity(), 45.0) self.assertEqual(packing_list_line.getTotalQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintConsistent(packing_list_line)
self.assertEqual(sorted(packing_list_line.getVariationCategoryList()), self.assertEqual(sorted(packing_list_line.getVariationCategoryList()),
sorted([size_base + '/3', sorted([size_base + '/3',
size_base + '/2', size_base + '/2',
...@@ -471,17 +501,20 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -471,17 +501,20 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
cell = packing_list_line.getCell(base_id='movement', cell = packing_list_line.getCell(base_id='movement',
*(size_base + '/3', )) *(size_base + '/3', ))
self.assertEqual(cell.getQuantity(), 20) self.assertEqual(cell.getQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintInconsistent(cell)
self.assertEqual(['Lot A'], cell.getAggregateTitleList()) self.assertEqual(['Lot A'], cell.getAggregateTitleList())
cell = packing_list_line.getCell(base_id='movement', cell = packing_list_line.getCell(base_id='movement',
*(size_base + '/2', )) *(size_base + '/2', ))
self.assertEqual(cell.getQuantity(), 10) self.assertEqual(cell.getQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintInconsistent(cell)
self.assertEqual(['Lot B'], cell.getAggregateTitleList()) self.assertEqual(['Lot B'], cell.getAggregateTitleList())
cell = packing_list_line.getCell(base_id='movement', cell = packing_list_line.getCell(base_id='movement',
*(size_base + '/1', )) *(size_base + '/1', ))
self.assertEqual(cell.getQuantity(), 15) self.assertEqual(cell.getQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintInconsistent(cell)
self.assertEqual(['Lot C'], cell.getAggregateTitleList()) self.assertEqual(['Lot C'], cell.getAggregateTitleList())
...@@ -507,7 +540,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -507,7 +540,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox) packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox)
self.assertEqual(packing_list_line.getVariationCategoryList(), self.assertEqual(packing_list_line.getVariationCategoryList(),
[size_base + '/3']) [size_base + '/3'])
self.assertEqual(packing_list_line.getTotalQuantity(), 20) self.assertEqual(packing_list_line.getTotalQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintConsistent(packing_list_line)
# create listbox a second time # create listbox a second time
listbox = ({ 'listbox_key': '000', listbox = ({ 'listbox_key': '000',
...@@ -526,7 +560,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -526,7 +560,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox) packing_list_line.DeliveryLine_createItemList(type='Item', listbox=listbox)
self.tic() self.tic()
self.assertEqual(packing_list_line.getTotalQuantity(), 55.0) self.assertEqual(packing_list_line.getTotalQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintConsistent(packing_list_line)
self.assertEqual(sorted(packing_list_line.getVariationCategoryList()), self.assertEqual(sorted(packing_list_line.getVariationCategoryList()),
sorted([size_base + '/1', sorted([size_base + '/1',
size_base + '/2', size_base + '/2',
...@@ -538,17 +573,20 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -538,17 +573,20 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
cell = packing_list_line.getCell(base_id='movement', cell = packing_list_line.getCell(base_id='movement',
*(size_base + '/3', )) *(size_base + '/3', ))
self.assertEqual(cell.getQuantity(), 20) self.assertEqual(cell.getQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintInconsistent(cell)
self.assertEqual(['Lot A2'], cell.getAggregateTitleList()) self.assertEqual(['Lot A2'], cell.getAggregateTitleList())
cell = packing_list_line.getCell(base_id='movement', cell = packing_list_line.getCell(base_id='movement',
*(size_base + '/1', )) *(size_base + '/1', ))
self.assertEqual(cell.getQuantity(), 20) self.assertEqual(cell.getQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintInconsistent(cell)
self.assertEqual(['Lot B2'], cell.getAggregateTitleList()) self.assertEqual(['Lot B2'], cell.getAggregateTitleList())
cell = packing_list_line.getCell(base_id='movement', cell = packing_list_line.getCell(base_id='movement',
*(size_base + '/2', )) *(size_base + '/2', ))
self.assertEqual(cell.getQuantity(), 15) self.assertEqual(cell.getQuantity(), 0.0)
self.assertMovementAggregateQuantityConstraintInconsistent(cell)
self.assertEqual(['Lot C2'], cell.getAggregateTitleList()) self.assertEqual(['Lot C2'], cell.getAggregateTitleList())
...@@ -595,7 +633,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -595,7 +633,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
len([x.getObject() for x in self.portal.portal_catalog( len([x.getObject() for x in self.portal.portal_catalog(
portal_type='Item', portal_type='Item',
title='Lot C3')]), 1) title='Lot C3')]), 1)
self.assertEqual(packing_list_line.getQuantity(),30.0) self.assertEqual(packing_list_line.getQuantity(),32.0)
self.assertMovementAggregateQuantityConstraintInconsistent(packing_list_line)
self.assertEqual(packing_list_line.getVariationCategoryList(), []) self.assertEqual(packing_list_line.getVariationCategoryList(), [])
self.assertEqual(packing_list_line.getAggregateTitleList(), self.assertEqual(packing_list_line.getAggregateTitleList(),
...@@ -897,7 +936,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -897,7 +936,8 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
uids=(item.getUid(),)) uids=(item.getUid(),))
self.assertEqual([item], packing_list_line.getAggregateValueList()) self.assertEqual([item], packing_list_line.getAggregateValueList())
self.assertEqual(12, packing_list_line.getQuantity()) self.assertEqual(32.0, packing_list_line.getQuantity())
self.assertMovementAggregateQuantityConstraintInconsistent(packing_list_line)
def test_select_item_dialog_variation(self): def test_select_item_dialog_variation(self):
...@@ -958,14 +998,16 @@ class TestItem(TestItemMixin, ERP5TypeTestCase): ...@@ -958,14 +998,16 @@ class TestItem(TestItemMixin, ERP5TypeTestCase):
self.assertEqual([variation], self.assertEqual([variation],
packing_list_line.getVariationCategoryList()) packing_list_line.getVariationCategoryList())
self.assertEqual(12, packing_list_line.getTotalQuantity()) self.assertEqual(0.0, packing_list_line.getTotalQuantity())
self.assertMovementAggregateQuantityConstraintConsistent(packing_list_line)
self.assertEqual([], packing_list_line.getAggregateValueList()) self.assertEqual([], packing_list_line.getAggregateValueList())
self.assertEqual(1, self.assertEqual(1,
len(packing_list_line.getCellValueList(base_id='movement'))) len(packing_list_line.getCellValueList(base_id='movement')))
cell = packing_list_line.getCell(base_id='movement', *(variation, )) cell = packing_list_line.getCell(base_id='movement', *(variation, ))
self.assertEqual(12, cell.getQuantity()) self.assertEqual(0.0, cell.getQuantity())
self.assertMovementAggregateQuantityConstraintInconsistent(cell)
self.assertEqual([item], cell.getAggregateValueList()) self.assertEqual([item], cell.getAggregateValueList())
......
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