Class: Merge::Accounting::Item

Inherits:
Object
  • Object
show all
Defined in:
lib/merge_ruby_client/accounting/types/item.rb

Overview

# The Item Object

### Description
The `Item` object refers to the goods involved in a transaction.
### Usage Example
Fetch from the `LIST Items` endpoint and view a company's items.

Constant Summary collapse

OMIT =
Object.new

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id: OMIT, remote_id: OMIT, created_at: OMIT, modified_at: OMIT, name: OMIT, status: OMIT, unit_price: OMIT, purchase_price: OMIT, purchase_account: OMIT, sales_account: OMIT, company: OMIT, remote_updated_at: OMIT, remote_was_deleted: OMIT, field_mappings: OMIT, remote_data: OMIT, additional_properties: nil) ⇒ Merge::Accounting::Item

Parameters:

  • id (String) (defaults to: OMIT)
  • remote_id (String) (defaults to: OMIT)

    The third-party API ID of the matching object.

  • created_at (DateTime) (defaults to: OMIT)

    The datetime that this object was created by Merge.

  • modified_at (DateTime) (defaults to: OMIT)

    The datetime that this object was modified by Merge.

  • name (String) (defaults to: OMIT)

    The item’s name.

  • status (Merge::Accounting::Status7D1Enum) (defaults to: OMIT)

    The item’s status.

    • ‘ACTIVE` - ACTIVE

    • ‘ARCHIVED` - ARCHIVED

  • unit_price (Float) (defaults to: OMIT)

    The item’s unit price.

  • purchase_price (Float) (defaults to: OMIT)

    The price at which the item is purchased from a vendor.

  • purchase_account (Merge::Accounting::ItemPurchaseAccount) (defaults to: OMIT)

    References the default account used to record a purchase of the item.

  • sales_account (Merge::Accounting::ItemSalesAccount) (defaults to: OMIT)

    References the default account used to record a sale.

  • company (Merge::Accounting::ItemCompany) (defaults to: OMIT)

    The company the item belongs to.

  • remote_updated_at (DateTime) (defaults to: OMIT)

    When the third party’s item note was updated.

  • remote_was_deleted (Boolean) (defaults to: OMIT)

    Indicates whether or not this object has been deleted in the third party platform.

  • field_mappings (Hash{String => Object}) (defaults to: OMIT)
  • remote_data (Array<Merge::Accounting::RemoteData>) (defaults to: OMIT)
  • additional_properties (OpenStruct) (defaults to: nil)

    Additional properties unmapped to the current class definition



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 81

def initialize(id: OMIT, remote_id: OMIT, created_at: OMIT, modified_at: OMIT, name: OMIT, status: OMIT,
               unit_price: OMIT, purchase_price: OMIT, purchase_account: OMIT, sales_account: OMIT, company: OMIT, remote_updated_at: OMIT, remote_was_deleted: OMIT, field_mappings: OMIT, remote_data: OMIT, additional_properties: nil)
  @id = id if id != OMIT
  @remote_id = remote_id if remote_id != OMIT
  @created_at = created_at if created_at != OMIT
  @modified_at = modified_at if modified_at != OMIT
  @name = name if name != OMIT
  @status = status if status != OMIT
  @unit_price = unit_price if unit_price != OMIT
  @purchase_price = purchase_price if purchase_price != OMIT
  @purchase_account =  if  != OMIT
  @sales_account =  if  != OMIT
  @company = company if company != OMIT
  @remote_updated_at = remote_updated_at if remote_updated_at != OMIT
  @remote_was_deleted = remote_was_deleted if remote_was_deleted != OMIT
  @field_mappings = field_mappings if field_mappings != OMIT
  @remote_data = remote_data if remote_data != OMIT
  @additional_properties = additional_properties
  @_field_set = {
    "id": id,
    "remote_id": remote_id,
    "created_at": created_at,
    "modified_at": modified_at,
    "name": name,
    "status": status,
    "unit_price": unit_price,
    "purchase_price": purchase_price,
    "purchase_account": ,
    "sales_account": ,
    "company": company,
    "remote_updated_at": remote_updated_at,
    "remote_was_deleted": remote_was_deleted,
    "field_mappings": field_mappings,
    "remote_data": remote_data
  }.reject do |_k, v|
    v == OMIT
  end
