Class: Agris::Api::Order

Inherits:
Object
  • Object
show all
Includes:
XmlModel
Defined in:
lib/agris/api/order.rb

Overview

NB: This is the model for returning orders

Constant Summary collapse

ATTRIBUTE_NAMES =
%w(
  order_location
  order_number
  order_status
  order_type
  order_date
  bill_to_from_id
  delete
  price_code
  price_level
  price_schedule
  invoice_terms
  statecounty
  user_order_field_1
  user_order_field_2
  external_order_number
  ship_to_from_id
  shipper_id
  agent_id
  unique_id
).freeze

Class Method Summary collapse

Instance Method Summary collapse

Methods included from XmlModel

included

Constructor Details

#initialize(hash = {}) ⇒ Order

Returns a new instance of Order.



55
56
57
58
59
60
# File 'lib/agris/api/order.rb', line 55

def initialize(hash = {})
  super

  @line_items = []
  @tran_codes = []
end

Class Method Details

.from_xml_hash(hash) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/agris/api/order.rb', line 32

def self.from_xml_hash(hash)
  super.tap do |order|
    if hash['lineitems']
      order.line_items.concat(
        [hash['lineitems']['lineitem']]
          .flatten
          .map do |lineitem|
            OrderLine.from_xml_hash(lineitem)
          end
      )
    end
    if hash['trancodes']
      order.tran_codes.concat(
        [hash['trancodes']['trancode']]
        .flatten
        .map do |trancode|
          Agris::Api::TranCode.from_xml_hash(trancode)
        end
      )
    end
  end
end