def _call_search_service(self, mapping_name, service_name, result_name): """ Calls the given search service for the global childpool :param mapping_name: Name of the action mapping to use the correct mapping. :param service_name: URL endpoint of the search service to call :param result_name: Name of the wrapping tag for the answer :return: """ mapping = base_mapping.new_onramp_mapping( self._name, self.env, mapping_name) params = mapping.get_connect_data(self) onramp = OnrampConnector() result = onramp.send_message(service_name, 'GET', None, params) if result['code'] == 200: self.nb_found = result['content'].get('NumberOfBeneficiaries', 0) mapping = base_mapping.new_onramp_mapping( 'compassion.global.child', self.env) for child_data in result['content'][result_name]: child_vals = mapping.get_vals_from_connect(child_data) child_vals['search_view_id'] = self.id self.global_child_ids += self.env[ 'compassion.global.child'].create(child_vals) else: raise Warning(result.get('content', result)['Error'])
def _call_search_service(self, mapping_name, service_name, result_name): """ Calls the given search service for the global childpool :param mapping_name: Name of the action mapping to use the correct mapping. :param service_name: URL endpoint of the search service to call :param result_name: Name of the wrapping tag for the answer :return: """ mapping = base_mapping.new_onramp_mapping(self._name, self.env, mapping_name) params = mapping.get_connect_data(self) onramp = OnrampConnector() result = onramp.send_message(service_name, 'GET', None, params) if result['code'] == 200: self.nb_found = result['content'].get('NumberOfBeneficiaries', 0) mapping = base_mapping.new_onramp_mapping( 'compassion.global.child', self.env) for child_data in result['content'][result_name]: child_vals = mapping.get_vals_from_connect(child_data) child_vals['search_view_id'] = self.id self.global_child_ids += self.env[ 'compassion.global.child'].create(child_vals) else: raise Warning(result.get('content', result)['Error'])
def intervention_hold_removal_notification(self, commkit_data): """ This function is automatically executed when a InterventionHoldRemovalNotification Message is received. It will convert the message from json to odoo format and then update the concerned records :param commkit_data contains the data of the message (json) :return list of intervention ids which are concerned by the message """ intervention_mapping = mapping.new_onramp_mapping( self._name, self.env, 'intervention_mapping') # Apparently this message contains a single dictionary, and not a # list of dictionaries, ihrn = commkit_data['InterventionHoldRemovalNotification'] # Remove problematic type as it is not needed and contains # erroneous data del ihrn['InterventionType_Name'] vals = intervention_mapping.get_vals_from_connect(ihrn) intervention_id = vals['intervention_id'] intervention = self.env['compassion.intervention'].search([ ('intervention_id', '=', intervention_id), ('hold_id', '=', vals['hold_id']) ]) if intervention: intervention.with_context(hold_update=False).write(vals) intervention.hold_cancelled() return [intervention.id]
def update_intervention_details_request(self, commkit_data): """This function is automatically executed when a UpdateInterventionDetailsRequest Message is received. It will convert the message from json to odoo format and then update the concerned records :param commkit_data contains the data of the message (json) :return list of intervention ids which are concerned by the message """ intervention_mapping = mapping.new_onramp_mapping( self._name, self.env, 'intervention_mapping') # actually commkit_data is a dictionary with a single entry which # value is a list of dictionary (for each record) interventionDetailsRequest = commkit_data['InterventionDetailsRequest'] intervention_local_ids = [] # For each dictionary, we update the corresponding record for idr in interventionDetailsRequest: vals = intervention_mapping.get_vals_from_connect(idr) intervention_id = vals['intervention_id'] intervention = self.env['compassion.intervention'].search([ ('intervention_id', '=', intervention_id) ]) intervention_local_ids.append(intervention.id) intervention.write(vals) return intervention_local_ids
def process_commkit(self, commkit_data): ''' This function is automatically executed when an Update Gift Message is received. It will convert the message from json to odoo format and then update the concerned records :param commkit_data contains the data of the message (json) :return list of gift ids which are concerned by the message ''' gift_update_mapping = mapping.new_onramp_mapping( self._name, self.env, 'create_update_gifts') # actually commkit_data is a dictionary with a single entry which # value is a list of dictionary (for each record) GiftUpdateRequestList = commkit_data['GiftUpdateRequestList'] gift_ids = [] changed_gifts = self # For each dictionary, we update the corresponding record for GiftUpdateRequest in GiftUpdateRequestList: vals = gift_update_mapping.\ get_vals_from_connect(GiftUpdateRequest) gift_id = vals['id'] gift_ids.append(gift_id) gift = self.env['sponsorship.gift'].browse([gift_id]) if vals.get('state', gift.state) != gift.state: changed_gifts += gift gift.write(vals) changed_gifts.filtered(lambda g: g.state == 'Delivered').\ _gift_delivered() changed_gifts.filtered(lambda g: g.state == 'Undeliverable').\ _gift_undeliverable() return gift_ids
def process_commkit(self, commkit_data): """ Update or Create the letter with given values. """ letter_mapping = mapping.new_onramp_mapping(self._name, self.env) letter_ids = list() process_letters = self for commkit in commkit_data.get('Responses', [commkit_data]): vals = letter_mapping.get_vals_from_connect(commkit) published_state = 'Published to Global Partner' is_published = vals.get('state') == published_state # Write/update letter kit_identifier = vals.get('kit_identifier') letter = self.search([('kit_identifier', '=', kit_identifier)]) if letter: # Avoid to publish twice a same letter is_published = is_published and letter.state != published_state letter.write(vals) else: if 'id' in vals: del vals['id'] letter = self.with_context(no_comm_kit=True).create(vals) if is_published: process_letters += letter letter_ids.append(letter.id) process_letters.process_letter() return letter_ids
def process_commkit(self, commkit_data): child_note_mapping = mapping.new_onramp_mapping( self._name, self.env, 'beneficiary_note') vals = child_note_mapping.get_vals_from_connect(commkit_data) child_note = self.create(vals) return [child_note.id]
def process_commkit(self, commkit_data): lifecycle_mapping = mapping.new_onramp_mapping(self._name, self.env, 'new_child_lifecyle') lifecycle_ids = list() for single_data in commkit_data.get('BeneficiaryLifecycleEventList', [commkit_data]): vals = lifecycle_mapping.get_vals_from_connect(single_data) lifecycle = self.create(vals) lifecycle_ids.append(lifecycle.id) return lifecycle_ids
def process_commkit(self, commkit_data): project_mapping = mapping.new_onramp_mapping(self._name, self.env, 'new_project_lifecyle') lifecycle_ids = list() for single_data in commkit_data.get('ICPLifecycleEventList', [commkit_data]): vals = project_mapping.get_vals_from_connect(single_data) lifecycle = self.create(vals) lifecycle_ids.append(lifecycle.id) lifecycle.project_id.status_date = fields.Date.today() return lifecycle_ids
def process_commkit(self, commkit_data): lifecycle_mapping = mapping.new_onramp_mapping( self._name, self.env, 'new_child_lifecyle') lifecycle_ids = list() for single_data in commkit_data.get('BeneficiaryLifecycleEventList', [commkit_data]): vals = lifecycle_mapping.get_vals_from_connect(single_data) lifecycle = self.create(vals) lifecycle_ids.append(lifecycle.id) return lifecycle_ids
def _process_connect_data(self, connect_data): # Replace odoo field id by connect field name if 'Field' in connect_data: field = self.env['ir.model.fields'].browse(connect_data['Field']) # Works only if field is defined in the mapping defined in context # (or default mapping) mapping_name = self.env.context.get('default_mapping_name', 'default') model_mapping = new_onramp_mapping(field.model, self.env, mapping_name) for connect_name, odoo_name in \ model_mapping.CONNECT_MAPPING.iteritems(): if odoo_name == field.name: connect_data['Field'] = connect_name break
def process_commkit(self, commkit_data): project_mapping = mapping.new_onramp_mapping( self._name, self.env, 'new_project_lifecyle') lifecycle_ids = list() for single_data in commkit_data.get('ICPLifecycleEventList', [commkit_data]): vals = project_mapping.get_vals_from_connect(single_data) lifecycle = self.create(vals) lifecycle_ids.append(lifecycle.id) lifecycle.project_id.status_date = fields.Date.today() return lifecycle_ids
def process_commkit(self, commkit_data): project_mapping = mapping.new_onramp_mapping(self._name, self.env, 'new_project_lifecyle') lifecycle_ids = list() for single_data in commkit_data.get('ICPLifecycleEventList', [commkit_data]): project = self.env['compassion.project'].search([ ('icp_id', '=', single_data['ICP_ID']) ]) if not project: project.create({'icp_id': single_data['ICP_ID']}) vals = project_mapping.get_vals_from_connect(single_data) lifecycle = self.create(vals) lifecycle_ids.append(lifecycle.id) lifecycle.project_id.status = vals['project_status'] lifecycle.project_id.status_date = fields.Date.today() return lifecycle_ids
def process_commkit(self, commkit_data): """ Update or Create the letter with given values. """ letter_mapping = mapping.new_onramp_mapping(self._name, self.env) letter_ids = list() for commkit in commkit_data.get('Responses', [commkit_data]): vals = letter_mapping.get_vals_from_connect(commkit) published_state = 'Published to Global Partner' is_published = vals.get('state') == published_state # Write/update letter kit_identifier = vals.get('kit_identifier') letter = self.search([('kit_identifier', '=', kit_identifier)]) if letter: # Avoid to publish twice a same letter is_published = is_published and letter.state != published_state letter.write(vals) else: letter = self.with_context(no_comm_kit=True).create(vals) if is_published: letter.process_letter() letter_ids.append(letter.id) return letter_ids
def process_commkit(self, commkit_data): child_assessment_mapping = mapping.new_onramp_mapping(self._name, self.env, "beneficiary_cdpr") vals = child_assessment_mapping.get_vals_from_connect(commkit_data) child_assessment = self.create(vals) return [child_assessment.id]