accodeing / fortnox-api

Gem that abstracts Fortnox's F3 API
GNU Lesser General Public License v3.0
9 stars 8 forks source link

Add support to force save entity as new #224

Open ehannes opened 1 year ago

ehannes commented 1 year ago

I have found a new use case for the gem - copy data from one Fortnox instance to another. The current implementation tries to save us an API call by checking the dirty tracking of the model and see if it's already saved before trying to save it. But if you want to fetch a resource from one Fortnox instance and save it to another, the model is marked as saved and it will not be saved.

One proposal is to add a force override:

def save(entity, force: false)
  return save_new(entity) if force

  return true if entity.saved?

  return save_new(entity) if entity.new?

  update_existing(entity)
end