コード例 #1
0
    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]
コード例 #2
0
    def process_commkit(self, commkit_data):
        """ Update or Create the letter with given values. """
        self.process_lock.acquire()
        try:
            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
                    if is_published or 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()
        finally:
            self.process_lock.release()
        return letter_ids
コード例 #3
0
    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)
        intervention_request = commkit_data.get(
            'InterventionDetailsRequest',
            commkit_data.get('InterventionAmendmentKitRequest')) or []
        intervention_local_ids = []
        # For each dictionary, we update the corresponding record
        for idr in intervention_request:
            vals = intervention_mapping.get_vals_from_connect(idr)
            intervention_id = vals['intervention_id']

            intervention = self.search([('intervention_id', '=',
                                         intervention_id)])
            if intervention:
                intervention_local_ids.append(intervention.id)
                intervention.with_context(hold_update=False).write(vals)
                intervention.message_post(_("The information of this "
                                            "intervention have been updated"),
                                          subject=(_(intervention.name +
                                                     "got an Update")),
                                          message_type='email',
                                          subtype='mail.mt_comment')

        return intervention_local_ids
コード例 #4
0
    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]
コード例 #5
0
    def process_commkit(self, commkit_data):
        """ Update or Create the letter with given values. """
        self.process_lock.acquire()
        try:
            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
                    if is_published or 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()
        finally:
            self.process_lock.release()
        return letter_ids
コード例 #6
0
 def _call_search_service(self,
                          mapping_name,
                          service_name,
                          result_name,
                          method='GET'):
     """
     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
     :param method: Method URL (GET or POST)
     :return:
     """
     mapping = base_mapping.new_onramp_mapping(self._name, self.env,
                                               mapping_name)
     params = mapping.get_connect_data(self)
     onramp = OnrampConnector()
     if method == 'POST':
         result = onramp.send_message(service_name, method, params)
     else:
         result = onramp.send_message(service_name, method, 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)
         if not result['content'][result_name]:
             raise UserError(_("No children found meeting criterias"))
         new_children = self.env['compassion.global.child']
         for child_data in result['content'][result_name]:
             child_vals = mapping.get_vals_from_connect(child_data)
             child_vals['search_view_id'] = self.id
             new_children += self.env['compassion.global.child'].create(
                 child_vals)
         restricted_children = new_children - new_children.filtered(
             'field_office_id.available_on_childpool')
         new_children -= restricted_children
         self.nb_restricted_children = len(restricted_children)
         restricted_children.unlink()
         self.global_child_ids += new_children
     else:
         error = result.get('content', result)['Error']
         if isinstance(error, dict):
             error = error.get('ErrorMessage')
         raise UserError(error)
コード例 #7
0
 def _call_search_service(self, mapping_name, service_name, result_name,
                          method='GET'):
     """
     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
     :param method: Method URL (GET or POST)
     :return:
     """
     mapping = base_mapping.new_onramp_mapping(
         self._name, self.env, mapping_name)
     params = mapping.get_connect_data(self)
     onramp = OnrampConnector()
     if method == 'POST':
         result = onramp.send_message(service_name, method, params)
     else:
         result = onramp.send_message(service_name, method, 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)
         if not result['content'][result_name]:
             raise UserError(_("No children found meeting criterias"))
         new_children = self.env['compassion.global.child']
         for child_data in result['content'][result_name]:
             child_vals = mapping.get_vals_from_connect(child_data)
             child_vals['search_view_id'] = self.id
             new_children += self.env['compassion.global.child'].create(
                 child_vals)
         restricted_children = new_children - new_children.filtered(
             'field_office_id.available_on_childpool')
         new_children -= restricted_children
         self.nb_restricted_children = len(restricted_children)
         restricted_children.unlink()
         self.global_child_ids += new_children
     else:
         error = result.get('content', result)['Error']
         if isinstance(error, dict):
             error = error.get('ErrorMessage')
         raise UserError(error)
コード例 #8
0
    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
