Changeset 12633 for main/waeup.ikoba


Ignore:
Timestamp:
27 Feb 2015, 17:39:46 (10 years ago)
Author:
Henrik Bettermann
Message:

Copy over valid_from and valid_to from products when creating contract objects.

Fix ContractProcessorBase?. Do really allow to import tc_dict, valid_from, title and valid_to.

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  
    2929      name="CREATE" tal:attributes="value view/export_button" />
    3030  </div>
     31  <br /><br />
    3132  <div class="form-group">
    3233  <input type="submit" name="CANCEL" class="btn btn-default"
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/batching.py

    r12333 r12633  
    3131from zope.interface import Interface
    3232from zope.schema import getFields
     33from zope.formlib.interfaces import ConversionError
    3334from zope.component import queryUtility, getUtility, createObject
    3435from zope.event import notify
     
    3839    IBatchProcessor, FatalCSVError, IObjectConverter, IUserAccount,
    3940    IObjectHistory, IGNORE_MARKER)
    40 from waeup.ikoba.interfaces import IIkobaUtils
     41from waeup.ikoba.interfaces import IIkobaUtils, DELETION_MARKER, IGNORE_MARKER
    4142from waeup.ikoba.interfaces import MessageFactory as _
    4243from waeup.ikoba.customers.utils import generate_contract_id
     
    4748    IMPORTABLE_REGISTRATION_STATES, IMPORTABLE_REGISTRATION_TRANSITIONS)
    4849from waeup.ikoba.utils.batching import BatchProcessor
     50
     51DATE_FORMAT = '%Y-%m-%d'
     52
     53
     54def 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()
    4964
    5065
     
    481496
    482497    location_fields = []
    483     additional_fields = ['class_name']
     498    additional_fields = ['class_name', 'title',
     499                         'tc_dict', 'valid_from', 'valid_to']
    484500    additional_headers = ['class_name']
    485501
     
    551567            if class_name != self.factory_name.strip('waeup.'):
    552568                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
    553607        return errs, inv_errs, conv_dict
    554608
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser.py

    r12599 r12633  
    12711271    pnav = 4
    12721272
    1273     form_fields = grok.AutoFields(IContract).omit(
    1274         'product_object', 'contract_id', 'product_options')
    1275 
    12761273    @property
    12771274    def edit_contracts_allowed(self):
     
    13011298        # classes depending on the contype parameter given in form.
    13021299        contract = createObject('waeup.%s' % contype)
    1303         self.applyData(contract, **data)
    13041300        self.context.addContract(contract)
    13051301        contype = getUtility(ICustomersUtils).SELECTABLE_CONTYPES_DICT[contype]
     
    13391335        self.context.title = self.context.product_object.contract_autotitle
    13401336        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
    13411339        isCustomer = getattr(
    13421340            self.request.principal, 'user_type', None) == 'customer'
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/browser_templates/contractaddpage.pt

    r12548 r12633  
    1717        </td>
    1818      </tr>
    19       <tal:widgets content="structure provider:widgets" />
    2019    </tbody>
    2120  </table>
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/contracts.py

    r12580 r12633  
    7676        self.tc_dict = {}
    7777        self.title = None
     78        self.valid_to = None
     79        self.valid_from = None
    7880        return
    7981
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/interfaces.py

    r12585 r12633  
    301301    title = Attribute('Title generated by the associated product')
    302302    tc_dict = Attribute('Multilingual "Terms and Conditions" dict')
     303    valid_from = Attribute('Contract valid from')
     304    valid_to = Attribute('Contract valid to')
    303305
    304306    contract_id = schema.TextLine(
     
    364366    """
    365367
     368    #title = schema.TextLine(
     369    #    required = False,
     370    #    )
     371
     372    #tc_dict = schema.Dict(
     373    #    required = False,
     374    #    default = {},
     375    #    )
     376
    366377    product_options = schema.List(
    367         title = _(u'Options/Fees'),
    368378        value_type = ProductOptionField(),
    369379        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,[],{},
     1class_name,contract_id,reg_number,product_object,document_object,product_options,tc_dict,title,valid_from,valid_to
     2SampleContract,c3,1,SAM,DOC1,"[('Base Fee', '800.6', 'USD')]",{'en':'Hello World'},Nice Contract,2014-06-25#,2015-06-25#
     3SampleContract,c4,2,SAM,DOC1,[],,,,
     4SampleContract,c5,3,SAM,DOC1,[],,,,
     5SampleContract,,1,SAM,DOC1,[],,,,
     6SampleContract,c5,2,SAM,DOC1,[],,,,
     7SampleContract,c6,3,SAM,NONEXISTENT,[],,,,
     8SampleContract,c7,3,NONEXISTENT,DOC1,[],,,,
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_batching.py

    r12580 r12633  
    158158        contract.product_options = self.product.options
    159159        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
    160163        customer['contracts'].addContract(contract)
    161164        self.contract = contract
     
    498501        fail_file = open(fail_file).read()
    499502        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'
    504507            )
    505508        contract = self.processor.getEntry(dict(reg_number='1',
     
    512515        self.assertEqual(contract.product_options[0].currency, 'USD')
    513516        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'})
    515519        contract = self.processor.getEntry(dict(reg_number='3',
    516520            contract_id='c5'), self.app)
     
    523527        self.assertTrue(
    524528            '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, '
    526530            'product_options=[]' % conid
    527531            in logcontent)
  • main/waeup.ikoba/trunk/src/waeup/ikoba/customers/tests/test_export.py

    r12580 r12633  
    257257            'class_name,comment,contract_category,contract_id,document_object,'
    258258            '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'
    262263            )
    263264        return
     
    273274            'class_name,comment,contract_category,contract_id,document_object,'
    274275            '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'
    276278
    277279            'SampleContract,,sample,CON1,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    278280            'Contract created by system\'],,'
    279281            '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',
    281284            result
    282285            )
     
    293296            'class_name,comment,contract_category,contract_id,document_object,'
    294297            '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'
    296300
    297301            'SampleContract,,sample,CON1,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    298302            'Contract created by system\'],,'
    299303            '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',
    301306            result
    302307            )
     
    313318            'class_name,comment,contract_category,contract_id,document_object,'
    314319            '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'
    316322
    317323            'SampleContract,,sample,CON1,DOC1,[u\'2014-12-04 12:10:46 UTC - '
    318324            'Contract created by system\'],,'
    319325            '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.