Example #1
0
    def add_contact_link(self,
                         parent_contact_id,
                         child_contact_id,
                         relationship_id=7,
                         details=None):
        """Add an contact link to this contact

        :parent_contact_id: Contact ID of the parent in the relationship
        :child_contact_id: Contact ID of the child in the relationship
        :relationship_id: identifier for the type of relationship, default = Parent / Subsidiary
        :details: additional details to add context
        :return: the contact link
        :rtype: ContactLink
        """
        post_args = dict(FIRST_CONTACT_ID=child_contact_id,
                         SECOND_CONTACT_ID=parent_contact_id,
                         RELATIONSHIP_ID=relationship_id)

        if details:
            post_args['DETAILS'] = details

        json_obj = self.client.get_json(
            Config["Contacts"]["Endpoints"]["AddContactLink"]["Url"].format(
                id=force_str(self.CONTACT_ID)),
            http_method=Config["Contacts"]["Endpoints"]["AddContactLink"]
            ["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return ContactLink.from_json(json_obj)
Example #2
0
 def fetch(self):
     """Fetch all attributes for this Contact"""
     json_obj = self.client.get_json(
         Config["Contacts"]["Endpoints"]["Get"]["Url"].format(
             id=force_str(self.CONTACT_ID)),
         http_method=Config["Contacts"]["Endpoints"]["Get"]["Method"])
     self.from_json(json_obj=json_obj)
Example #3
0
    def add_opportunity_link(self, opportunity_id, role=None, details=None):
        """Add an opportunity link to this organisation

        :opportunity: Opportunity ID to link to this Contact
        :role: role in this Opportunity
        :details: additional details to add context
        :return: the link
        :rtype: Link
        """

        post_args = dict(CONTACT_ID=self.CONTACT_ID,
                         OPPORTUNITY_ID=opportunity_id)

        if role:
            post_args['ROLE'] = role

        if details:
            post_args['DETAILS'] = details

        json_obj = self.client.get_json(
            Config["Contacts"]["Endpoints"]["AddLink"]["Url"].format(
                id=force_str(self.CONTACT_ID)),
            http_method=Config["Contacts"]["Endpoints"]["AddLink"]["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return Link.from_json(json_obj)
Example #4
0
 def save(self):
     """ Create or update  """
     if self.CONTACT_ID is None:  # create a new contact
         json_obj = self.client.get_json(
             Config["Contacts"]["Endpoints"]["Add"]["Url"],
             http_method=Config["Contacts"]["Endpoints"]["Add"]["Method"],
             post_args=json.loads(self.to_json()))
         # Set initial data from Insightly, includes any updates
         self.from_json(json_obj=json_obj)
         self.CONTACT_ID = json_obj["CONTACT_ID"]
     else:  # update existing contact
         json_obj = self.client.get_json(
             Config["Contacts"]["Endpoints"]["Update"]["Url"].format(
                 id=force_str(self.CONTACT_ID)),
             http_method=Config["Contacts"]["Endpoints"]["Update"]
             ["Method"],
             post_args=json.loads(self.to_json()))
         # Set new data from Insightly, includes any updates
         self.from_json(json_obj=json_obj)
Example #5
0
    def update_contact_link(self,
                            contact_link_id,
                            parent_contact_id=None,
                            child_contact_id=None,
                            relationship_id=None,
                            details=None):
        """Update an Contact Link to this Contact
        :contact_link_id: the identifier for the contact link - note: must exist already in order to update
        :parent_contact_id: Contact ID of the parent in the relationship
        :child_contact_id: Contact ID of the child in the relationship
        :relationship_id: identifier for the type of relationship, default = Parent / Subsidiary
        :details: additional details to add context
        :return: the contact link
        :rtype: ContactLink
        """

        contact_link = self.get_contact_link(contact_link_id)

        if not contact_link:
            raise DoesNotExist("Contact Link does not exist", contact_link_id)

        post_args = dict(CONTACT_LINK_ID=contact_link_id,
                         FIRST_CONTACT_ID=child_contact_id if child_contact_id
                         else contact_link.FIRST_CONTACT_ID,
                         SECOND_CONTACT_ID=parent_contact_id if
                         parent_contact_id else contact_link.SECOND_CONTACT_ID,
                         RELATIONSHIP_ID=relationship_id
                         if relationship_id else contact_link.RELATIONSHIP_ID)

        if details:
            post_args['DETAILS'] = details
        if not details and contact_link.DETAILS:
            post_args['DETAILS'] = contact_link.DETAILS

        json_obj = self.client.get_json(
            Config["Contacts"]["Endpoints"]["UpdateContactLink"]["Url"].format(
                id=force_str(self.CONTACT_ID)),
            http_method=Config["Contacts"]["Endpoints"]["UpdateContactLink"]
            ["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return ContactLink.from_json(json_obj)
Example #6
0
    def update_opportunity_link(self,
                                link_id=None,
                                opportunity_id=None,
                                role=None,
                                details=None):
        """Update a opportunity link to this Contact
        :link_id: the identifier for the opportunity link - note: must exist already in order to update
        :opportunity_id: Opportunity ID to link to this Contact
        :role: role in this Opportunity
        :details: additional details to add context
        :return: the link
        :rtype: Link
        """

        link = self.get_link(link_id)

        if not link:
            raise DoesNotExist("Opportunity Link does not exist", link)

        post_args = dict(LINK_ID=link_id,
                         OPPORTUNITY_ID=opportunity_id
                         if opportunity_id else link.OPPORTUNITY_ID)

        if role:
            post_args['ROLE'] = role
        if not role and link.ROLE:
            post_args['ROLE'] = link.ROLE

        if details:
            post_args['DETAILS'] = details
        if not details and link.DETAILS:
            post_args['DETAILS'] = link.DETAILS

        json_obj = self.client.get_json(
            Config["Contacts"]["Endpoints"]["UpdateLink"]["Url"].format(
                id=force_str(self.CONTACT_ID)),
            http_method=Config["Contacts"]["Endpoints"]["UpdateLink"]
            ["Method"],
            post_args=post_args)
        # self.fetch()  # update current model
        return Link.from_json(json_obj)
Example #7
0
 def __repr__(self):
     return force_str(u'<Contact {}  {}>'.format(
         self.CONTACT_ID,
         force_str("{} {}".format(self.FIRST_NAME, self.LAST_NAME))))
Example #8
0
 def __repr__(self):
     return force_str(u'<Relationship {}  {}>'.format(
         self.RELATIONSHIP_ID, self.FORWARD_TITLE))
Example #9
0
 def __repr__(self):
     return force_str(u'<Organisation {}  {}>'.format(
         self.ORGANISATION_ID, self.ORGANISATION_NAME))
Example #10
0
 def __repr__(self):
     return force_str(u'<Opportunity {}  {}>'.format(
         self.OPPORTUNITY_ID, self.OPPORTUNITY_NAME))
Example #11
0
 def __repr__(self):
     return force_str(u'<CustomField {}  {}>'.format(
         self.CUSTOM_FIELD_ID, self.FIELD_VALUE))
Example #12
0
 def __repr__(self):
     return force_str(u'<OrganisationLink {}  {} --> {}>'.format(
         self.ORG_LINK_ID, self.SECOND_ORGANISATION_ID,
         self.FIRST_ORGANISATION_ID))
Example #13
0
 def __repr__(self):
     return force_str(u'<LINK {} ORGANISATION  {}>'.format(
         self.LINK_ID, self.ORGANISATION_ID))
Example #14
0
 def __repr__(self):
     return force_str(u'<OpportunityLink {}  {} --> {}>'.format(
         self.ORG_LINK_ID, self.SECOND_OPPORTUNITY_ID,
         self.FIRST_OPPORTUNITY_ID))
Example #15
0
 def __repr__(self):
     return force_str(u'<ContactLink {}  {} --> {}>'.format(
         self.ORG_LINK_ID, self.SECOND_CONTACT_ID, self.FIRST_CONTACT_ID))
Example #16
0
 def __repr__(self):
     return force_str(u'<Opportunity Category {}  {}>'.format(
         self.CATEGORY_ID, self.CATEGORY_NAME))
Example #17
0
 def __repr__(self):
     return force_str(u'<User {}  {} {}>'.format(self.USER_ID,
                                                 self.FIRST_NAME,
                                                 self.LAST_NAME))