コード例 #9
0
    def intervention_amendement_commitment(self, commkit_data):
        """This function is automatically executed when a
        InterventionAmendmentCommitmentNotification is received,
        it send a message to the follower of the Intervention,
        and update it
        :param commkit_data contains the data of the
               message (json)
        :return list of intervention ids which are concerned
                by the message """
        # sleep to prevent a concurence error
        time.sleep(10)
        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)
        interventionamendment = commkit_data.get(
            'InterventionAmendmentCommitmentNotification',
            commkit_data.get('InterventionAmendmentKitRequest', [{}])[0])
        intervention_local_ids = []

        v = intervention_mapping.get_vals_from_connect(interventionamendment)
        intervention_id = v['intervention_id']
        amendment_amount = interventionamendment[
            'AdditionalAmountRequestedUSD']
        intervention = self.env['compassion.intervention'].search([
            ('intervention_id', '=', intervention_id)
        ])

        if intervention:
            if amendment_amount:
                intervention.total_amendment += amendment_amount
            intervention.get_infos()
            intervention_local_ids.append(intervention.id)
            body = _("This intervention has been modified by amendment.")
            body += "<br/><ul><li>Amendment ID: {}</li>".format(
                interventionamendment['InterventionAmendment_ID'])
            body += "<li>Amendment Type: {}</li>".format(', '.join(
                interventionamendment.get('AmendmentType', [])))
            body += "<li>Amendment Reason: {}</li>".format(
                interventionamendment.get('ReasonsForAmendment', ''))
            body += "<li>Amendment Amount: {}</li>".format(amendment_amount)
            body += "<li>Hold ID: {}</li></ul>".format(
                interventionamendment.get('HoldID', ''))
            intervention.message_post(body,
                                      subject=_(intervention.name +
                                                ": Amendment received"),
                                      message_type='email',
                                      subtype='mail.mt_comment')

        return intervention_local_ids
コード例 #10
0
    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
コード例 #11
0
    def intervention_amendement_commitment(self, commkit_data):
        """This function is automatically executed when a
        InterventionAmendmentCommitmentNotification is received,
        it send a message to the follower of the Intervention,
        and update it
        :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)
        interventionamendment = commkit_data[
            'InterventionAmendmentCommitmentNotification']
        intervention_local_ids = []

        v = intervention_mapping.get_vals_from_connect(interventionamendment)
        intervention_id = v['intervention_id']
        amendment_amount = interventionamendment[
            'AdditionalAmountRequestedUSD']
        intervention = self.env['compassion.intervention'].search([
            ('intervention_id', '=', intervention_id)
        ])

        if intervention:
            intervention.total_amendment += amendment_amount
            intervention.get_infos()
            intervention_local_ids.append(intervention.id)
            body = _("This intervention has been modified by amendment.")
            body += "<br/><ul><li>Amendment ID: {}</li>".format(
                interventionamendment['InterventionAmendment_ID'])
            body += "<li>Amendment Amount: {}</li>".format(
                amendment_amount)
            body += "<li>Hold ID: {}</li></ul>".format(
                interventionamendment['HoldID'])
            intervention.message_post(
                body,
                subject=_(intervention.name + ": Amendment received"),
                message_type='email', subtype='mail.mt_comment')

        return intervention_local_ids
コード例 #12
0
    def create_intervention(self, commkit_data):
        intervention_mapping = mapping.new_onramp_mapping(
            self._name,
            self.env,
            'intervention_mapping')

        # Two messages can call this method. Try to find which one.
        intervention_details_request = commkit_data.get(
            'GPInitiatedInterventionHoldNotification',
            commkit_data.get('InterventionOptInHoldNotification')
        )

        intervention = self
        if intervention_details_request:
            vals = intervention_mapping.get_vals_from_connect(
                intervention_details_request)

            vals['total_cost'] = vals['hold_amount'] = float(
                vals['hold_amount'].replace("'", "").replace(",", ""))
            if not vals['secondary_owner']:
                del vals['secondary_owner']

            if 'service_level' not in vals:
                vals['service_level'] = 'Level 1'

            intervention_name = vals['name']

            if intervention_name.find('FY') != -1:
                split_name = intervention_name.split('FY')
                search_value = split_name[0] + 'FY' + str(int(split_name[1])-1)
                last_intervention = self.search([
                    ('name', '=', search_value)
                ])
                if last_intervention:
                    vals['product_template_id'] = \
                        last_intervention.product_template_id.id

            # By default we want to opt-in for next years
            vals['next_year_opt_in'] = True
            intervention = self.create(vals)

        return intervention.ids
コード例 #13
0
    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.last_update_date = fields.Date.today()

        return lifecycle_ids
コード例 #14
0
    def create_intervention(self, commkit_data):
        intervention_mapping = mapping.new_onramp_mapping(
            self._name, self.env, 'intervention_mapping')

        # Two messages can call this method. Try to find which one.
        intervention_details_request = commkit_data.get(
            'GPInitiatedInterventionHoldNotification',
            commkit_data.get('InterventionOptInHoldNotification'))

        intervention = self
        if intervention_details_request:
            vals = intervention_mapping.get_vals_from_connect(
                intervention_details_request)

            if 'service_level' not in vals:
                vals['service_level'] = 'Level 1'

            intervention = self.create(vals)

        return intervention.ids
コード例 #15
0
    def intervention_reporting_milestone(self, commkit_data):
        """This function is automatically executed when a
                InterventionReportingMilestoneRequestList is received,
                it send a message to the follower of the Intervention
                :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)
        milestones_data = commkit_data[
            'InterventionReportingMilestoneRequestList']
        intervention_local_ids = []

        for milestone in milestones_data:
            intervention_vals = intervention_mapping.get_vals_from_connect(
                milestone)
            milestone_id = milestone.get('InterventionReportingMilestone_ID')
            intervention_id = intervention_vals.get('intervention_id')
            intervention = self.search([
                ('intervention_id', '=', intervention_id)
            ])
            if intervention:
                intervention_local_ids.append(intervention.id)
                body = "A new milestone is available"
                if milestone_id:
                    milestone_url = INTERVENTION_PORTAL_URL + milestone_id
                    body += ' at <a href="{}" target="_blank">{}</a>.'.format(
                            milestone_url, milestone_url)
                intervention.message_post(
                    body,
                    subject=(_(intervention.name + ': New milestone '
                                                   'received.')),
                    message_type='email',
                    subtype='mail.mt_comment'
                )
        return intervention_local_ids
