# Buggy code
def cli_consumption_list_usage(
    client,
    billing_period_name=None,
    top=None,
    include_additional_properties=False,
    include_meter_details=False,
    start_date=None,
    end_date=None,
):
    if include_additional_properties and include_meter_details:
        expand = "properties/additionalProperties,properties/meterDetails"
    elif include_additional_properties:
        expand = "properties/additionalProperties"
    elif include_meter_details:
        expand = "properties/meterDetails"
    else:
        expand = None

    filter_from = None
    filter_to = None
    filter_expression = None
    if start_date and end_date:
        filter_from = "properties/usageEnd ge '{}'".format(
            start_date.strftime("%Y-%m-%dT%H:%M:%SZ")
        )
        filter_to = "properties/usageEnd le '{}'".format(
            end_date.strftime("%Y-%m-%dT%H:%M:%SZ")
        )
        filter_expression = "{} and {}".format(filter_from, filter_to)

    if billing_period_name and top:
        return list(
            client.list_by_billing_period(
                billing_period_name, expand=expand, filter=filter_expression, top=top
            ).advance_page()
        )
    elif billing_period_name and not top:
        return list(
            client.list_by_billing_period(expand=expand, filter=filter_expression)
        )
    elif not billing_period_name and top:
        return list(
            client.list(expand=expand, filter=filter_expression, top=top).advance_page()
        )
    return client.list(expand=expand, filter=filter_expression)


# Traceback (TypeError)
list_by_billing_period() missing 1 required positional argument: 'billing_period_name'
Traceback (most recent call last):
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/knack/cli.py", line 197, in invoke
cmd_result = self.invocation.execute(args)
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 333, in execute
cmd.exception_handler(ex)
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/azure/cli/command_modules/consumption/_exception_handler.py", line 17, in consumption_exception_handler
reraise(*sys.exc_info())
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/six.py", line 693, in reraise
raise value
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 310, in execute
result = cmd(params)
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/azure/cli/core/commands/__init__.py", line 171, in __call__
return super(AzCliCommand, self).__call__(*args, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/knack/commands.py", line 109, in __call__
return self.handler(*args, **kwargs)
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/azure/cli/core/__init__.py", line 420, in default_command_handler
result = op(**command_args)
File "/usr/local/Cellar/azure-cli/2.0.37/libexec/lib/python3.6/site-packages/azure/cli/command_modules/consumption/custom.py", line 30, in cli_consumption_list_usage
return list(client.list_by_billing_period(expand=expand, filter=filter_expression))
TypeError: list_by_billing_period() missing 1 required positional argument: 'billing_period_name'

# Fixed code
def cli_consumption_list_usage(
    client,
    billing_period_name=None,
    top=None,
    include_additional_properties=False,
    include_meter_details=False,
    start_date=None,
    end_date=None,
):
    if include_additional_properties and include_meter_details:
        expand = "properties/additionalProperties,properties/meterDetails"
    elif include_additional_properties:
        expand = "properties/additionalProperties"
    elif include_meter_details:
        expand = "properties/meterDetails"
    else:
        expand = None

    filter_from = None
    filter_to = None
    filter_expression = None
    if start_date and end_date:
        filter_from = "properties/usageEnd ge '{}'".format(
            start_date.strftime("%Y-%m-%dT%H:%M:%SZ")
        )
        filter_to = "properties/usageEnd le '{}'".format(
            end_date.strftime("%Y-%m-%dT%H:%M:%SZ")
        )
        filter_expression = "{} and {}".format(filter_from, filter_to)

    if billing_period_name and top:
        return list(
            client.list_by_billing_period(
                billing_period_name, expand=expand, filter=filter_expression, top=top
            ).advance_page()
        )
    elif billing_period_name and not top:
        return list(
            client.list_by_billing_period(
                billing_period_name, expand=expand, filter=filter_expression
            )
        )
    elif not billing_period_name and top:
        return list(
            client.list(expand=expand, filter=filter_expression, top=top).advance_page()
        )
    return client.list(expand=expand, filter=filter_expression)