Commit 3b1e230c authored by Jérome Perrin's avatar Jérome Perrin

Don't call a useless getPrice on edit(price=x)

Base.edit has this feature of not actually modifying the properties when
the new property value is same as the current one, so when we do
`movement.edit(price=x)`, this will cause an implicit getPrice.

As price lookup is a bit slow, do not lookup price in this case.

/cc @vpelletier @kazuhiko @romain 

/reviewed-on nexedi/erp5!259
parents bc3b5a25 a78c0126
......@@ -230,8 +230,6 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
if self.isMovingItem(item)]
# Pricing methods
# _getPrice is defined in the order / delivery
# Pricing mehod
def _getPrice(self, context):
context = self.asContext(context=context,
quantity=self.getConvertedQuantity())
......@@ -327,7 +325,7 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
DeprecationWarning)
local_price = self._baseGetPrice()
if local_price is None:
if local_price is None and evaluate:
# We must find a price for this movement
local_price = self._getPrice(context=self)
return local_price
......
......@@ -588,6 +588,19 @@ class TestSaleSupply(TestSupplyMixin, SubcontentReindexingWrapper,
preference.setPreferredPricingOptimise(False)
self._clearCache()
def test_getPriceDoesNotLookupPriceDuringEdit(self):
"""Test getPrice does not lookup price during edit.
"""
movement = self._makeRealMovement()
def methodThatShouldNotBeCalled(*args, **kw):
self.fail("price lookup should not happen")
movement.getPriceCalculationOperandDict = methodThatShouldNotBeCalled
movement._getPrice = methodThatShouldNotBeCalled
movement.edit(price=10)
self.assertEqual(10, movement.getPrice())
self.abort()
def _createTwoHundredSupplyLineInASupply(self):
supply = self._makeSupply(
......
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