Hello!
Each month I create a new invoice via the web UI for all the unbilled tasks on a particular project. When I did it this month, I found many previously-invoiced tasks were included on the new invoice. I am trying to figure out how / why this happened so I can fix it.
On 5th October, a few days after I created last month’s invoice, I decided to change the income category of all the tasks on all the invoices for the project. I did it using my Ruby API client like this:
desired_category = user.freeagent.category('008').url.to_s
id = ->(uri) { uri.to_s[/\d+$/] }
user.freeagent.invoices(contact: 12345,
nested_invoice_items: true,
sort: '-created_at',
auto_paginate: true).each do |invoice|
items = invoice.invoice_items.select { |item| item.category.to_s != desired_category }
next if items.empty?
user.freeagent.update_invoice(
id[invoice.url],
invoice_items: items.map { |item|
{
id: id[item.url],
category: desired_category,
item_type: item.item_type # need to specify because blank == "No unit"
}
}
)
end
Is it possible that updating invoice items’ categories could have somehow reset the associated tasks’ billed_on_invoice
attribute? I had assumed that you only need to specify the attributes which are changing (the docs say “…containing elements…that should be updated”).
Many thanks!
Yours,
Andrew
–