Class: NewStoreApi::QuotationTotalsDto

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

Overview

QuotationTotalsDto 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(discount_total = nil, grand_total = nil, net_total = nil, shipping_tax_amount = nil, shipping_total = nil, subtotal = nil, tax_rates_summary = nil, tax_strategy = nil, tax_total = nil) ⇒ QuotationTotalsDto

Returns a new instance of QuotationTotalsDto.



81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 81

def initialize(discount_total = nil, grand_total = nil, net_total = nil,
               shipping_tax_amount = nil, shipping_total = nil,
               subtotal = nil, tax_rates_summary = nil, tax_strategy = nil,
               tax_total = nil)
  @discount_total = discount_total
  @grand_total = grand_total
  @net_total = net_total
  @shipping_tax_amount = shipping_tax_amount
  @shipping_total = shipping_total
  @subtotal = subtotal
  @tax_rates_summary = tax_rates_summary
  @tax_strategy = tax_strategy
  @tax_total = tax_total
end

Instance Attribute Details

#discount_totalInteger

The total discount amount, in the currency's minor unit.

Returns:

  • (Integer)


14
15
16
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 14

def discount_total
  @discount_total
end

#grand_totalInteger

The amount consumer has to pay for the order, in the currency's minor unit.

Returns:

  • (Integer)


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

def grand_total
  @grand_total
end

#net_totalInteger

The sum of net prices of all the items including shipping and gift wrapping, in the currency's minor unit.

Returns:

  • (Integer)


24
25
26
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 24

def net_total
  @net_total
end

#shipping_tax_amountInteger

The shipping tax amount, in the currency's minor unit.

Returns:

  • (Integer)


28
29
30
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 28

def shipping_tax_amount
  @shipping_tax_amount
end

#shipping_totalInteger

The total shipping amount, in the currency's minor unit.

Returns:

  • (Integer)


32
33
34
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 32

def shipping_total
  @shipping_total
end

#subtotalInteger

The sum of item prices incl. or excl. tax (depending on tax method), in the currency's minor unit.

Returns:

  • (Integer)


37
38
39
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 37

def subtotal
  @subtotal
end

#tax_rates_summaryArray[EnrichedQuotationTaxRateDto]

Summary of the tax rates applied on the line items of the transaction grouped by the tax name and tax rate. Monetary fields are in the currency's minor unit.

Returns:



43
44
45
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 43

def tax_rates_summary
  @tax_rates_summary
end

#tax_strategyTaxCalculationStrategyEnum

Summary of the tax rates applied on the line items of the transaction grouped by the tax name and tax rate. Monetary fields are in the currency's minor unit.



49
50
51
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 49

def tax_strategy
  @tax_strategy
end

#tax_totalInteger

The total tax sum (grand total tax incl. shipping tax), in the currency's minor unit.

Returns:

  • (Integer)


54
55
56
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 54

def tax_total
  @tax_total
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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
124
125
126
127
128
129
130
131
132
133
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 97

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  discount_total =
    hash.key?('discount_total') ? hash['discount_total'] : nil
  grand_total = hash.key?('grand_total') ? hash['grand_total'] : nil
  net_total = hash.key?('net_total') ? hash['net_total'] : nil
  shipping_tax_amount =
    hash.key?('shipping_tax_amount') ? hash['shipping_tax_amount'] : nil
  shipping_total =
    hash.key?('shipping_total') ? hash['shipping_total'] : nil
  subtotal = hash.key?('subtotal') ? hash['subtotal'] : nil
  # Parameter is an array, so we need to iterate through it
  tax_rates_summary = nil
  unless hash['tax_rates_summary'].nil?
    tax_rates_summary = []
    hash['tax_rates_summary'].each do |structure|
      tax_rates_summary << (EnrichedQuotationTaxRateDto.from_hash(structure) if structure)
    end
  end

  tax_rates_summary = nil unless hash.key?('tax_rates_summary')
  tax_strategy = hash.key?('tax_strategy') ? hash['tax_strategy'] : nil
  tax_total = hash.key?('tax_total') ? hash['tax_total'] : nil

  # Create object from extracted values.
  QuotationTotalsDto.new(discount_total,
                         grand_total,
                         net_total,
                         shipping_tax_amount,
                         shipping_total,
                         subtotal,
                         tax_rates_summary,
                         tax_strategy,
                         tax_total)
end

.namesObject

A mapping from model property names to API property names.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 57

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['discount_total'] = 'discount_total'
  @_hash['grand_total'] = 'grand_total'
  @_hash['net_total'] = 'net_total'
  @_hash['shipping_tax_amount'] = 'shipping_tax_amount'
  @_hash['shipping_total'] = 'shipping_total'
  @_hash['subtotal'] = 'subtotal'
  @_hash['tax_rates_summary'] = 'tax_rates_summary'
  @_hash['tax_strategy'] = 'tax_strategy'
  @_hash['tax_total'] = 'tax_total'
  @_hash
end

.nullablesObject

An array for nullable fields



77
78
79
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 77

def self.nullables
  []
end

.optionalsObject

An array for optional fields



72
73
74
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 72

def self.optionals
  []
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



145
146
147
148
149
150
151
152
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 145

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_total: #{@discount_total.inspect}, grand_total:"\
  " #{@grand_total.inspect}, net_total: #{@net_total.inspect}, shipping_tax_amount:"\
  " #{@shipping_tax_amount.inspect}, shipping_total: #{@shipping_total.inspect}, subtotal:"\
  " #{@subtotal.inspect}, tax_rates_summary: #{@tax_rates_summary.inspect}, tax_strategy:"\
  " #{@tax_strategy.inspect}, tax_total: #{@tax_total.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



136
137
138
139
140
141
142
# File 'lib/new_store_api/models/quotation_totals_dto.rb', line 136

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} discount_total: #{@discount_total}, grand_total: #{@grand_total},"\
  " net_total: #{@net_total}, shipping_tax_amount: #{@shipping_tax_amount}, shipping_total:"\
  " #{@shipping_total}, subtotal: #{@subtotal}, tax_rates_summary: #{@tax_rates_summary},"\
  " tax_strategy: #{@tax_strategy}, tax_total: #{@tax_total}>"
end