XeroAPI / xero-ruby

Xero Ruby SDK for OAuth 2.0 generated from XeroAPI/Xero-OpenAPI
http://developer.xero.com/
MIT License
58 stars 91 forks source link

JournalLine model missing required field, LineAmount #214

Closed HashNotAdam closed 2 years ago

HashNotAdam commented 2 years ago

XeroRuby::Accounting::JournalLine does not have a line_amount attribute but this is an API required field.

Extending the class like this solved the issue for me:

# frozen_string_literal: true

module EA
  module Xero
    module Models
      class JournalLine < XeroRuby::Accounting::JournalLine
        def self.attribute_map
          super.merge(line_amount: :LineAmount)
        end

        def self.openapi_types
          super.merge(line_amount: :BigDecimal)
        end

        attr_accessor :line_amount

        def initialize(attributes = {})
          super(attributes)

          self.line_amount ||= attributes[:line_amount]
        end

        def ==(other)
          return true if equal?(other)
          return false if self.class != other.class

          self.class.attribute_map.all? do |attr, _|
            public_send(attr).eql?(other.public_send(attr))
          end
        end

        def hash
          self.class.attribute_map.map { |attr, _| public_send(attr) }.hash
        end
      end
    end
  end
end
pumpkinball commented 2 years ago

Hi @HashNotAdam thanks for raising this query. Can you confirm if you are looking at 'Journal' or 'Manual Journal'. For Manual Journal, LineAmount is required see https://developer.xero.com/documentation/api/accounting/manualjournals/ For Journals, it uses NetAmount, GrossAmount, TaxAmount instead. Please see https://developer.xero.com/documentation/api/accounting/journals. Reopen if that doesn't answer your question. Thanks