コード例 #16
0
    def intervention_reporting_milestone(self, commkit_data):
        """This function is automatically executed when a
                InterventionReportingMilestoneRequestList is received,
                it send a message to the follower of the Intervention
                :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)
        milestones_data = commkit_data[
            'InterventionReportingMilestoneRequestList']
        intervention_local_ids = []

        for milestone in milestones_data:
            intervention_vals = intervention_mapping.get_vals_from_connect(
                milestone)
            milestone_id = milestone.get('InterventionReportingMilestone_ID')
            intervention_id = intervention_vals.get('intervention_id')
            intervention = self.search([
                ('intervention_id', '=', intervention_id)
            ])
            if intervention:
                intervention_local_ids.append(intervention.id)
                body = "A new milestone is available"
                if milestone_id:
                    milestone_url = INTERVENTION_PORTAL_URL + milestone_id
                    body += ' at <a href="{}" target="_blank">{}</a>.'.format(
                            milestone_url, milestone_url)
                intervention.message_post(
                    body,
                    subject=(_(intervention.name + ': New milestone '
                                                   'received.')),
                    message_type='email',
                    subtype='mail.mt_comment'
                )
        return intervention_local_ids
コード例 #17
0
    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.last_update_date = fields.Date.today()

        return lifecycle_ids
コード例 #18
0
    def create_intervention(self, commkit_data):
        intervention_mapping = mapping.new_onramp_mapping(
            self._name,
            self.env,
            'intervention_mapping')

        # Two messages can call this method. Try to find which one.
        intervention_details_request = commkit_data.get(
            'GPInitiatedInterventionHoldNotification',
            commkit_data.get('InterventionOptInHoldNotification')
        )

        intervention = self
        if intervention_details_request:
            vals = intervention_mapping.get_vals_from_connect(
                intervention_details_request)

            if 'service_level' not in vals:
                vals['service_level'] = 'Level 1'

            intervention = self.create(vals)

        return intervention.ids
コード例 #19
0
    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.search([
                ('intervention_id', '=', intervention_id)
            ])
            if intervention:
                intervention_local_ids.append(intervention.id)
                intervention.with_context(hold_update=False).write(vals)
                intervention.message_post(_("The information of this "
                                          "intervention have been updated"),
                                          subject=(_(intervention.name +
                                                   "got an Update")),
                                          message_type='email',
                                          subtype='mail.mt_comment')

        return intervention_local_ids