Sha256: 527b137fe18ee08c2737cd13b49efe19617dad53da9edde5a23e4075184da76d

Contents?: true

Size: 1.46 KB

Versions: 4

Compression:

Stored size: 1.46 KB

Contents

# frozen_string_literal: true

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

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

          attribute(:ParentRef) do |args = {}|
            resource = args.fetch(:resource)

            if resource.parent.present?
              {
                'value' => resource.parent.ledger_id
              }
            end
          end

          # 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.4.4 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb
ledger_sync-1.4.2 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb
ledger_sync-1.4.1 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb
ledger_sync-1.4.0 lib/ledger_sync/ledgers/quickbooks_online/department/serializer.rb