Sha256: 22e54c14b623a2964a81cdf1f3d2c09e43c7b0bb4a20ad6cec99f36777a1281d

Contents?: true

Size: 1.59 KB

Versions: 4

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

require_relative '../expense_line/serializer'
require_relative '../reference/serializer'

module LedgerSync
  module Ledgers
    module QuickBooksOnline
      class Expense
        class Serializer < QuickBooksOnline::Serializer
          id

          attribute :DocNumber
          date :TxnDate
          attribute :PrivateNote
          attribute :ExchangeRate

          attribute :PaymentType,
                    type: LedgerSync::Serialization::Type::MappingType.new(hash: Expense::PAYMENT_TYPES)

          attribute('EntityRef') do |args = {}|
            resource = args.fetch(:resource)
            if resource.Entity
              {
                'name' => resource.Entity.name,
                'value' => resource.Entity.ledger_id,
                'type' => Client.ledger_resource_type_for(
                  resource_class: resource.Entity.class
                ).classify
              }
            end
          end

          references_one 'CurrencyRef',
                         resource_attribute: :Currency,
                         serializer: Reference::Serializer

          references_one 'AccountRef',
                         resource_attribute: :Account,
                         serializer: Reference::Serializer

          references_one 'DepartmentRef',
                         resource_attribute: :Department,
                         serializer: Reference::Serializer

          references_many 'Line',
                          resource_attribute: :Line,
                          serializer: ExpenseLine::Serializer
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ledger_sync-1.6.0 lib/ledger_sync/ledgers/quickbooks_online/expense/serializer.rb
ledger_sync-1.5.2 lib/ledger_sync/ledgers/quickbooks_online/expense/serializer.rb
ledger_sync-1.5.1 lib/ledger_sync/ledgers/quickbooks_online/expense/serializer.rb
ledger_sync-1.5.0 lib/ledger_sync/ledgers/quickbooks_online/expense/serializer.rb