Ignore:
Timestamp:
10 Feb 2015, 15:39:09 (10 years ago)
Author:
Henrik Bettermann
Message:

Only valid (active) products are selectable in UI.

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

Legend:

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

    r12553 r12585  
    3232    contextual_reg_num_source, contextual_email_source,
    3333    GenderSource, nats_vocab,
    34     ConCatProductSource, CustomerDocumentSource,
     34    ConCatProductSource, ConCatActiveProductSource,
     35    CustomerDocumentSource,
    3536    ProductOptionSourceFactory)
    3637
     
    332333    product_object = schema.Choice(
    333334        title = _(u'Product'),
    334         source = ConCatProductSource(),
     335        source = ConCatActiveProductSource(),
    335336        required = True,
    336337        )
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12580 r12585  
    113113        self.product.title = u'Our Sample Product'
    114114        self.product.contract_category = self._contract_category
    115         self.product.valid_from = date(2015, 12, 4)
     115        self.product.valid_from = date(2014, 12, 4)
    116116        self.product.tc_dict = {'en': u'Hello world'}
    117117        prodoption = ProductOption()
     
    12651265        self.assertEqual(
    12661266            self.browser.url, self.contracts_path + '/%s/selectproduct' % conid)
    1267         # SAM is in the correct contract_category ...
     1267        # SAM is in the correct contract_category
    12681268        self.assertTrue('<option value="SAM">' in self.browser.contents)
    1269         # ... but NOTSAM not.
    1270         self.assertFalse('<option value="LIC">' in self.browser.contents)
    12711269        # So far last_product_id is None.
    12721270        self.assertTrue(self.customer['contracts'][conid].last_product_id is None)
     
    13311329        product.title = u'Our License Product'
    13321330        product.contract_category = u'license'
     1331        product.valid_from = date(2014, 12, 4)
    13331332        self.app['products'].addProduct(product)
    13341333        # Customers can manage contracts under certain conditions
     
    13571356        # SAM is in the correct contract_category ...
    13581357        self.assertTrue('<option value="SAM">' in self.browser.contents)
    1359         # ... but NOTSAM not.
     1358        # ... but LIC not.
    13601359        self.assertFalse('<option value="LIC">' in self.browser.contents)
    13611360        # So far last_product_id is None.
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_interfaces.py

    r12351 r12585  
    2323import tempfile
    2424import shutil
     25from datetime import date
    2526from zope.component.hooks import setSite
    2627from zope.component import queryUtility, createObject
     
    2930from waeup.ikoba.interfaces import SUBMITTED
    3031from waeup.ikoba.customers.vocabularies import (
    31     ConCatProductSource, CustomerDocumentSource)
     32    ConCatProductSource, ConCatActiveProductSource, CustomerDocumentSource)
    3233from waeup.ikoba.testing import FunctionalLayer, FunctionalTestCase
    3334
     
    9697        self.assertEqual(result, u'SAM - Our Sample Product')
    9798
     99    def test_getValues_ConCatActiveProductSource(self):
     100        source = ConCatActiveProductSource()
     101        self.product.valid_from = date(2030, 12, 4)
     102        self.product.valid_to = None
     103        self.product.contract_category = u'sample'
     104        result = source.factory.getValues(self.contract)
     105        self.assertFalse(self.product in result)
     106        self.product.valid_from = None
     107        self.product.valid_to = date(2030, 12, 4)
     108        self.product.contract_category = u'sample'
     109        result = source.factory.getValues(self.contract)
     110        self.assertTrue(self.product in result)
     111        self.product.valid_from = None
     112        self.product.valid_to = date(2010, 12, 4)
     113        self.product.contract_category = u'sample'
     114        result = source.factory.getValues(self.contract)
     115        self.assertFalse(self.product in result)
     116        self.product.valid_from = date(2010, 12, 4)
     117        self.product.valid_to = None
     118        self.product.contract_category = u'sample'
     119        result = source.factory.getValues(self.contract)
     120        self.assertTrue(self.product in result)
     121
    98122    def test_getValues_CustomerDocumentSource(self):
    99123        source = CustomerDocumentSource()
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/vocabularies.py

    r12524 r12585  
    1919"""
    2020import grok
     21from datetime import date
    2122from zope.component import getUtility, queryUtility
    2223from zope.catalog.interfaces import ICatalog
     
    157158
    158159
     160class ConCatActiveProductSource(ConCatProductSource):
     161    """A contract category product source delivers all products
     162    which belong to a certain contract_category.
     163    """
     164
     165    def getValues(self, context):
     166        concat = getattr(context, 'contract_category', None)
     167        products = grok.getSite()['products'].values()
     168        if not concat:
     169            return products
     170        now = date.today()
     171        resultlist = [
     172            value for value in products
     173            if value.contract_category == concat
     174                and (not value.valid_from or value.valid_from <= now)
     175                and (not value.valid_to or value.valid_to >= now)
     176            ]
     177        return resultlist
     178
     179
    159180class CustomerDocumentSource(BasicContextualSourceFactory):
    160181    """A customer document source delivers all submitted and verified documents
Note: See TracChangeset for help on using the changeset viewer.