Sha256: 7ceed8897103a1def88f8541309d39f1e4a79e5278a818d3c4e43cb01d755aeb

Contents?: true

Size: 1.2 KB

Versions: 4

Compression:

Stored size: 1.2 KB

Contents

# frozen_string_literal: true

require_relative '../reference/serializer'

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

          attribute :Name
          attribute :Active
          attribute :SubDepartment
          attribute :FullyQualifiedName

          references_one 'ParentRef',
                         resource_attribute: :Parent,
                         serializer: Reference::Serializer

          # Sending "ParentRef": {"value": null} results in QBO API crash
          # This patches serialized hash to exclude it unless we don't set value
          def serialize(args = {})
            deep_merge_unmapped_values = args.fetch(:deep_merge_unmapped_values, {})
            only_changes = args.fetch(:only_changes, false)
            resource = args.fetch(:resource)

            ret = super(only_changes: only_changes, resource: resource)

            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.6.0 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb
ledger_sync-1.5.2 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb
ledger_sync-1.5.1 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb
ledger_sync-1.5.0 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb