Commit b4d0d9ac authored by Jérome Perrin's avatar Jérome Perrin

base: do not acquire stop date on currency exchange line

This allows defining an exchange rate without end date
parent fe105274
No related merge requests found
......@@ -2,7 +2,7 @@ currency_exchange_line = context.getParentValue()
currency = currency_exchange_line.getParentValue()
return context.asContext(_range_criterion=dict(start_date=(currency_exchange_line.getStartDate(),
currency_exchange_line.getStopDate())),
currency_exchange_line.hasStopDate() and currency_exchange_line.getStopDate() or None)),
membership_criterion_base_category=['price_currency', 'resource', 'currency_exchange_type'],
membership_criterion_category=['resource/%s' % currency.getRelativeUrl(),
currency_exchange_line.getPriceCurrency(base=True),
......
start_date = context.getStartDate()
stop_date = context.getStopDate()
stop_date = context.hasStopDate() and context.getStopDate() or None
identity_criterion = {'start_date':(start_date,stop_date)}
return context.asContext(_range_criterion=identity_criterion,
membership_criterion_base_category=['price_currency','resource'],
......
......@@ -9,7 +9,9 @@
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
<list>
<string>default</string>
</list>
</value>
</item>
<item>
......@@ -50,6 +52,12 @@
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
......@@ -70,8 +78,10 @@
<value>
<dictionary>
<item>
<key> <string>description</string> </key>
<value> <string>The end date for validity of the currency exchange rate.</string> </value>
<key> <string>default</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
......@@ -85,14 +95,23 @@
<key> <string>target</string> </key>
<value> <string>Click to edit the target</string> </value>
</item>
<item>
<key> <string>title</string> </key>
<value> <string>Validity End Date</string> </value>
</item>
</dictionary>
</value>
</item>
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: context.hasStopDate() and context.getStopDate() or None</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -9,7 +9,9 @@
<item>
<key> <string>delegated_list</string> </key>
<value>
<list/>
<list>
<string>default</string>
</list>
</value>
</item>
<item>
......@@ -50,6 +52,12 @@
<key> <string>tales</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<persistent> <string encoding="base64">AAAAAAAAAAI=</string> </persistent>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string></string> </value>
......@@ -69,6 +77,12 @@
<key> <string>values</string> </key>
<value>
<dictionary>
<item>
<key> <string>default</string> </key>
<value>
<none/>
</value>
</item>
<item>
<key> <string>field_id</string> </key>
<value> <string>my_stop_date</string> </value>
......@@ -87,4 +101,17 @@
</dictionary>
</pickle>
</record>
<record id="2" aka="AAAAAAAAAAI=">
<pickle>
<global name="TALESMethod" module="Products.Formulator.TALESField"/>
</pickle>
<pickle>
<dictionary>
<item>
<key> <string>_text</string> </key>
<value> <string>python: cell.hasStopDate() and cell.getStopDate() or None</string> </value>
</item>
</dictionary>
</pickle>
</record>
</ZopeData>
......@@ -79,6 +79,12 @@ class CurrencyExchangeTestCase(AccountingTestCase):
'erp5_simulation_test'
)
def _getPriceContext(self, **kw):
"""Returns a temp movement that we can use for getPrice(context=
"""
from Products.ERP5Type.Document import newTempMovement
return newTempMovement(self.portal, 'tmp', **kw)
class TestCurrencyExchangeLine(CurrencyExchangeTestCase):
"""
......@@ -495,6 +501,51 @@ class TestCurrencyExchangeLine(CurrencyExchangeTestCase):
else:
self.fail('line not found')
def test_date_on_currency_exchange_line(self):
euro = self.portal.currency_module.euro
usd = self.portal.currency_module.usd
euro_to_usd_before_2016 = euro.newContent(
portal_type='Currency Exchange Line',
stop_date=DateTime(2015, 12, 31, 23, 59),
base_price=0.5,
price_currency_value=usd)
euro_to_usd_before_2016.validate()
euro_to_usd_2016 = euro.newContent(
portal_type='Currency Exchange Line',
start_date=DateTime(2016, 1, 1),
stop_date=DateTime(2016, 12, 31, 23, 59),
base_price=0.6,
price_currency_value=usd)
euro_to_usd_2016.validate()
euro_to_usd_after_2016 = euro.newContent(
portal_type='Currency Exchange Line',
start_date=DateTime(2017, 1, 1),
base_price=0.7,
price_currency_value=usd)
euro_to_usd_after_2016.validate()
self.tic()
context_2015 = self._getPriceContext(
start_date=DateTime(2015, 1, 1),
categories=[
'resource/currency_module/euro',
'price_currency/currency_module/usd'])
self.assertEqual(0.5, euro.getPrice(context=context_2015))
context_2016 = self._getPriceContext(
start_date=DateTime(2016, 1, 1),
categories=[
'resource/currency_module/euro',
'price_currency/currency_module/usd'])
self.assertEqual(0.6, euro.getPrice(context=context_2016))
context_2017 = self._getPriceContext(
start_date=DateTime(2017, 1, 1),
categories=[
'resource/currency_module/euro',
'price_currency/currency_module/usd'])
self.assertEqual(0.7, euro.getPrice(context=context_2017))
class TestCurrencyExchangeCell(CurrencyExchangeTestCase):
def afterSetUp(self):
currency_exchange_type = \
......@@ -591,6 +642,74 @@ class TestCurrencyExchangeCell(CurrencyExchangeTestCase):
self.assertEqual(0.98, exchange_ratio)
def test_date_on_currency_exchange_cell(self):
euro = self.portal.currency_module.euro
usd = self.portal.currency_module.usd
euro_to_usd_before_2016 = euro.newContent(
portal_type='Currency Exchange Line',
stop_date=DateTime(2015, 12, 31, 23, 59),
price_currency_value=usd)
type_a_cell = euro_to_usd_before_2016.getCell(
'currency_exchange_type/type_a',
'resource/%s' % euro.getRelativeUrl(),
'price_currency/%s' % usd.getRelativeUrl(),
base_id='path')
type_a_cell.setBasePrice(0.5)
euro_to_usd_before_2016.validate()
euro_to_usd_2016 = euro.newContent(
portal_type='Currency Exchange Line',
start_date=DateTime(2016, 1, 1),
stop_date=DateTime(2016, 12, 31, 23, 59),
price_currency_value=usd)
type_a_cell = euro_to_usd_2016.getCell(
'currency_exchange_type/type_a',
'resource/%s' % euro.getRelativeUrl(),
'price_currency/%s' % usd.getRelativeUrl(),
base_id='path')
type_a_cell.setBasePrice(0.6)
euro_to_usd_2016.validate()
euro_to_usd_after_2016 = euro.newContent(
portal_type='Currency Exchange Line',
start_date=DateTime(2017, 1, 1),
price_currency_value=usd)
type_a_cell = euro_to_usd_after_2016.getCell(
'currency_exchange_type/type_a',
'resource/%s' % euro.getRelativeUrl(),
'price_currency/%s' % usd.getRelativeUrl(),
base_id='path')
type_a_cell.setBasePrice(0.7)
euro_to_usd_after_2016.validate()
self.tic()
context_2015 = self._getPriceContext(
start_date=DateTime(2015, 1, 1),
categories=[
'resource/currency_module/euro',
'price_currency/currency_module/usd',
'currency_exchange_type/type_a'])
self.assertEqual(0.5,
euro.getPrice(context=context_2015, portal_type='Currency Exchange Cell'))
context_2016 = self._getPriceContext(
start_date=DateTime(2016, 1, 1),
categories=[
'resource/currency_module/euro',
'price_currency/currency_module/usd',
'currency_exchange_type/type_a'])
self.assertEqual(0.6,
euro.getPrice(context=context_2016, portal_type='Currency Exchange Cell'))
context_2017 = self._getPriceContext(
start_date=DateTime(2017, 1, 1),
categories=[
'resource/currency_module/euro',
'price_currency/currency_module/usd',
'currency_exchange_type/type_a'])
self.assertEqual(0.7,
euro.getPrice(context=context_2017, portal_type='Currency Exchange Cell'))
def test_suite():
suite = unittest.TestSuite()
suite.addTest(unittest.makeSuite(TestCurrencyExchangeLine))
......
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