end

Instance Attribute Details

#additional_propertiesOpenStruct (readonly)

Returns Additional properties unmapped to the current class definition.

Returns:

  • (OpenStruct)

    Additional properties unmapped to the current class definition



54
55
56
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 54

def additional_properties
  @additional_properties
end

#companyMerge::Accounting::ItemCompany (readonly)

Returns The company the item belongs to.

Returns:



43
44
45
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 43

def company
  @company
end

#created_atDateTime (readonly)

Returns The datetime that this object was created by Merge.

Returns:

  • (DateTime)

    The datetime that this object was created by Merge.



25
26
27
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 25

def created_at
  @created_at
end

#field_mappingsHash{String => Object} (readonly)

Returns:

  • (Hash{String => Object})


50
51
52
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 50

def field_mappings
  @field_mappings
end

#idString (readonly)

Returns:

  • (String)


21
22
23
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 21

def id
  @id
end

#modified_atDateTime (readonly)

Returns The datetime that this object was modified by Merge.

Returns:

  • (DateTime)

    The datetime that this object was modified by Merge.



27
28
29
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 27

def modified_at
  @modified_at
end

#nameString (readonly)

Returns The item’s name.

Returns:

  • (String)

    The item’s name.



29
30
31
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 29

def name
  @name
end

#purchase_accountMerge::Accounting::ItemPurchaseAccount (readonly)

Returns References the default account used to record a purchase of the item.

Returns:



39
40
41
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 39

def 
  @purchase_account
end

#purchase_priceFloat (readonly)

Returns The price at which the item is purchased from a vendor.

Returns:

  • (Float)

    The price at which the item is purchased from a vendor.



37
38
39
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 37

def purchase_price
  @purchase_price
end

#remote_dataArray<Merge::Accounting::RemoteData> (readonly)

Returns:



52
53
54
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 52

def remote_data
  @remote_data
end

#remote_idString (readonly)

Returns The third-party API ID of the matching object.

Returns:

  • (String)

    The third-party API ID of the matching object.



23
24
25
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 23

def remote_id
  @remote_id
end

#remote_updated_atDateTime (readonly)

Returns When the third party’s item note was updated.

Returns:

  • (DateTime)

    When the third party’s item note was updated.



45
46
47
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 45

def remote_updated_at
  @remote_updated_at
end

#remote_was_deletedBoolean (readonly)

Returns Indicates whether or not this object has been deleted in the third party platform.

Returns:

  • (Boolean)

    Indicates whether or not this object has been deleted in the third party platform.



48
49
50
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 48

def remote_was_deleted
  @remote_was_deleted
end

#sales_accountMerge::Accounting::ItemSalesAccount (readonly)

Returns References the default account used to record a sale.

Returns:



41
42
43
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 41

def 
  @sales_account
end

#statusMerge::Accounting::Status7D1Enum (readonly)

Returns The item’s status.

  • ‘ACTIVE` - ACTIVE

  • ‘ARCHIVED` - ARCHIVED.

Returns:



33
34
35
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 33

def status
  @status
end

#unit_priceFloat (readonly)

Returns The item’s unit price.

Returns:

  • (Float)

    The item’s unit price.



35
36
37
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 35

def unit_price
  @unit_price
end

Class Method Details

.from_json(json_object:) ⇒ Merge::Accounting::Item

Deserialize a JSON object to an instance of Item

Parameters:

  • json_object (String)

Returns:



124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 124

