Changeset 12499 for main/ikobacustom.pcn


Ignore:
Timestamp:
20 Jan 2015, 08:31:25 (10 years ago)
Author:
Henrik Bettermann
Message:

Add second batch of contract components which are so far a copy of the IRONContract components.

Location:
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn
Files:
8 edited

Legend:

Unmodified
Added
Removed
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/batching.py

    r12493 r12499  
    2626    IPCNCustomerJPGDocument,
    2727    IPCNCustomerPDFDocument,
    28     IRONContract)
     28    IRONContract,
     29    IROPContract)
    2930from ikobacustom.pcn.interfaces import MessageFactory as _
    3031
     
    6263    util_name = 'roncontractprocessor'
    6364    grok.name(util_name)
    64     name = _('PCN Customer Contract Processor')
     65    name = _('Retention of Name Contract Processor')
    6566    iface = IRONContract
    6667    factory_name = 'waeup.RONContract'
     68
     69class ROPContractProcessor(ContractProcessorBase):
     70    """A batch processor for IROPContract objects.
     71    """
     72    util_name = 'ropcontractprocessor'
     73    grok.name(util_name)
     74    name = _('Registration of Premises Contract Processor')
     75    iface = IROPContract
     76    factory_name = 'waeup.ROPContract'
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/contracts.py

    r12488 r12499  
    2828from ikobacustom.pcn.interfaces import MessageFactory as _
    2929from ikobacustom.pcn.customers.interfaces import (
    30     IRONContract, IRONContractEdit, IRONContractProcess)
     30    IRONContract, IRONContractEdit, IRONContractProcess,
     31    IROPContract, IROPContractEdit, IROPContractProcess)
    3132
    3233
     
    5253
    5354
    54 # Contracts must be importable. So we might need a factory.
    5555class RONContractFactory(grok.GlobalUtility):
    5656    """A factory for contracts.
     
    5959    grok.name(u'waeup.RONContract')
    6060    title = u"Create a new license contract.",
    61     description = u"This factory instantiates new license contract instances."
     61    description = u"This factory instantiates new contract instances."
    6262
    6363    def __call__(self, *args, **kw):
     
    6666    def getInterfaces(self):
    6767        return implementedBy(RONContract)
     68
     69
     70class ROPContract(ContractBase):
     71    """This is a sample contract.
     72    """
     73
     74    grok.implements(
     75        IROPContractProcess,
     76        IROPContract,
     77        IROPContractEdit,
     78        ICustomerNavigation)
     79
     80    contract_category = 'rop'
     81
     82    form_fields_interface = IROPContract
     83
     84    edit_form_fields_interface = IROPContractEdit
     85
     86    check_docs_interface = IROPContract
     87
     88ROPContract = attrs_to_fields(ROPContract)
     89
     90
     91class ROPContractFactory(grok.GlobalUtility):
     92    """A factory for contracts.
     93    """
     94    grok.implements(IFactory)
     95    grok.name(u'waeup.ROPContract')
     96    title = u"Create a new license contract.",
     97    description = u"This factory instantiates new contract instances."
     98
     99    def __call__(self, *args, **kw):
     100        return ROPContract(*args, **kw)
     101
     102    def getInterfaces(self):
     103        return implementedBy(ROPContract)
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/export.py

    r12484 r12499  
    2323from ikobacustom.pcn.customers.interfaces import (
    2424    IPCNCustomer, IPCNCustomerJPGDocument,
    25     IPCNCustomerPDFDocument, IRONContract)
     25    IPCNCustomerPDFDocument, IRONContract, IROPContract)
    2626from ikobacustom.pcn.interfaces import MessageFactory as _
    2727
     
    5555    grok.name('roncontracts')
    5656    iface = IRONContract
    57     title = _(u'PCN Customer License Contracts')
     57    title = _(u'Retention of Name Contracts')
    5858    class_name = 'RONContract'
     59
     60
     61class ROPContractExporter(ContractExporterBase):
     62    """Exporter for Contract instances.
     63    """
     64    grok.name('ropcontracts')
     65    iface = IROPContract
     66    title = _(u'Registration of Premises Contracts')
     67    class_name = 'ROPContract'
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/interfaces.py

    r12488 r12499  
    5454
    5555class IRONContract(IContract):
    56     """A Retention Of Name contract.
     56    """A Retention of Name contract.
    5757
    5858    """
     
    149149    #    required = True,
    150150    #    )
     151
     152
     153class IROPContract(IContract):
     154    """A Registration of Premises contract.
     155
     156    """
     157
     158    date_of_birth = FormattedDate(
     159        title = _(u'Date of Birth'),
     160        required = True,
     161        show_year = True,
     162        )
     163
     164    state_of_origin = schema.Choice(
     165        vocabulary = nats_vocab,
     166        title = _(u'State of Origin'),
     167        required = False,
     168        )
     169
     170    lga = schema.Choice(
     171        source = LGASource(),
     172        title = _(u'State / LGA'),
     173        required = True,
     174        )
     175
     176    year_qualification = schema.Choice(
     177        title = _(u'Year of Qualification'),
     178        required = True,
     179        values = year_range(),
     180        )
     181
     182    res_address = schema.Text(
     183        title = _(u'Residential Address'),
     184        required = True,
     185        )
     186
     187    res_address = schema.Text(
     188        title = _(u'Residential Address'),
     189        required = False,
     190        )
     191
     192    work_address = schema.Text(
     193        title = _(u'Work Address'),
     194        required = False,
     195        )
     196
     197    work_email = schema.ASCIILine(
     198        title = _(u'Work Email Address'),
     199        required = False,
     200        constraint=validate_email,
     201        )
     202
     203    work_phone = PhoneNumber(
     204        title = _(u'Work Phone'),
     205        description = u'',
     206        required = False,
     207        )
     208
     209    category_practice = schema.TextLine(
     210        title = _(u'Category of Practice'),
     211        description = _(u'academic, retail and dispensing, hospital, administrative, wholesale, importation, manufacturing, etc.'),
     212        required = False,
     213        )
     214
     215    superintendent = schema.Bool(
     216        title= _('Superintendent'),
     217        description= _('Tick box if you are a superintendent pharamcist.'),
     218        required = False,
     219        )
     220
     221    #document_object = schema.Choice(
     222    #    title = _(u'Document'),
     223    #    source = CustomerDocumentSource(),
     224    #    required = False,
     225    #    )
     226
     227class IROPContractProcess(IROPContract):
     228    """Interface for processing RON data.
     229    """
     230
     231    product_options = schema.List(
     232        title = _(u'Options/Fees'),
     233        value_type = ProductOptionField(),
     234        required = False,
     235        readonly = False,
     236        default = [],
     237        )
     238
     239class IROPContractEdit(IROPContract):
     240    """Interface for editing RON data by customers.
     241
     242    """
     243
     244    #document_object = schema.Choice(
     245    #    title = _(u'Document'),
     246    #    source = CustomerDocumentSource(),
     247    #    required = True,
     248    #    )
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_browser.py

    r12488 r12499  
    3434    PCNCustomerPDFDocumentExporter,
    3535    PCNCustomerJPGDocumentExporter,
    36     RONContractExporter)
     36    RONContractExporter,
     37    ROPContractExporter)
    3738from ikobacustom.pcn.customers.batching import (
    3839    PCNCustomerProcessor,
    3940    PCNCustomerPDFDocumentProcessor,
    4041    PCNCustomerJPGDocumentProcessor,
    41     RONContractProcessor)
     42    RONContractProcessor,
     43    ROPContractProcessor)
    4244from ikobacustom.pcn.testing import FunctionalLayer, samples_dir
    4345
     
    6870        customer['documents'].addDocument(document1)
    6971        customer['documents'].addDocument(document2)
    70         contract = createObject(u'waeup.RONContract')
    71         contract.tc_dict = {'en':u'Hello World'}
    72         customer['contracts'].addContract(contract)
     72        contract1 = createObject(u'waeup.RONContract')
     73        contract1.tc_dict = {'en':u'Hello World'}
     74        customer['contracts'].addContract(contract1)
     75        contract2 = createObject(u'waeup.ROPContract')
     76        contract2.tc_dict = {'en':u'Hello World'}
     77        customer['contracts'].addContract(contract2)
    7378        self.customer = customer
    7479        self.document1 = document1
    7580        self.document2 = document2
    76         self.contract = contract
     81        self.contract1 = contract1
     82        self.contract2 = contract2
    7783        self.outfile = os.path.join(self.workdir, 'myoutput.csv')
    7884        return
     
    206212        return
    207213
    208     def test_export_reimport_contracts(self):
     214    def test_export_reimport_roncontracts(self):
    209215        # we can export all contracts in a portal
    210216        # set values we can expect in export file
     
    222228            '[u\'2015-01-18 16:40:01 WAT - Contract created by system\'],,,,'
    223229            '[],,created,,,{\'en\': u\'Hello World\'},,K1000000,,,,\r\n'
    224             % self.contract.contract_id)
     230            % self.contract1.contract_id)
    225231        # We can reimport the file if we change the header
    226232        # (user_id -> customer_id). Not all columns are necessary.
     
    233239            '[u\'2014-12-21 22:26:00 WAT - Contract created by system\']'
    234240            ',,,[],created,{\'en\': u\'Hello World\'},,K1000000\r\n'
    235             % self.contract.contract_id)
     241            % self.contract1.contract_id)
    236242        result = processor.doImport(
    237243            self.outfile,
     
    244250        self.assertEqual(num_fail,1)
    245251        # We remove the original contract.
    246         del self.customer['contracts'][self.contract.contract_id]
     252        del self.customer['contracts'][self.contract1.contract_id]
     253        result = processor.doImport(
     254            self.outfile,
     255            ['class_name','contract_category','contract_id','document_object',
     256            'history','last_product_id','product_object','product_options',
     257            'state','tc_dict','title','customer_id'],
     258            mode='create')
     259        num_succ, num_fail, finished_path, failed_path = result
     260        self.assertEqual(num_fail,0)
     261        # We can import the same file in update mode.
     262        result = processor.doImport(
     263            self.outfile,
     264            ['class_name','contract_category','contract_id','document_object',
     265            'history','last_product_id','product_object','product_options',
     266            'state','tc_dict','title','customer_id'],
     267            mode='update')
     268        num_succ, num_fail, finished_path, failed_path = result
     269        self.assertEqual(num_succ,1)
     270        self.assertEqual(num_fail,0)
     271        return
     272
     273    def test_export_reimport_ropcontracts(self):
     274        # we can export all contracts in a portal
     275        # set values we can expect in export file
     276        self.setup_for_export()
     277        exporter = ROPContractExporter()
     278        exporter.export_all(self.app, self.outfile)
     279        result = open(self.outfile, 'rb').read()
     280        self.assertMatches(result,
     281            'category_practice,class_name,contract_category,contract_id,'
     282            'date_of_birth,history,last_product_id,lga,product_object,'
     283            'product_options,res_address,state,state_of_origin,superintendent,'
     284            'tc_dict,title,user_id,work_address,work_email,work_phone,'
     285            'year_qualification\r\n'
     286            ',ROPContract,rop,%s,,'
     287            '[u\'2015-01-18 16:40:01 WAT - Contract created by system\'],,,,'
     288            '[],,created,,,{\'en\': u\'Hello World\'},,K1000000,,,,\r\n'
     289            % self.contract2.contract_id)
     290        # We can reimport the file if we change the header
     291        # (user_id -> customer_id). Not all columns are necessary.
     292        processor = ROPContractProcessor()
     293        open(self.outfile, 'wb').write(
     294            'class_name,contract_category,contract_id,document_object,'
     295            'history,last_product_id,product_object,product_options,'
     296            'state,tc_dict,title,user_id\r\n'
     297            'ROPContract,rop,%s,,'
     298            '[u\'2014-12-21 22:26:00 WAT - Contract created by system\']'
     299            ',,,[],created,{\'en\': u\'Hello World\'},,K1000000\r\n'
     300            % self.contract2.contract_id)
     301        result = processor.doImport(
     302            self.outfile,
     303            ['class_name','contract_category','contract_id','document_object',
     304            'history','last_product_id','product_object','product_options',
     305            'state','tc_dict','title','customer_id'],
     306            mode='create')
     307        num, num_fail, finished_path, failed_path = result
     308        # The object exists.
     309        self.assertEqual(num_fail,1)
     310        # We remove the original contract.
     311        del self.customer['contracts'][self.contract2.contract_id]
    247312        result = processor.doImport(
    248313            self.outfile,
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_contract.py

    r12484 r12499  
    2929
    3030from ikobacustom.pcn.testing import (FunctionalLayer, FunctionalTestCase)
    31 from ikobacustom.pcn.customers.contracts import RONContract
    32 from ikobacustom.pcn.customers.interfaces import IRONContract
     31from ikobacustom.pcn.customers.contracts import RONContract, ROPContract
     32from ikobacustom.pcn.customers.interfaces import IRONContract, IROPContract
    3333
    3434
     
    4242        verify.verifyObject(IRONContract, RONContract())
    4343        verify.verifyObject(ICustomerNavigation, RONContract())
     44        verify.verifyObject(IROPContract, ROPContract())
     45        verify.verifyObject(ICustomerNavigation, ROPContract())
    4446        return
    4547
    4648    def test_addContract(self):
    4749        container = ContractsContainer()
    48         contract = createObject(u'waeup.RONContract')
    49         id = contract.contract_id
    50         container.addContract(contract)
    51         self.assertEqual(container[id], contract)
     50        contract1 = createObject(u'waeup.RONContract')
     51        id1 = contract1.contract_id
     52        container.addContract(contract1)
     53        self.assertEqual(container[id1], contract1)
    5254        self.assertRaises(TypeError, container.addContract, object())
    53         self.assertEqual(contract.class_name, 'RONContract')
     55        self.assertEqual(contract1.class_name, 'RONContract')
     56
     57        contract2 = createObject(u'waeup.ROPContract')
     58        id2 = contract2.contract_id
     59        container.addContract(contract2)
     60        self.assertEqual(container[id2], contract2)
     61        self.assertRaises(TypeError, container.addContract, object())
     62        self.assertEqual(contract2.class_name, 'ROPContract')
    5463        return
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/utils.py

    r12493 r12499  
    5555
    5656        'RONContract': _('Retention of Name on the Registrar'),
     57        'ROPContract': _('Registration of Premises'),
    5758        }
    5859
     
    6566        'pcncustomerjpgdocuments',
    6667        'pcncustomerpdfdocuments',
    67         'roncontracts')
     68        'roncontracts',
     69        'ropcontracts')
  • main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/utils/utils.py

    r12488 r12499  
    4747    CON_CATS_DICT = {
    4848        'ron': 'Retention of Name',
     49        'rop': 'Registration of Premises',
    4950        'no': 'no contract',
    5051        }
     
    6869        'pcncustomerjpgdocuments',
    6970        'pcncustomerpdfdocuments',
    70         'roncontracts')
     71        'roncontracts',
     72        'ropcontracts')
    7173
    7274    BATCH_PROCESSOR_NAMES = (
     
    7577        'pcncustomerpdfdocumentprocessor',
    7678        'roncontractprocessor',
     79        'ropcontractprocessor',
    7780        'pcnproductprocessor',
    7881        'pdfdocumentprocessor',
Note: See TracChangeset for help on using the changeset viewer.