zoho crm django code example

Example: Django Zoho CRM Create

Copy to Clipboard
# Create Records
# --------------
def create_records(self):
    try:
        record_ins_list = list()
        for i in range(0, 2):
            record = zcrmsdk.ZCRMRecord.get_instance('Invoices')  # Module API Name
            record.set_field_value('Subject', 'Invoice' + str(
                i))  # This method use to set FieldApiName and value similar to all other FieldApis and Custom field
            record.set_field_value('Account_Name', 'account_name')
            record.set_field_value('Price_Book_Name', 'book_name')
            record.set_field_value('Pricing_Model', 'Flat')
            record.set_field_value('Event_Title', 'Title')
            record.set_field_value('Start_DateTime', '2018-09-04T15:52:21+05:30')
            record.set_field_value('End_DateTime', '2019-01-04T15:52:21+05:30')
            record.set_field_value('Product_Name', 'product_name1')
            user = zcrmsdk.ZCRMUser.get_instance(3477061000, 'Owner name')  # user id and user name
            record.set_field_value('Owner', user)

            # Following methods are being used only by Inventory modules
            taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")

            record.tax_list.append(taxIns)

            pricing = zcrmsdk.ZCRMPriceBookPricing(None)
            pricing.to_range = 5
            pricing.from_range = 1
            pricing.discount = 0
            record.price_details.append(pricing)

            pricing = zcrmsdk.ZCRMPriceBookPricing(None)
            pricing.to_range = 11
            pricing.from_range = 6
            pricing.discount = 1
            record.price_details.append(pricing)

            pricing = zcrmsdk.ZCRMPriceBookPricing(None)
            pricing.to_range = 17
            pricing.from_range = 12
            pricing.discount = 2
            record.price_details.append(pricing)

            # participants = zcrmsdk.ZCRMEventParticipant(3477061000000,'contact') # Contacts record id and participant type
            # record.participants.append(participants)

            # participants = zcrmsdk.ZCRMEventParticipant('[email protected]', 'email')
            # participants.email = '[email protected]'
            # participants.name = 'username'
            # participants.is_invited = 'true'
            # record.participants.append(participants)

            line_item = zcrmsdk.ZCRMInventoryLineItem.get_instance(
                zcrmsdk.ZCRMRecord.get_instance('Products', 347706100))  # module api name and record id
            line_item.discount = 10
            line_item.list_price = 8
            line_item.description = 'Product Description'
            line_item.quantity = 100
            line_item.tax_amount = 2.5
            taxIns = zcrmsdk.ZCRMTax.get_instance("Vat")
            taxIns.percentage = 5
            line_item.line_tax.append(taxIns)
            record.add_line_item(line_item)

            line_tax = []
            line_tax_row1 = {}
            line_tax_row1['percentage'] = 12.5
            line_tax_row1['name'] = 'Sales Tax'
            line_tax.append(line_tax_row1)
            line_tax_row2 = {}
            line_tax_row2['percentage'] = 8.5
            line_tax_row2['name'] = 'Common Tax'
            line_tax.append(line_tax_row2)

            record.set_field_value('$line_tax', line_tax)
            record_ins_list.append(record)

        # Actions to be triggered
        trigger = ["approval", "workflow", "blueprint"]
        # Process to be run
        process = ["review_process"]
        # To pass Lead Assignment Rule ID
        lar_id = "3477061000101"

        resp = zcrmsdk.ZCRMModule.get_instance('Invoices').create_records(record_ins_list=record_ins_list, trigger=trigger, process=process, lar_id=lar_id)
        print(resp.status_code)
        entity_responses = resp.bulk_entity_response
        for entity_response in entity_responses:
            print(entity_response.details)
            print(entity_response.status)
            print(entity_response.message)
            print(entity_response.data.entity_id)
            print(entity_response.data.created_by.id)
            print(entity_response.data.created_time)
            print(entity_response.data.modified_by.id)
            print("\n\n")
    except zcrmsdk.ZCRMException as ex:
        print(ex.status_code)
        print(ex.error_message)
        print(ex.error_code)
        print(ex.error_details)
        print(ex.error_content)

Tags:

Misc Example