Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

timesheet_lines calls .to_hash on float #263

Open
davidhin opened this issue Jun 29, 2023 · 2 comments
Open

timesheet_lines calls .to_hash on float #263

davidhin opened this issue Jun 29, 2023 · 2 comments

Comments

@davidhin
Copy link

When calling to_hash on a timesheet returned from Xero API, it fails because it attempts to call to_hash on a float.

For examlpe, timesheet lines look like this.

  @timesheet_lines=[
    #<XeroRuby::PayrollAu::TimesheetLine:0x00007fa052d99258 
        @earnings_rate_id="4c099b8b-8fe3-436d-973e-0e17c01146a0", 
        @number_of_units=[0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0], 
        @updated_date_utc=Wed, 28 Jun 2023 05:28:34 +0000>
   ]

Number of units is an array of floats: [0.0, 0.0, 0.0, 0.0, 4.0, 0.0, 0.0]

eval error: undefined method `to_hash' for 4.0:Float
def _to_hash(value, downcase: false)
  if value.is_a?(Array)
    value.map do |v|
      v.to_hash(downcase: downcase) # <- the problematic part, because it doesn't check if the value responds to to_hash
    end
  elsif value.is_a?(Hash)
    {}.tap do |hash|
      value.map { |k, v| hash[k] = _to_hash(v, downcase: downcase) }
    end
  elsif value.respond_to? :to_hash
    value.to_hash(downcase: downcase)
  else
    value
  end
end
@github-actions
Copy link

PETOSS-310

@github-actions
Copy link

Thanks for raising an issue, a ticket has been created to track your request

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant