Commit 9d340a75 authored by Jérome Perrin's avatar Jérome Perrin

ERP5: do not lookup price during movement.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.
parent dc216a92
...@@ -325,7 +325,7 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin): ...@@ -325,7 +325,7 @@ class Movement(XMLObject, Amount, CompositionMixin, AmountGeneratorMixin):
DeprecationWarning) DeprecationWarning)
local_price = self._baseGetPrice() local_price = self._baseGetPrice()
if local_price is None: if local_price is None and evaluate:
# We must find a price for this movement # We must find a price for this movement
local_price = self._getPrice(context=self) local_price = self._getPrice(context=self)
return local_price return local_price
......
...@@ -588,6 +588,19 @@ class TestSaleSupply(TestSupplyMixin, SubcontentReindexingWrapper, ...@@ -588,6 +588,19 @@ class TestSaleSupply(TestSupplyMixin, SubcontentReindexingWrapper,
preference.setPreferredPricingOptimise(False) preference.setPreferredPricingOptimise(False)
self._clearCache() 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): def _createTwoHundredSupplyLineInASupply(self):
supply = self._makeSupply( 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