Ignore:
Timestamp:
18 Dec 2014, 14:44:30 (10 years ago)
Author:
Henrik Bettermann
Message:

Change contract_id generation algorithm. Use Universally Unique IDentifiers instead of consecutive numbers.

File:
1 edited

Legend:

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

    r12256 r12258  
    406406        return None
    407407
    408         #documents = self.getParent(row, site)
    409         #if documents is None:
    410         #    return None
    411         #document_id = row.get('document_id', None)
    412         #if document_id is None:
    413         #    return None
    414         #entry = documents.get(document_id)
    415         #return entry
    416 
    417408    def updateEntry(self, obj, row, site, filename):
    418409        """Update obj to the values given in row.
     
    496487        if contract_id is None:
    497488            return None
    498         entry = contracts.get(contract_id)
    499         return entry
     489        cat = queryUtility(ICatalog, name='contracts_catalog')
     490        results = list(cat.searchResults(contract_id=(contract_id, contract_id)))
     491        if results:
     492            return results[0]
     493        return None
    500494
    501495    def updateEntry(self, obj, row, site, filename):
    502496        """Update obj to the values given in row.
    503497        """
     498        # Remove contract_id from row if empty
     499        if 'contract_id' in row and row['contract_id'] in (None, IGNORE_MARKER):
     500            row.pop('contract_id')
    504501        items_changed = super(ContractProcessor, self).updateEntry(
    505502            obj, row, site, filename)
    506503        customer = self.getParent(row, site).__parent__
    507504        customer.__parent__.logger.info(
    508             '%s - %s - %s - updated: %s'
    509             % (self.name, filename, customer.customer_id, items_changed))
     505            '%s - %s - %s - %s - updated: %s'
     506            % (self.name, filename, customer.customer_id, obj.contract_id,
     507               items_changed))
    510508        return
    511509
    512510    def addEntry(self, obj, row, site):
    513511        parent = self.getParent(row, site)
    514         contract_id = row['contract_id'].strip('#')
    515         parent[contract_id] = obj
    516         # Reset _curr_con_id if contract_id has been imported
    517         site = grok.getSite()
    518         if row.get('contract_id', None) not in (None, IGNORE_MARKER):
    519             site._curr_con_id -= 1
     512        parent.addContract(obj)
    520513        return
    521514
     
    541534            if class_name != self.factory_name.strip('waeup.'):
    542535                errs.append(('class_name','wrong processor'))
    543         try:
    544             # Correct con_id counter. As the IConverter for contracts
    545             # creates contract objects that are not used afterwards, we
    546             # have to fix the site-wide con_id counter.
    547             site = grok.getSite()
    548             site._curr_con_id -= 1
    549         except (KeyError, TypeError, AttributeError):
    550                 pass
    551         # We have to check contract_id.
    552         contract_id = row.get('contract_id', None)
    553         if mode == 'create':
    554             if not contract_id:
    555                 contract_id = generate_contract_id()
    556                 conv_dict['contract_id'] = contract_id
    557                 return errs, inv_errs, conv_dict
    558             cat = queryUtility(ICatalog, name='contracts_catalog')
    559             results = list(
    560                 cat.searchResults(contract_id=(contract_id, contract_id)))
    561             if results:
    562                 # contract_id must not exist.
    563                 errs.append(('contract_id','id exists'))
    564         else:
    565             if not contract_id.startswith('c'):
    566                 errs.append(('contract_id','invalid format'))
    567536        return errs, inv_errs, conv_dict
Note: See TracChangeset for help on using the changeset viewer.