Sha256: e023820eade255893906de0ce26250ef133a9f005d9b1c05f389a9e7ef2b344e

Contents?: true

Size: 1.15 KB

Versions: 3

Compression:

Stored size: 1.15 KB

Contents

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Invoice
        module Operations
          class Upsert < Operation::Upsert
            class Contract < LedgerSync::Adaptors::Contract
              schema do
                required(:ledger_id).maybe(:string)
                required(:currency).maybe(:string)
                required(:customer).maybe(Types::Reference)
                required(:line_items).maybe(:array)
                required(:number).maybe(:integer)
              end
            end

            private

            def build
              op =  if qbo_invoice?
                      Update.new(adaptor: adaptor, resource: resource)
                    else
                      Create.new(adaptor: adaptor, resource: resource)
                    end

              add_root_operation(op)
            end

            def find_result
              @find_result ||= Find.new(
                adaptor: adaptor,
                resource: resource
              ).perform
            end

            def qbo_invoice?
              find_result.success?
            end
          end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
ledger_sync-1.0.3 lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/upsert.rb
ledger_sync-1.0.2 lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/upsert.rb
ledger_sync-1.0.0 lib/ledger_sync/adaptors/quickbooks_online/invoice/operations/upsert.rb