Changeset 12633
- Timestamp:
- 27 Feb 2015, 17:39:46 (10 years ago)
- Location:
- main/waeup.ikoba/trunk/src/waeup/ikoba
- Files:
-
- 9 edited
Legend:
- Unmodified
- Added
- Removed
-
main/waeup.ikoba/trunk/src/waeup/ikoba/browser/templates/datacenterexportpage.pt
r11952 r12633 29 29 name="CREATE" tal:attributes="value view/export_button" /> 30 30 </div> 31 <br /><br /> 31 32 <div class="form-group"> 32 33 <input type="submit" name="CANCEL" class="btn btn-default" -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py
r12333 r12633 31 31 from zope.interface import Interface 32 32 from zope.schema import getFields 33 from zope.formlib.interfaces import ConversionError 33 34 from zope.component import queryUtility, getUtility, createObject 34 35 from zope.event import notify … … 38 39 IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount, 39 40 IObjectHistory, IGNORE_MARKER) 40 from waeup.ikoba.interfaces import IIkobaUtils 41 from waeup.ikoba.interfaces import IIkobaUtils, DELETION_MARKER, IGNORE_MARKER 41 42 from waeup.ikoba.interfaces import MessageFactory as _ 42 43 from waeup.ikoba.customers.utils import generate_contract_id … … 47 48 IMPORTABLE_REGISTRATION_STATES, IMPORTABLE_REGISTRATION_TRANSITIONS) 48 49 from waeup.ikoba.utils.batching import BatchProcessor 50 51 DATE_FORMAT = '%Y-%m-%d' 52 53 54 def date_to_field(input): 55 # In import files we can use the hash symbol at the end of a 56 # date string to avoid annoying automatic date transformation 57 # by Excel or Calc 58 input = input.strip('#') 59 try: 60 value = datetime.strptime(input, DATE_FORMAT) 61 except (ValueError, IndexError), v: 62 raise ConversionError("Invalid datetime data", v) 63 return value.date() 49 64 50 65 … … 481 496 482 497 location_fields = [] 483 additional_fields = ['class_name'] 498 additional_fields = ['class_name', 'title', 499 'tc_dict', 'valid_from', 'valid_to'] 484 500 additional_headers = ['class_name'] 485 501 … … 551 567 if class_name != self.factory_name.strip('waeup.'): 552 568 errs.append(('class_name','wrong processor')) 569 tc_dict = row.get('tc_dict', None) 570 # We need to check tc_dict, valid_to and valid_from because they 571 # are not schema fields are thus not checked by the 572 # DefaultObjectConverter. 573 while True: 574 if tc_dict in (IGNORE_MARKER, None, {}, ''): 575 break 576 if tc_dict == DELETION_MARKER: 577 conv_dict['tc_dict'] = None 578 break 579 try: 580 tc_dict = eval(tc_dict) 581 conv_dict['tc_dict'] = tc_dict 582 break 583 except SyntaxError: 584 errs.append(('tc_dict','syntax error')) 585 break 586 if not isinstance(tc_dict, dict): 587 errs.append(('tc_dict','not a dictionary')) 588 break 589 valid_from = row.get('valid_from', None) 590 while True: 591 if valid_from in (IGNORE_MARKER, None, ''): 592 break 593 try: 594 date = date_to_field(valid_from) 595 except ConversionError: 596 errs.append(('valid_from','invalid date format')) 597 break 598 valid_to = row.get('valid_to', None) 599 while True: 600 if valid_to in (IGNORE_MARKER, None, ''): 601 break 602 try: 603 date = date_to_field(valid_to) 604 except ConversionError: 605 errs.append(('valid_to','invalid date format')) 606 break 553 607 return errs, inv_errs, conv_dict 554 608 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py
r12599 r12633 1271 1271 pnav = 4 1272 1272 1273 form_fields = grok.AutoFields(IContract).omit(1274 'product_object', 'contract_id', 'product_options')1275 1276 1273 @property 1277 1274 def edit_contracts_allowed(self): … … 1301 1298 # classes depending on the contype parameter given in form. 1302 1299 contract = createObject('waeup.%s' % contype) 1303 self.applyData(contract, **data)1304 1300 self.context.addContract(contract) 1305 1301 contype = getUtility(ICustomersUtils).SELECTABLE_CONTYPES_DICT[contype] … … 1339 1335 self.context.title = self.context.product_object.contract_autotitle 1340 1336 self.context.tc_dict = self.context.product_object.tc_dict 1337 self.context.valid_from = self.context.product_object.valid_from 1338 self.context.valid_to = self.context.product_object.valid_to 1341 1339 isCustomer = getattr( 1342 1340 self.request.principal, 'user_type', None) == 'customer' -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/contractaddpage.pt
r12548 r12633 17 17 </td> 18 18 </tr> 19 <tal:widgets content="structure provider:widgets" />20 19 </tbody> 21 20 </table> -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/contracts.py
r12580 r12633 76 76 self.tc_dict = {} 77 77 self.title = None 78 self.valid_to = None 79 self.valid_from = None 78 80 return 79 81 -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py
r12585 r12633 301 301 title = Attribute('Title generated by the associated product') 302 302 tc_dict = Attribute('Multilingual "Terms and Conditions" dict') 303 valid_from = Attribute('Contract valid from') 304 valid_to = Attribute('Contract valid to') 303 305 304 306 contract_id = schema.TextLine( … … 364 366 """ 365 367 368 #title = schema.TextLine( 369 # required = False, 370 # ) 371 372 #tc_dict = schema.Dict( 373 # required = False, 374 # default = {}, 375 # ) 376 366 377 product_options = schema.List( 367 title = _(u'Options/Fees'),368 378 value_type = ProductOptionField(), 369 379 required = False, -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/sample_contract_data.csv
r12580 r12633 1 class_name,contract_id,reg_number,product_object,document_object,product_options,tc_dict,title 2 SampleContract,c3,1,SAM,DOC1,"[('Base Fee', '800.6', 'USD')]",{'en':'Hello World'},Nice Contract 3 SampleContract,c4,2,SAM,DOC1,[], {},4 SampleContract,c5,3,SAM,DOC1,[], {},5 SampleContract,,1,SAM,DOC1,[], {},6 SampleContract,c5,2,SAM,DOC1,[], {},7 SampleContract,c6,3,SAM,NONEXISTENT,[], {},8 SampleContract,c7,3,NONEXISTENT,DOC1,[], {},1 class_name,contract_id,reg_number,product_object,document_object,product_options,tc_dict,title,valid_from,valid_to 2 SampleContract,c3,1,SAM,DOC1,"[('Base Fee', '800.6', 'USD')]",{'en':'Hello World'},Nice Contract,2014-06-25#,2015-06-25# 3 SampleContract,c4,2,SAM,DOC1,[],,,, 4 SampleContract,c5,3,SAM,DOC1,[],,,, 5 SampleContract,,1,SAM,DOC1,[],,,, 6 SampleContract,c5,2,SAM,DOC1,[],,,, 7 SampleContract,c6,3,SAM,NONEXISTENT,[],,,, 8 SampleContract,c7,3,NONEXISTENT,DOC1,[],,,, -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py
r12580 r12633 158 158 contract.product_options = self.product.options 159 159 contract.tc_dict = {'en': u'Hello world'} 160 contract.valid_from = datetime.date(2014, 2, 4) 161 contract.valid_to = datetime.date(2014, 12, 4) 162 160 163 customer['contracts'].addContract(contract) 161 164 self.contract = contract … … 498 501 fail_file = open(fail_file).read() 499 502 self.assertEqual(fail_file, 500 'reg_number, contract_id,title,class_name,product_object,tc_dict,document_object,product_options,--ERRORS--\r\n'501 '2, c5,,SampleContract,SAM,{},DOC1,[],This object already exists. Skipping.\r\n'502 '3, c6,,SampleContract,SAM,{},NONEXISTENT,[],document_object: Invalid value\r\n'503 '3, c7,,SampleContract,NONEXISTENT,{},DOC1,[],product_object: Invalid value\r\n'503 'reg_number,valid_from,contract_id,title,class_name,valid_to,product_object,tc_dict,document_object,product_options,--ERRORS--\r\n' 504 '2,,c5,,SampleContract,,SAM,,DOC1,[],This object already exists. Skipping.\r\n' 505 '3,,c6,,SampleContract,,SAM,,NONEXISTENT,[],document_object: Invalid value\r\n' 506 '3,,c7,,SampleContract,,NONEXISTENT,,DOC1,[],product_object: Invalid value\r\n' 504 507 ) 505 508 contract = self.processor.getEntry(dict(reg_number='1', … … 512 515 self.assertEqual(contract.product_options[0].currency, 'USD') 513 516 self.assertEqual(contract.contract_id, 'c3') 514 self.assertEqual(contract.tc_dict, u"{'en':'Hello World'}") 517 self.assertEqual(contract.title, u'Nice Contract') 518 self.assertEqual(contract.tc_dict, {'en':'Hello World'}) 515 519 contract = self.processor.getEntry(dict(reg_number='3', 516 520 contract_id='c5'), self.app) … … 523 527 self.assertTrue( 524 528 'INFO - system - Customer Sample Contract Processor - sample_contract_data - ' 525 'X666666 - %s - updated: title=, product_object=SAM, tc_dict={}, document_object=DOC1, '529 'X666666 - %s - updated: valid_from=, title=, valid_to=, product_object=SAM, tc_dict=, document_object=DOC1, ' 526 530 'product_options=[]' % conid 527 531 in logcontent) -
main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py
r12580 r12633 257 257 'class_name,comment,contract_category,contract_id,document_object,' 258 258 'history,last_product_id,' 259 'product_object,product_options,state,tc_dict,title,user_id\r\n' 260 261 'SampleContract,,sample,CON1,,[],,,[],,{},,\r\n' 259 'product_object,product_options,state,tc_dict,title,user_id,' 260 'valid_from,valid_to\r\n' 261 262 'SampleContract,,sample,CON1,,[],,,[],,{},,,,\r\n' 262 263 ) 263 264 return … … 273 274 'class_name,comment,contract_category,contract_id,document_object,' 274 275 'history,last_product_id,' 275 'product_object,product_options,state,tc_dict,title,user_id\r\n' 276 'product_object,product_options,state,tc_dict,title,user_id,' 277 'valid_from,valid_to\r\n' 276 278 277 279 'SampleContract,,sample,CON1,DOC1,[u\'2014-12-04 12:10:46 UTC - ' 278 280 'Contract created by system\'],,' 279 281 'SAM,"[(u\'Base Fee\', u\'800.6\', u\'USD\')]",' 280 'created,{\'en\': u\'Hello world\'},,A111111\r\n', 282 'created,{\'en\': u\'Hello world\'},,A111111,' 283 '2014-02-04#,2014-12-04#\r\n', 281 284 result 282 285 ) … … 293 296 'class_name,comment,contract_category,contract_id,document_object,' 294 297 'history,last_product_id,' 295 'product_object,product_options,state,tc_dict,title,user_id\r\n' 298 'product_object,product_options,state,tc_dict,title,user_id,' 299 'valid_from,valid_to\r\n' 296 300 297 301 'SampleContract,,sample,CON1,DOC1,[u\'2014-12-04 12:10:46 UTC - ' 298 302 'Contract created by system\'],,' 299 303 'SAM,"[(u\'Base Fee\', u\'800.6\', u\'USD\')]",' 300 'created,{\'en\': u\'Hello world\'},,A111111\r\n', 304 'created,{\'en\': u\'Hello world\'},,A111111,' 305 '2014-02-04#,2014-12-04#\r\n', 301 306 result 302 307 ) … … 313 318 'class_name,comment,contract_category,contract_id,document_object,' 314 319 'history,last_product_id,' 315 'product_object,product_options,state,tc_dict,title,user_id\r\n' 320 'product_object,product_options,state,tc_dict,title,user_id,' 321 'valid_from,valid_to\r\n' 316 322 317 323 'SampleContract,,sample,CON1,DOC1,[u\'2014-12-04 12:10:46 UTC - ' 318 324 'Contract created by system\'],,' 319 325 'SAM,"[(u\'Base Fee\', u\'800.6\', u\'USD\')]",' 320 'created,{\'en\': u\'Hello world\'},,A111111\r\n', 321 result 322 ) 323 return 324 326 'created,{\'en\': u\'Hello world\'},,A111111,' 327 '2014-02-04#,2014-12-04#\r\n', 328 result 329 ) 330 return 331
Note: See TracChangeset for help on using the changeset viewer.