Sha256: 6f5cc052d94b465f775e7b2a55c3207b6fc46328d10f7230ebc66a887b0adb3f

Contents?: true

Size: 1.33 KB

Versions: 4

Compression:

Stored size: 1.33 KB

Contents

# frozen_string_literal: true

module LedgerSync
  module Adaptors
    module QuickBooksOnline
      module Department
        class LedgerSerializer < QuickBooksOnline::LedgerSerializer
          id

          attribute ledger_attribute: 'Name',
                    resource_attribute: :name
          attribute ledger_attribute: 'Active',
                    resource_attribute: :active
          attribute ledger_attribute: 'SubDepartment',
                    resource_attribute: :sub_department
          attribute ledger_attribute: 'FullyQualifiedName',
                    resource_attribute: :fully_qualified_name

          attribute ledger_attribute: 'ParentRef.value',
                    resource_attribute: 'parent.ledger_id'

          # Sending "ParentRef": {"value": null} results in QBO API crash
          # This patches serialized hash to exclude it unless we don't set value
          def to_ledger_hash(deep_merge_unmapped_values: {}, only_changes: false)
            ret = super(only_changes: only_changes)
            ret = ret.except('ParentRef') unless resource.parent_changed?
            return ret unless deep_merge_unmapped_values.any?

            deep_merge_if_not_mapped(
              current_hash: ret,
              hash_to_search: deep_merge_unmapped_values
            )
          end
        end
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
ledger_sync-1.3.4 lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb
ledger_sync-1.3.3 lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb
ledger_sync-1.3.2 lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb
ledger_sync-1.3.1 lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb