Sha256: 49e1b1cbd2f70e9cbce528b554cff18d1dc439855a9c592ab5392df119c0fdb5

Contents?: true

Size: 1.38 KB

Versions: 1

Compression:

Stored size: 1.38 KB

Contents

# frozen_string_literal: true

require_relative '../ledger_serializer_type/department_reference_type'

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,
                    resource_attribute: :parent,
                    type: LedgerSerializerType::DepartmentReferenceType

          # 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)

            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

1 entries across 1 versions & 1 rubygems

Version Path
ledger_sync-1.3.5 lib/ledger_sync/adaptors/quickbooks_online/department/ledger_serializer.rb