def self.from_json(json_object:)
  struct = JSON.parse(json_object, object_class: OpenStruct)
  parsed_json = JSON.parse(json_object)
  id = parsed_json["id"]
  remote_id = parsed_json["remote_id"]
  created_at = (DateTime.parse(parsed_json["created_at"]) unless parsed_json["created_at"].nil?)
  modified_at = (DateTime.parse(parsed_json["modified_at"]) unless parsed_json["modified_at"].nil?)
  name = parsed_json["name"]
  status = parsed_json["status"]
  unit_price = parsed_json["unit_price"]
  purchase_price = parsed_json["purchase_price"]
  if parsed_json["purchase_account"].nil?
     = nil
  else
     = parsed_json["purchase_account"].to_json
     = Merge::Accounting::ItemPurchaseAccount.from_json(json_object: )
  end
  if parsed_json["sales_account"].nil?
     = nil
  else
     = parsed_json["sales_account"].to_json
     = Merge::Accounting::ItemSalesAccount.from_json(json_object: )
  end
  if parsed_json["company"].nil?
    company = nil
  else
    company = parsed_json["company"].to_json
    company = Merge::Accounting::ItemCompany.from_json(json_object: company)
  end
  remote_updated_at = unless parsed_json["remote_updated_at"].nil?
                        DateTime.parse(parsed_json["remote_updated_at"])
                      end
  remote_was_deleted = parsed_json["remote_was_deleted"]
  field_mappings = parsed_json["field_mappings"]
  remote_data = parsed_json["remote_data"]&.map do |item|
    item = item.to_json
    Merge::Accounting::RemoteData.from_json(json_object: item)
  end
  new(
    id: id,
    remote_id: remote_id,
    created_at: created_at,
    modified_at: modified_at,
    name: name,
    status: status,
    unit_price: unit_price,
    purchase_price: purchase_price,
    purchase_account: ,
    sales_account: ,
    company: company,
    remote_updated_at: remote_updated_at,
    remote_was_deleted: remote_was_deleted,
    field_mappings: field_mappings,
    remote_data: remote_data,
    additional_properties: struct
  )
end

.validate_raw(obj:) ⇒ Void

Leveraged for Union-type generation, validate_raw attempts to parse the given

hash and check each fields type against the current object's property
definitions.

Parameters:

  • obj (Object)

Returns:

  • (Void)


195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 195

def self.validate_raw(obj:)
  obj.id&.is_a?(String) != false || raise("Passed value for field obj.id is not the expected type, validation failed.")
  obj.remote_id&.is_a?(String) != false || raise("Passed value for field obj.remote_id is not the expected type, validation failed.")
  obj.created_at&.is_a?(DateTime) != false || raise("Passed value for field obj.created_at is not the expected type, validation failed.")
  obj.modified_at&.is_a?(DateTime) != false || raise("Passed value for field obj.modified_at is not the expected type, validation failed.")
  obj.name&.is_a?(String) != false || raise("Passed value for field obj.name is not the expected type, validation failed.")
  obj.status&.is_a?(Merge::Accounting::Status7D1Enum) != false || raise("Passed value for field obj.status is not the expected type, validation failed.")
  obj.unit_price&.is_a?(Float) != false || raise("Passed value for field obj.unit_price is not the expected type, validation failed.")
  obj.purchase_price&.is_a?(Float) != false || raise("Passed value for field obj.purchase_price is not the expected type, validation failed.")
  obj..nil? || Merge::Accounting::ItemPurchaseAccount.validate_raw(obj: obj.)
  obj..nil? || Merge::Accounting::ItemSalesAccount.validate_raw(obj: obj.)
  obj.company.nil? || Merge::Accounting::ItemCompany.validate_raw(obj: obj.company)
  obj.remote_updated_at&.is_a?(DateTime) != false || raise("Passed value for field obj.remote_updated_at is not the expected type, validation failed.")
  obj.remote_was_deleted&.is_a?(Boolean) != false || raise("Passed value for field obj.remote_was_deleted is not the expected type, validation failed.")
  obj.field_mappings&.is_a?(Hash) != false || raise("Passed value for field obj.field_mappings is not the expected type, validation failed.")
  obj.remote_data&.is_a?(Array) != false || raise("Passed value for field obj.remote_data is not the expected type, validation failed.")
end

Instance Method Details

#to_json(*_args) ⇒ String

Serialize an instance of Item to a JSON object

Returns:

  • (String)


185
186
187
# File 'lib/merge_ruby_client/accounting/types/item.rb', line 185

def to_json(*_args)
  @_field_set&.to_json
end