Method: Osm::Invoice#update

Defined in:
lib/osm/invoice.rb

#update(api) ⇒ Boolan

Update the invoice in OSM

Parameters:

  • api (Osm::Api)

    The api to use to make the request

Returns:

  • (Boolan)

    whether the invoice was successfully updated or not

Raises:



133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/osm/invoice.rb', line 133

def update(api)
  raise Osm::ObjectIsInvalid, 'invoice is invalid' unless valid?
  require_ability_to(api, :write, :finance, section_id)

  data = api.perform_query("finances.php?action=addInvoice&sectionid=#{section_id}", {
    'invoiceid' => id,
    'name' => name,
    'extra' => extra_details,
    'date' => date.strftime(Osm::OSM_DATE_FORMAT),
  })

  if data.is_a?(Hash) && data['ok'].eql?(true)
    reset_changed_attributes
    # The cached invoice will be out of date - remove it
    cache_delete(api, ['invoice', self.id])
    return true
  end
  return false
end