예제 #1
0
    def update_base_currency():
        """
        This method is used to update base currency details.
        """

        # Get instance of CurrenciesOperations Class
        currencies_operations = CurrenciesOperations()

        # Get instance of BaseCurrencyWrapper Class that will contain the request body
        request = BaseCurrencyWrapper()

        # Get instance of Currency Class
        currency = ZCRMCurrency()

        # To set currency Id
        currency.set_id(3409643000002293001)

        # To set the position of the ISO code in the currency.
        # True: Display ISO code before the currency value.
        # False: Display ISO code after the currency value.
        currency.set_prefix_symbol(True)

        # To set the symbol of the currency.
        currency.set_symbol("Af")

        # To set the rate at which the currency has to be exchanged for home currency.
        currency.set_exchange_rate("1.000000000")

        # To set the status of the currency.
        # True: The currency is active.
        # False: The currency is inactive.
        currency.set_is_active(True)

        format = Format()

        # It can be a Period or Comma, depending on the currency.
        format.set_decimal_separator(Choice('Period'))

        # It can be a Period, Comma, or Space, depending on the currency.
        format.set_thousand_separator(Choice('Comma'))

        # To set the number of decimal places allowed for the currency. It can be 0, 2, or 3.
        format.set_decimal_places(Choice('3'))

        # To set the format of the currency
        currency.set_format(format)

        # Set the Currency in BodyWrapper instance
        request.set_base_currency(currency)

        # Call update_base_currency method that takes BaseCurrencyWrapper instance as parameter
        response = currencies_operations.update_base_currency(request)

        if response is not None:

            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected BaseCurrencyActionWrapper instance is received.
                if isinstance(response_object, BaseCurrencyActionWrapper):

                    # Get the obtained ActionResponse instance
                    action_response = response_object.get_base_currency()

                    # Check if the request is successful
                    if isinstance(action_response, SuccessResponse):

                        # Get the Status
                        print("Status: " +
                              action_response.get_status().get_value())

                        # Get the Code
                        print("Code: " +
                              action_response.get_code().get_value())

                        print("Details")

                        # Get the details dict
                        details = action_response.get_details()

                        for key, value in details.items():
                            print(key + ' : ' + str(value))

                        # Get the Message
                        print("Message: " +
                              action_response.get_message().get_value())

                    # Check if the request returned an exception
                    elif isinstance(action_response, APIException):

                        # Get the Status
                        print("Status: " +
                              action_response.get_status().get_value())

                        # Get the Code
                        print("Code: " +
                              action_response.get_code().get_value())

                        print("Details")

                        # Get the details dict
                        details = action_response.get_details()

                        for key, value in details.items():
                            print(key + ' : ' + str(value))

                        # Get the Message
                        print("Message: " +
                              action_response.get_message().get_value())

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):

                    # Get the Status
                    print("Status: " +
                          response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " +
                          response_object.get_message().get_value())
예제 #2
0
    def add_currencies():
        """
        This method is used to add new currencies to your organization.
        """

        # Get instance of CurrenciesOperations Class
        currencies_operations = CurrenciesOperations()

        # Get instance of BodyWrapper Class that will contain the request body
        request = BodyWrapper()

        # List to hold Currency instances
        currencies_list = []

        # Get instance of Currency Class
        currency = ZCRMCurrency()

        # To set the position of the ISO code in the currency.
        # True: Display ISO code before the currency value.
        # False: Display ISO code after the currency value.
        currency.set_prefix_symbol(True)

        # To set the name of the currency.
        currency.set_name("Angolan Kwanza - AOA")

        # To set the ISO code of the currency.
        currency.set_iso_code("AOA")

        # To set the symbol of the currency.
        currency.set_symbol("Kz")

        # To set the rate at which the currency has to be exchanged for home currency.
        currency.set_exchange_rate("20.")

        # To set the status of the currency.
        # True: The currency is active.
        # False: The currency is inactive.
        currency.set_is_active(True)

        format = Format()

        # It can be a Period or Comma, depending on the currency.
        format.set_decimal_separator(Choice('Period'))

        # It can be a Period, Comma, or Space, depending on the currency.
        format.set_thousand_separator(Choice('Comma'))

        # To set the number of decimal places allowed for the currency. It can be 0, 2, or 3.
        format.set_decimal_places(Choice('2'))

        # To set the format of the currency
        currency.set_format(format)

        currencies_list.append(currency)

        # Set the list to Currency in BodyWrapper instance
        request.set_currencies(currencies_list)

        # Call add_currencies method that takes BodyWrapper instance as parameter
        response = currencies_operations.add_currencies(request)

        if response is not None:

            # Get the status code from response
            print('Status Code: ' + str(response.get_status_code()))

            # Get object from response
            response_object = response.get_object()

            if response_object is not None:

                # Check if expected ActionWrapper instance is received.
                if isinstance(response_object, ActionWrapper):

                    # Get the obtained ActionResponse instances
                    action_response_list = response_object.get_currencies()

                    for action_response in action_response_list:

                        # Check if the request is successful
                        if isinstance(action_response, SuccessResponse):

                            # Get the Status
                            print("Status: " +
                                  action_response.get_status().get_value())

                            # Get the Code
                            print("Code: " +
                                  action_response.get_code().get_value())

                            print("Details")

                            # Get the details dict
                            details = action_response.get_details()

                            for key, value in details.items():
                                print(key + ' : ' + str(value))

                            # Get the Message
                            print("Message: " +
                                  action_response.get_message().get_value())

                        # Check if the request returned an exception
                        elif isinstance(action_response, APIException):

                            # Get the Status
                            print("Status: " +
                                  action_response.get_status().get_value())

                            # Get the Code
                            print("Code: " +
                                  action_response.get_code().get_value())

                            print("Details")

                            # Get the details dict
                            details = action_response.get_details()

                            for key, value in details.items():
                                print(key + ' : ' + str(value))

                            # Get the Message
                            print("Message: " +
                                  action_response.get_message().get_value())

                # Check if the request returned an exception
                elif isinstance(response_object, APIException):

                    # Get the Status
                    print("Status: " +
                          response_object.get_status().get_value())

                    # Get the Code
                    print("Code: " + response_object.get_code().get_value())

                    print("Details")

                    # Get the details dict
                    details = response_object.get_details()

                    for key, value in details.items():
                        print(key + ' : ' + str(value))

                    # Get the Message
                    print("Message: " +
                          response_object.get_message().get_value())