Commit 4e168f81 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 9679fdec
......@@ -325,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