Changeset 12499
- Timestamp:
- 20 Jan 2015, 08:31:25 (10 years ago)
- 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 26 26 IPCNCustomerJPGDocument, 27 27 IPCNCustomerPDFDocument, 28 IRONContract) 28 IRONContract, 29 IROPContract) 29 30 from ikobacustom.pcn.interfaces import MessageFactory as _ 30 31 … … 62 63 util_name = 'roncontractprocessor' 63 64 grok.name(util_name) 64 name = _(' PCN CustomerContract Processor')65 name = _('Retention of Name Contract Processor') 65 66 iface = IRONContract 66 67 factory_name = 'waeup.RONContract' 68 69 class 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 28 28 from ikobacustom.pcn.interfaces import MessageFactory as _ 29 29 from ikobacustom.pcn.customers.interfaces import ( 30 IRONContract, IRONContractEdit, IRONContractProcess) 30 IRONContract, IRONContractEdit, IRONContractProcess, 31 IROPContract, IROPContractEdit, IROPContractProcess) 31 32 32 33 … … 52 53 53 54 54 # Contracts must be importable. So we might need a factory.55 55 class RONContractFactory(grok.GlobalUtility): 56 56 """A factory for contracts. … … 59 59 grok.name(u'waeup.RONContract') 60 60 title = u"Create a new license contract.", 61 description = u"This factory instantiates new licensecontract instances."61 description = u"This factory instantiates new contract instances." 62 62 63 63 def __call__(self, *args, **kw): … … 66 66 def getInterfaces(self): 67 67 return implementedBy(RONContract) 68 69 70 class 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 88 ROPContract = attrs_to_fields(ROPContract) 89 90 91 class 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 23 23 from ikobacustom.pcn.customers.interfaces import ( 24 24 IPCNCustomer, IPCNCustomerJPGDocument, 25 IPCNCustomerPDFDocument, IRONContract )25 IPCNCustomerPDFDocument, IRONContract, IROPContract) 26 26 from ikobacustom.pcn.interfaces import MessageFactory as _ 27 27 … … 55 55 grok.name('roncontracts') 56 56 iface = IRONContract 57 title = _(u' PCN Customer License Contracts')57 title = _(u'Retention of Name Contracts') 58 58 class_name = 'RONContract' 59 60 61 class 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 54 54 55 55 class IRONContract(IContract): 56 """A Retention Of Namecontract.56 """A Retention of Name contract. 57 57 58 58 """ … … 149 149 # required = True, 150 150 # ) 151 152 153 class 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 227 class 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 239 class 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 34 34 PCNCustomerPDFDocumentExporter, 35 35 PCNCustomerJPGDocumentExporter, 36 RONContractExporter) 36 RONContractExporter, 37 ROPContractExporter) 37 38 from ikobacustom.pcn.customers.batching import ( 38 39 PCNCustomerProcessor, 39 40 PCNCustomerPDFDocumentProcessor, 40 41 PCNCustomerJPGDocumentProcessor, 41 RONContractProcessor) 42 RONContractProcessor, 43 ROPContractProcessor) 42 44 from ikobacustom.pcn.testing import FunctionalLayer, samples_dir 43 45 … … 68 70 customer['documents'].addDocument(document1) 69 71 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) 73 78 self.customer = customer 74 79 self.document1 = document1 75 80 self.document2 = document2 76 self.contract = contract 81 self.contract1 = contract1 82 self.contract2 = contract2 77 83 self.outfile = os.path.join(self.workdir, 'myoutput.csv') 78 84 return … … 206 212 return 207 213 208 def test_export_reimport_ contracts(self):214 def test_export_reimport_roncontracts(self): 209 215 # we can export all contracts in a portal 210 216 # set values we can expect in export file … … 222 228 '[u\'2015-01-18 16:40:01 WAT - Contract created by system\'],,,,' 223 229 '[],,created,,,{\'en\': u\'Hello World\'},,K1000000,,,,\r\n' 224 % self.contract .contract_id)230 % self.contract1.contract_id) 225 231 # We can reimport the file if we change the header 226 232 # (user_id -> customer_id). Not all columns are necessary. … … 233 239 '[u\'2014-12-21 22:26:00 WAT - Contract created by system\']' 234 240 ',,,[],created,{\'en\': u\'Hello World\'},,K1000000\r\n' 235 % self.contract .contract_id)241 % self.contract1.contract_id) 236 242 result = processor.doImport( 237 243 self.outfile, … … 244 250 self.assertEqual(num_fail,1) 245 251 # 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] 247 312 result = processor.doImport( 248 313 self.outfile, -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/tests/test_contract.py
r12484 r12499 29 29 30 30 from ikobacustom.pcn.testing import (FunctionalLayer, FunctionalTestCase) 31 from ikobacustom.pcn.customers.contracts import RONContract 32 from ikobacustom.pcn.customers.interfaces import IRONContract 31 from ikobacustom.pcn.customers.contracts import RONContract, ROPContract 32 from ikobacustom.pcn.customers.interfaces import IRONContract, IROPContract 33 33 34 34 … … 42 42 verify.verifyObject(IRONContract, RONContract()) 43 43 verify.verifyObject(ICustomerNavigation, RONContract()) 44 verify.verifyObject(IROPContract, ROPContract()) 45 verify.verifyObject(ICustomerNavigation, ROPContract()) 44 46 return 45 47 46 48 def test_addContract(self): 47 49 container = ContractsContainer() 48 contract = createObject(u'waeup.RONContract')49 id = contract.contract_id50 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) 52 54 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') 54 63 return -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/customers/utils.py
r12493 r12499 55 55 56 56 'RONContract': _('Retention of Name on the Registrar'), 57 'ROPContract': _('Registration of Premises'), 57 58 } 58 59 … … 65 66 'pcncustomerjpgdocuments', 66 67 'pcncustomerpdfdocuments', 67 'roncontracts') 68 'roncontracts', 69 'ropcontracts') -
main/ikobacustom.pcn/trunk/src/ikobacustom/pcn/utils/utils.py
r12488 r12499 47 47 CON_CATS_DICT = { 48 48 'ron': 'Retention of Name', 49 'rop': 'Registration of Premises', 49 50 'no': 'no contract', 50 51 } … … 68 69 'pcncustomerjpgdocuments', 69 70 'pcncustomerpdfdocuments', 70 'roncontracts') 71 'roncontracts', 72 'ropcontracts') 71 73 72 74 BATCH_PROCESSOR_NAMES = ( … … 75 77 'pcncustomerpdfdocumentprocessor', 76 78 'roncontractprocessor', 79 'ropcontractprocessor', 77 80 'pcnproductprocessor', 78 81 'pdfdocumentprocessor',
Note: See TracChangeset for help on using the changeset viewer.