Ignore:
Timestamp:
1 Dec 2014, 09:59:14 (10 years ago)
Author:
Henrik Bettermann
Message:

Add sample contract interfaces with additional document field. Use these interfaces in form pages.

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

Legend:

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

    r12099 r12103  
    5151    ICustomer, ICustomersContainer, ICustomerRequestPW, ICustomersUtils,
    5252    ICustomerDocument, ICustomerDocumentsContainer, ICustomerCreate,
    53     ICustomerPDFDocument, IContractsContainer, IContract, IContractEdit
     53    ICustomerPDFDocument, IContractsContainer, IContract, IContractEdit,
     54    ISampleContract,
    5455    )
    5556from waeup.ikoba.customers.catalog import search
     
    11501151    grok.require('waeup.viewCustomer')
    11511152    grok.template('contractpage')
    1152     form_fields = grok.AutoFields(IContract).omit('last_transition_date')
    1153     pnav = 4
     1153    pnav = 4
     1154
     1155    @property
     1156    def form_fields(self):
     1157        return grok.AutoFields(self.context.form_fields_interface).omit(
     1158            'last_transition_date')
    11541159
    11551160    @property
     
    11651170    grok.require('waeup.manageCustomer')
    11661171    grok.template('contracteditpage')
    1167     form_fields = grok.AutoFields(IContract).omit('last_transition_date')
    11681172    pnav = 4
    11691173    deletion_warning = _('Are you sure?')
     1174
     1175    @property
     1176    def form_fields(self):
     1177        return grok.AutoFields(self.context.form_fields_interface).omit(
     1178            'last_transition_date')
    11701179
    11711180    @property
     
    11841193    grok.name('edit')
    11851194    grok.require('waeup.handleCustomer')
    1186     form_fields = grok.AutoFields(IContractEdit).omit('last_transition_date')
     1195
     1196    @property
     1197    def form_fields(self):
     1198        return grok.AutoFields(self.context.edit_form_fields_interface).omit(
     1199            'last_transition_date')
    11871200
    11881201    def update(self):
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/contracts.py

    r12099 r12103  
    3030    IContractsContainer, ICustomerNavigation,
    3131    IContract, IContractEdit, ICustomersUtils,
    32     )
     32    ISampleContract, ISampleContractEdit)
    3333from waeup.ikoba.customers.utils import generate_contract_id
    3434from waeup.ikoba.utils.helpers import attrs_to_fields
     
    6464
    6565    contract_category = None
     66
     67    form_fields_interface = None
     68
     69    edit_form_fields_interface = None
    6670
    6771    def __init__(self):
     
    142146    """
    143147
     148    grok.implements(ISampleContract, ISampleContractEdit, ICustomerNavigation)
     149
    144150    contract_category = 'sample'
     151
     152    form_fields_interface = ISampleContract
     153
     154    edit_form_fields_interface = ISampleContractEdit
    145155
    146156SampleContract = attrs_to_fields(SampleContract)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12098 r12103  
    2929
    3030from waeup.ikoba.customers.vocabularies import (
    31     contextual_reg_num_source, GenderSource, nats_vocab, ConCatProductSource)
     31    contextual_reg_num_source, GenderSource, nats_vocab,
     32    ConCatProductSource, CustomerDocumentSource)
    3233
    3334
     
    293294        )
    294295
     296
    295297class IContractEdit(IContract):
    296298    """Interface for editing contract data by customers.
     
    303305        required = True,
    304306        )
     307
     308
     309class ISampleContract(IContract):
     310    """A customer contract sample with document attached.
     311
     312    """
     313
     314    document = schema.Choice(
     315        title = _(u'Document'),
     316        source = CustomerDocumentSource(),
     317        required = False,
     318        )
     319
     320
     321class ISampleContractEdit(ISampleContract):
     322    """Interface for editing sample contract data by customers.
     323
     324    """
     325
     326    product = schema.Choice(
     327        title = _(u'Product'),
     328        source = ConCatProductSource(),
     329        required = True,
     330        )
     331
     332    document = schema.Choice(
     333        title = _(u'Document'),
     334        source = CustomerDocumentSource(),
     335        required = True,
     336        )
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_browser.py

    r12098 r12103  
    4040from waeup.ikoba.customers.interfaces import ICustomersUtils
    4141from waeup.ikoba.customers.customer import Customer
    42 from waeup.ikoba.interfaces import IUserAccount, IJobManager, APPROVED
     42from waeup.ikoba.interfaces import (
     43    IUserAccount, IJobManager, APPROVED, SUBMITTED)
    4344from waeup.ikoba.authentication import LocalRoleSetEvent
    4445from waeup.ikoba.tests.test_async import FunctionalAsyncTestCase
     
    111112        self.customer_id = customer.customer_id
    112113        self.customer = self.app['customers'][self.customer_id]
    113         document = createObject('waeup.CustomerSampleDocument')
    114         document.title = u'My first document'
    115         self.customer['documents'].addDocument(document)
    116         contract = createObject('waeup.SampleContract')
    117         contract.title = u'My first contract'
    118         self.customer['contracts'].addContract(contract)
     114        self.document = createObject('waeup.CustomerSampleDocument')
     115        self.document.title = u'My first document'
     116        self.customer['documents'].addDocument(self.document)
     117        self.contract = createObject('waeup.SampleContract')
     118        self.contract.title = u'My first contract'
     119        self.customer['contracts'].addContract(self.contract)
    119120
    120121        # Set password
     
    10741075        self.browser.getLink("Manage").click()
    10751076        self.browser.getControl(name="form.product").value = ['SAM']
    1076         self.browser.getControl(name="form.title").value = 'My second app'
     1077        self.browser.getControl(name="form.title").value = 'My second contract'
    10771078        self.browser.getControl("Save").click()
    10781079        self.assertTrue('Form has been saved.' in self.browser.contents)
     
    11401141        IWorkflowState(self.customer).setState(APPROVED)
    11411142        self.browser.open(self.contracts_path + '/c102/edit')
    1142         self.browser.getControl(name="form.title").value = 'My second app'
     1143        self.browser.getControl(name="form.title").value = 'My second contract'
    11431144        # SAM is in the correct contract_category ...
    11441145        self.assertTrue('<option value="SAM">' in self.browser.contents)
     
    11491150        self.browser.getControl(name="form.product").value = ['SAM']
    11501151        self.browser.getControl("Save").click()
    1151         # After saving the form, last_product_id is set.
     1152        # Document is a required field on edit form page.
     1153        self.assertTrue('Document: <span class="error">Required input is missing.</span>'
     1154            in self.browser.contents)
     1155        # But our document can't be selected because it's not submitted
     1156        self.assertFalse('My first document' in self.browser.contents)
     1157        IWorkflowState(self.document).setState(SUBMITTED)
     1158        self.browser.open(self.contracts_path + '/c102/edit')
     1159        self.browser.getControl(name="form.product").value = ['SAM']
     1160        self.browser.getControl(name="form.document").value = ['d101']
     1161        self.browser.getControl(name="form.title").value = 'My second contract'
     1162        self.browser.getControl("Save").click()
     1163        # After saving the form, last_product_id and other attributes are set
     1164        self.assertTrue('Form has been saved.' in self.browser.contents)
    11521165        self.assertEqual(self.customer['contracts']['c102'].last_product_id, 'SAM')
    1153         self.assertTrue('Form has been saved.' in self.browser.contents)
     1166        self.assertEqual(contract.title, 'My second contract')
     1167        self.assertEqual(contract.product, self.product)
     1168        self.assertEqual(contract.document, self.document)
    11541169        # Saving the form again does not unset last_product_id
    1155         self.assertEqual(contract.title, 'My second app')
     1170        self.browser.getControl(name="form.title").value = 'My third contract'
    11561171        self.browser.getControl("Save").click()
    11571172        self.assertEqual(self.customer['contracts']['c102'].last_product_id, 'SAM')
     
    11611176        # Customer can submit the form. The form is also saved.
    11621177        self.browser.getLink("Edit").click()
    1163         self.browser.getControl(name="form.title").value = 'My third app'
     1178        self.browser.getControl(name="form.title").value = 'My fourth contract'
    11641179        self.browser.getControl("Apply now").click()
    1165         self.assertEqual(contract.title, 'My third app')
     1180        self.assertEqual(contract.title, 'My fourth contract')
    11661181        self.assertEqual(contract.state, 'submitted')
    11671182        self.assertTrue('Contract State: submitted for approval' in self.browser.contents)
Note: See TracChangeset for help on using the changeset viewer.