Changeset 12768 for main


Ignore:
Timestamp:
15 Mar 2015, 13:02:49 (10 years ago)
Author:
Henrik Bettermann
Message:

Add constraint to forbid the selection of options with different currencies.

Location:
main/waeup.ikoba/trunk/src/waeup/ikoba/customers
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12741 r12768  
    3737
    3838
     39# Define a validation method for product options
     40class CurrencyMismatch(schema.ValidationError):
     41    __doc__ = u"Currency mismatch"
     42
     43
     44def unique_currency(value):
     45    currencies = set([x.currency for x in value])
     46    if len(currencies) > 1:
     47        raise CurrencyMismatch(value)
     48    return True
     49
     50
    3951class ICustomersUtils(Interface):
    4052    """A collection of methods which are subject to customization.
     
    324336            required = True,
    325337            ),
     338        constraint=unique_currency,
    326339        required = False,
    327340        readonly = False,
     
    379392    product_options = schema.List(
    380393        value_type = ProductOptionField(),
     394        constraint=unique_currency,
    381395        required = False,
    382396        readonly = False,
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12750 r12768  
    4949from waeup.ikoba.browser.tests.test_pdf import samples_dir
    5050from waeup.ikoba.products.productoptions import ProductOption
     51from waeup.ikoba.customers.interfaces import CurrencyMismatch
    5152
    5253PH_LEN = 15911  # Length of placeholder file
     
    12971298        contract.product_options = [prodoption, ]
    12981299
     1300    def test_multiple_currencies(self):
     1301        prodoption1 = ProductOption()
     1302        prodoption1.title = u'Any product option in Euros'
     1303        prodoption1.fee = Decimal('88.8')
     1304        prodoption1.currency = 'EUR'
     1305        prodoption2 = ProductOption()
     1306        prodoption2.title = u'Any product option in Dollars'
     1307        prodoption2.fee = Decimal('99.9')
     1308        prodoption2.currency = 'USD'
     1309        self.assertRaises(CurrencyMismatch,
     1310                          setattr, self.contract,
     1311                          'product_options',
     1312                          [prodoption1, prodoption2]
     1313                          )
     1314
    12991315    def prepare_payment_select(self):
    13001316        IWorkflowState(self.customer).setState('approved')
Note: See TracChangeset for help on using the changeset viewer.