Sha256: 358351b7bbd1ae7793ee7cfebd8fcf3bc21d78f8192e7a6b3c1bdbbe77a21dfc

Contents?: true

Size: 1.76 KB

Versions: 1

Compression:

Stored size: 1.76 KB

Contents

require 'ledger_sync/adaptors/quickbooks_online/account/mapping'

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Account
        module Operations
          class Create < Operation::Create
            class Contract < LedgerSync::Adaptors::Contract
              params do
                required(:ledger_id).value(:nil)
                required(:name).filled(:string)
                required(:classification).filled(:string)
                required(:account_type).filled(:string)
                required(:account_sub_type).filled(:string)
                required(:number).maybe(:integer)
                required(:currency).maybe(:string)
                required(:description).maybe(:string)
                required(:active).maybe(:bool)
              end
            end

            private

            def operate
              response = adaptor.post(
                resource: 'account',
                payload: local_resource_data
              )

              resource.ledger_id = response.dig('Id')
              success(response: response)
            end

            def local_resource_data
              {
                'Name' => resource.name,
                'Classification' => Mapping::ACCOUNT_CLASSIFICATIONS[resource.classification],
                'AccountType' => Mapping::ACCOUNT_TYPES[resource.account_type],
                'AccountSubType' => Mapping::ACCOUNT_SUB_TYPES[resource.account_sub_type],
                'AcctNum' => resource.number,
                'CurrencyRef' => {
                  'value' => resource.currency,
                },
                'Description' => resource.description,
                'Active' => resource.active
              }
            end
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ledger_sync-1.1.1 lib/ledger_sync/adaptors/quickbooks_online/account/operations/create.rb