Class: NewStoreApi::QuotationDto

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/new_store_api/models/quotation_dto.rb

Overview

QuotationDto 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(items = nil, calculation_mode = SKIP, exemption_class = SKIP, exemption_number = SKIP, tax_date = SKIP, tax_exempt = false, transaction_type = SKIP) ⇒ QuotationDto

Returns a new instance of QuotationDto.



80
81
82
83
84
85
86
87
88
89
90
# File 'lib/new_store_api/models/quotation_dto.rb', line 80

def initialize(items = nil, calculation_mode = SKIP, exemption_class = SKIP,
               exemption_number = SKIP, tax_date = SKIP, tax_exempt = false,
               transaction_type = SKIP)
  @calculation_mode = calculation_mode unless calculation_mode == SKIP
  @exemption_class = exemption_class unless exemption_class == SKIP
  @exemption_number = exemption_number unless exemption_number == SKIP
  @items = items
  @tax_date = tax_date unless tax_date == SKIP
  @tax_exempt = tax_exempt unless tax_exempt == SKIP
  @transaction_type = transaction_type unless transaction_type == SKIP
end

Instance Attribute Details

#calculation_modeCalculationModeEnum

TODO: Write general description for this method

Returns:



15
16
17
# File 'lib/new_store_api/models/quotation_dto.rb', line 15

def calculation_mode
  @calculation_mode
end

#exemption_classExemptionClassEnum

TODO: Write general description for this method

Returns:



19
20
21
# File 'lib/new_store_api/models/quotation_dto.rb', line 19

def exemption_class
  @exemption_class
end

#exemption_numberString

The number of the customer's exemption certificate.

  • The given value can be verified by the auditors in the event of a tax audit.

Returns:

  • (String)


25
26
27
# File 'lib/new_store_api/models/quotation_dto.rb', line 25

def exemption_number
  @exemption_number
end

#itemsArray[Object]

A list of the items sold/returned in the quotation. Monetary fields are in the currency's minor unit. All items must use the same currency_consumer.

  • The type ReverseCalculationQuotationItemDto should be used when the calculation_mode is set to REVERSE.
  • The type QuotationItemDto should be used When the calculation_mode is not sent or set to STANDARD.

Returns:

  • (Array[Object])


35
36
37
# File 'lib/new_store_api/models/quotation_dto.rb', line 35

def items
  @items
end

#tax_dateDateTime

Date of the transaction (in UTC timezone) that'll be used in committing taxes.

Returns:

  • (DateTime)


40
41
42
# File 'lib/new_store_api/models/quotation_dto.rb', line 40

def tax_date
  @tax_date
end

#tax_exemptTrueClass | FalseClass

Defines the tax exemption status of the transaction.

Returns:

  • (TrueClass | FalseClass)


44
45
46
# File 'lib/new_store_api/models/quotation_dto.rb', line 44

def tax_exempt
  @tax_exempt
end

#transaction_typeTransactionTypeEnum

Defines the tax exemption status of the transaction.

Returns:



48
49
50
# File 'lib/new_store_api/models/quotation_dto.rb', line 48

def transaction_type
  @transaction_type
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
119
120
121
122
123
# File 'lib/new_store_api/models/quotation_dto.rb', line 93

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  items = hash.key?('items') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:QuotationDtoItems), hash['items']
  ) : nil
  calculation_mode =
    hash.key?('calculation_mode') ? hash['calculation_mode'] : SKIP
  exemption_class =
    hash.key?('exemption_class') ? hash['exemption_class'] : SKIP
  exemption_number =
    hash.key?('exemption_number') ? hash['exemption_number'] : SKIP
  tax_date = if hash.key?('tax_date')
               (DateTimeHelper.from_rfc3339(hash['tax_date']) if hash['tax_date'])
             else
               SKIP
             end
  tax_exempt = hash['tax_exempt'] ||= false
  transaction_type =
    hash.key?('transaction_type') ? hash['transaction_type'] : SKIP

  # Create object from extracted values.
  QuotationDto.new(items,
                   calculation_mode,
                   exemption_class,
                   exemption_number,
                   tax_date,
                   tax_exempt,
                   transaction_type)
end

.namesObject

A mapping from model property names to API property names.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/new_store_api/models/quotation_dto.rb', line 51

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['calculation_mode'] = 'calculation_mode'
  @_hash['exemption_class'] = 'exemption_class'
  @_hash['exemption_number'] = 'exemption_number'
  @_hash['items'] = 'items'
  @_hash['tax_date'] = 'tax_date'
  @_hash['tax_exempt'] = 'tax_exempt'
  @_hash['transaction_type'] = 'transaction_type'
  @_hash
end

.nullablesObject

An array for nullable fields



76
77
78
# File 'lib/new_store_api/models/quotation_dto.rb', line 76

def self.nullables
  []
end

.optionalsObject

An array for optional fields



64
65
66
67
68
69
70
71
72
73
# File 'lib/new_store_api/models/quotation_dto.rb', line 64

def self.optionals
  %w[
    calculation_mode
    exemption_class
    exemption_number
    tax_date
    tax_exempt
    transaction_type
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (QuotationDto | Hash)

    value against the validation is performed.



131
132
133
134
135
136
137
138
139
140
141
# File 'lib/new_store_api/models/quotation_dto.rb', line 131

def self.validate(value)
  if value.instance_of? self
    return UnionTypeLookUp.get(:QuotationDtoItems)
                          .validate(value.items)
  end

  return false unless value.instance_of? Hash

  UnionTypeLookUp.get(:QuotationDtoItems)
                 .validate(value['items'])
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



152
153
154
155
156
157
158
# File 'lib/new_store_api/models/quotation_dto.rb', line 152

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} calculation_mode: #{@calculation_mode.inspect}, exemption_class:"\
  " #{@exemption_class.inspect}, exemption_number: #{@exemption_number.inspect}, items:"\
  " #{@items.inspect}, tax_date: #{@tax_date.inspect}, tax_exempt: #{@tax_exempt.inspect},"\
  " transaction_type: #{@transaction_type.inspect}>"
end

#to_custom_tax_dateObject



125
126
127
# File 'lib/new_store_api/models/quotation_dto.rb', line 125

def to_custom_tax_date
  DateTimeHelper.to_rfc3339(tax_date)
end

#to_sObject

Provides a human-readable string representation of the object.



144
145
146
147
148
149
# File 'lib/new_store_api/models/quotation_dto.rb', line 144

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} calculation_mode: #{@calculation_mode}, exemption_class:"\
  " #{@exemption_class}, exemption_number: #{@exemption_number}, items: #{@items}, tax_date:"\
  " #{@tax_date}, tax_exempt: #{@tax_exempt}, transaction_type: #{@transaction_type}>"
end