예제 #1
0
 def parse_data(self, instance, mapping, oerp_model, action=None):
     '''
     Converts Satchmo fields to OpenErp fields and returns data dictionary
     '''
     data = {}
     children = {}
     if mapping is None:
         raise MappingError('No mapping was specified')
     #loop though fields of mapping
     for oerp_field, satchmo_field in mapping.items():
         if isinstance(satchmo_field, dict):
             #mapping of a child model was found
             children[oerp_field] = satchmo_field
         elif oerp_field not in self._protected_tags:
             #normal field-to-field mapping
             try:
                 #only map field if current action is specified in field actions
                 if action in satchmo_field.actions:
                     #get field data
                     data[oerp_field] = satchmo_field.get_content(instance, oerp_model)
             except Exception as e:
                 raise MappingError(
                     'An error occured while mapping content %s: %s -- %s' % \
                     (oerp_field, satchmo_field, e))
     return (data, children)
예제 #2
0
 def get_children(self, mapping):
     '''
     Finds child models (and their mapping) of given mapping
     '''
     children = {}
     for oerp_field, satchmo_field in mapping.items():
         if isinstance(satchmo_field, dict):
             children[oerp_field] = satchmo_field
     return children