Class: LoyaltyApIs::SaleItem

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/loyalty_ap_is/models/sale_item.rb

Overview

SaleItem Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(amount:, detail_type:, discount_amount:, offer_infos:, original_amount:, product_data:, quantity:, description: SKIP, offer_lang: SKIP, original_net_amount: SKIP, vat_amount: SKIP, vat_rate: SKIP, voucher_items: SKIP, vouchers: SKIP, unit_price: SKIP, unit_measure: SKIP, ev: SKIP, points: SKIP, additional_properties: nil) ⇒ SaleItem

Returns a new instance of SaleItem.



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
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 131

def initialize(amount:, detail_type:, discount_amount:, offer_infos:,
               original_amount:, product_data:, quantity:,
               description: SKIP, offer_lang: SKIP,
               original_net_amount: SKIP, vat_amount: SKIP, vat_rate: SKIP,
               voucher_items: SKIP, vouchers: SKIP, unit_price: SKIP,
               unit_measure: SKIP, ev: SKIP, points: SKIP,
               additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @description = description unless description == SKIP
  @amount = amount
  @detail_type = detail_type
  @discount_amount = discount_amount
  @offer_infos = offer_infos
  @offer_lang = offer_lang unless offer_lang == SKIP
  @original_amount = original_amount
  @original_net_amount = original_net_amount unless original_net_amount == SKIP
  @product_data = product_data
  @quantity = quantity
  @vat_amount = vat_amount unless vat_amount == SKIP
  @vat_rate = vat_rate unless vat_rate == SKIP
  @voucher_items = voucher_items unless voucher_items == SKIP
  @vouchers = vouchers unless vouchers == SKIP
  @unit_price = unit_price unless unit_price == SKIP
  @unit_measure = unit_measure unless unit_measure == SKIP
  @ev = ev unless ev == SKIP
  @points = points unless points == SKIP
  @additional_properties = additional_properties
end

Instance Attribute Details

#amountFloat

Total amount

Returns:

  • (Float)


18
19
20
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 18

def amount
  @amount
end

#descriptionString

Description - currently not in use

Returns:

  • (String)


14
15
16
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 14

def description
  @description
end

#detail_typeTransactionDetailType

Indicates the Type of the transaction detail row (award, redemption, transfer, voucher, refund or central award).



23
24
25
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 23

def detail_type
  @detail_type
end

#discount_amountFloat

Discount amount of sales line

Returns:

  • (Float)


27
28
29
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 27

def discount_amount
  @discount_amount
end

#evEvChargingDetails

Unit of measure

Returns:



79
80
81
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 79

def ev
  @ev
end

#offer_infosArray[OfferInfo]

Discount amount of sales line

Returns:



31
32
33
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 31

def offer_infos
  @offer_infos
end

#offer_langOfferLanguage

Discount amount of sales line

Returns:



35
36
37
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 35

def offer_lang
  @offer_lang
end

#original_amountFloat

Original amount of sales line

Returns:

  • (Float)


39
40
41
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 39

def original_amount
  @original_amount
end

#original_net_amountFloat

Original amount excluding VAT

Returns:

  • (Float)


43
44
45
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 43

def original_net_amount
  @original_net_amount
end

#pointsInteger

Points earned in a transaction

Returns:

  • (Integer)


83
84
85
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 83

def points
  @points
end

#product_dataSaleItemProduct

Original amount excluding VAT

Returns:



47
48
49
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 47

def product_data
  @product_data
end

#quantityFloat

Quantity of product

Returns:

  • (Float)


51
52
53
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 51

def quantity
  @quantity
end

#unit_measureUnitMeasure

Unit of measure

Returns:



75
76
77
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 75

def unit_measure
  @unit_measure
end

#unit_priceFloat

Unit price of sale item

Returns:

  • (Float)


71
72
73
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 71

def unit_price
  @unit_price
end

#vat_amountFloat

Value added tax

Returns:

  • (Float)


55
56
57
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 55

def vat_amount
  @vat_amount
end

#vat_rateFloat

VAT rate of sales line

Returns:

  • (Float)


59
60
61
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 59

def vat_rate
  @vat_rate
end

#voucher_itemsArray[VoucherItem]

VAT rate of sales line

Returns:



63
64
65
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 63

def voucher_items
  @voucher_items
end

#vouchersArray[String]

List of vouchers

Returns:

  • (Array[String])


67
68
69
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 67

def vouchers
  @vouchers
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 163

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  amount = hash.key?('amount') ? hash['amount'] : nil
  detail_type = hash.key?('detailType') ? hash['detailType'] : nil
  discount_amount =
    hash.key?('discountAmount') ? hash['discountAmount'] : nil
  # Parameter is an array, so we need to iterate through it
  offer_infos = nil
  unless hash['offerInfos'].nil?
    offer_infos = []
    hash['offerInfos'].each do |structure|
      offer_infos << (OfferInfo.from_hash(structure) if structure)
    end
  end

  offer_infos = nil unless hash.key?('offerInfos')
  original_amount =
    hash.key?('originalAmount') ? hash['originalAmount'] : nil
  product_data = SaleItemProduct.from_hash(hash['productData']) if hash['productData']
  quantity = hash.key?('quantity') ? hash['quantity'] : nil
  description = hash.key?('description') ? hash['description'] : SKIP
  offer_lang = OfferLanguage.from_hash(hash['offerLang']) if hash['offerLang']
  original_net_amount =
    hash.key?('originalNetAmount') ? hash['originalNetAmount'] : SKIP
  vat_amount = hash.key?('vatAmount') ? hash['vatAmount'] : SKIP
  vat_rate = hash.key?('vatRate') ? hash['vatRate'] : SKIP
  # Parameter is an array, so we need to iterate through it
  voucher_items = nil
  unless hash['voucherItems'].nil?
    voucher_items = []
    hash['voucherItems'].each do |structure|
      voucher_items << (VoucherItem.from_hash(structure) if structure)
    end
  end

  voucher_items = SKIP unless hash.key?('voucherItems')
  vouchers = hash.key?('vouchers') ? hash['vouchers'] : SKIP
  unit_price = hash.key?('unitPrice') ? hash['unitPrice'] : SKIP
  unit_measure = hash.key?('unitMeasure') ? hash['unitMeasure'] : SKIP
  ev = EvChargingDetails.from_hash(hash['EV']) if hash['EV']
  points = hash.key?('points') ? hash['points'] : SKIP

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  SaleItem.new(amount: amount,
               detail_type: detail_type,
               discount_amount: discount_amount,
               offer_infos: offer_infos,
               original_amount: original_amount,
               product_data: product_data,
               quantity: quantity,
               description: description,
               offer_lang: offer_lang,
               original_net_amount: original_net_amount,
               vat_amount: vat_amount,
               vat_rate: vat_rate,
               voucher_items: voucher_items,
               vouchers: vouchers,
               unit_price: unit_price,
               unit_measure: unit_measure,
               ev: ev,
               points: points,
               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 86

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['description'] = 'description'
  @_hash['amount'] = 'amount'
  @_hash['detail_type'] = 'detailType'
  @_hash['discount_amount'] = 'discountAmount'
  @_hash['offer_infos'] = 'offerInfos'
  @_hash['offer_lang'] = 'offerLang'
  @_hash['original_amount'] = 'originalAmount'
  @_hash['original_net_amount'] = 'originalNetAmount'
  @_hash['product_data'] = 'productData'
  @_hash['quantity'] = 'quantity'
  @_hash['vat_amount'] = 'vatAmount'
  @_hash['vat_rate'] = 'vatRate'
  @_hash['voucher_items'] = 'voucherItems'
  @_hash['vouchers'] = 'vouchers'
  @_hash['unit_price'] = 'unitPrice'
  @_hash['unit_measure'] = 'unitMeasure'
  @_hash['ev'] = 'EV'
  @_hash['points'] = 'points'
  @_hash
end

.nullablesObject

An array for nullable fields



127
128
129
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 127

def self.nullables
  []
end

.optionalsObject

An array for optional fields



110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 110

def self.optionals
  %w[
    description
    offer_lang
    original_net_amount
    vat_amount
    vat_rate
    voucher_items
    vouchers
    unit_price
    unit_measure
    ev
    points
  ]
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



249
250
251
252
253
254
255
256
257
258
259
260
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 249

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} description: #{@description.inspect}, amount: #{@amount.inspect},"\
  " detail_type: #{@detail_type.inspect}, discount_amount: #{@discount_amount.inspect},"\
  " offer_infos: #{@offer_infos.inspect}, offer_lang: #{@offer_lang.inspect}, original_amount:"\
  " #{@original_amount.inspect}, original_net_amount: #{@original_net_amount.inspect},"\
  " product_data: #{@product_data.inspect}, quantity: #{@quantity.inspect}, vat_amount:"\
  " #{@vat_amount.inspect}, vat_rate: #{@vat_rate.inspect}, voucher_items:"\
  " #{@voucher_items.inspect}, vouchers: #{@vouchers.inspect}, unit_price:"\
  " #{@unit_price.inspect}, unit_measure: #{@unit_measure.inspect}, ev: #{@ev.inspect},"\
  " points: #{@points.inspect}, additional_properties: #{@additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



237
238
239
240
241
242
243
244
245
246
# File 'lib/loyalty_ap_is/models/sale_item.rb', line 237

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} description: #{@description}, amount: #{@amount}, detail_type:"\
  " #{@detail_type}, discount_amount: #{@discount_amount}, offer_infos: #{@offer_infos},"\
  " offer_lang: #{@offer_lang}, original_amount: #{@original_amount}, original_net_amount:"\
  " #{@original_net_amount}, product_data: #{@product_data}, quantity: #{@quantity},"\
  " vat_amount: #{@vat_amount}, vat_rate: #{@vat_rate}, voucher_items: #{@voucher_items},"\
  " vouchers: #{@vouchers}, unit_price: #{@unit_price}, unit_measure: #{@unit_measure}, ev:"\
  " #{@ev}, points: #{@points}, additional_properties: #{@additional_properties}>"
end