class Pipedrive::NewDealProduct
Attributes
Any textual comment associated with this product-deal attachment. Visible and editable in the application UI.
Discount %. If omitted, will be set to 0
Duration of the product (when product durations are not enabled for the company or if omitted, defaults to 1)
Whether the product is enabled on the deal or not. This makes it possible to add products to a deal with specific price and discount criteria - but keep them disabled, which refrains them from being included in deal price calculation. When omitted, the product will be marked as enabled by default.
Price at which this product will be added to the deal
ID of the product that will be attached
ID of the product variation to use. When omitted, no variation will be used.
Quantity – e.g. how many items of this product will be added to the deal
Public Class Methods
Attribute mapping from ruby-style variable name to JSON key.
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 42 def self.attribute_map { :'item_price' => :'item_price', :'quantity' => :'quantity', :'discount_percentage' => :'discount_percentage', :'duration' => :'duration', :'product_variation_id' => :'product_variation_id', :'comments' => :'comments', :'enabled_flag' => :'enabled_flag', :'product_id' => :'product_id' } end
Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 193 def self.build_from_hash(attributes) new.build_from_hash(attributes) end
Initializes the object @param [Hash] attributes Model attributes in the form of hash
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 85 def initialize(attributes = {}) if (!attributes.is_a?(Hash)) fail ArgumentError, "The input argument (attributes) must be a hash in `Pipedrive::NewDealProduct` initialize method" end # check to see if the attribute exists and convert string to symbol for hash key attributes = attributes.each_with_object({}) { |(k, v), h| if (!self.class.attribute_map.key?(k.to_sym)) fail ArgumentError, "`#{k}` is not a valid attribute in `Pipedrive::NewDealProduct`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect end h[k.to_sym] = v } if attributes.key?(:'item_price') self.item_price = attributes[:'item_price'] end if attributes.key?(:'quantity') self.quantity = attributes[:'quantity'] end if attributes.key?(:'discount_percentage') self.discount_percentage = attributes[:'discount_percentage'] else self.discount_percentage = 0 end if attributes.key?(:'duration') self.duration = attributes[:'duration'] else self.duration = 1 end if attributes.key?(:'product_variation_id') self.product_variation_id = attributes[:'product_variation_id'] end if attributes.key?(:'comments') self.comments = attributes[:'comments'] end if attributes.key?(:'enabled_flag') self.enabled_flag = attributes[:'enabled_flag'] end if attributes.key?(:'product_id') self.product_id = attributes[:'product_id'] end end
List of class defined in allOf (OpenAPI v3)
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 76 def self.openapi_all_of [ :'BasicDealProduct', :'NewDealProductAllOf' ] end
List of attributes with nullable: true
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 70 def self.openapi_nullable Set.new([ ]) end
Attribute type mapping.
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 56 def self.openapi_types { :'item_price' => :'Float', :'quantity' => :'Integer', :'discount_percentage' => :'Float', :'duration' => :'Float', :'product_variation_id' => :'Integer', :'comments' => :'String', :'enabled_flag' => :'NumberBoolean', :'product_id' => :'Integer' } end
Public Instance Methods
Checks equality by comparing each attribute. @param [Object] Object to be compared
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 165 def ==(o) return true if self.equal?(o) self.class == o.class && item_price == o.item_price && quantity == o.quantity && discount_percentage == o.discount_percentage && duration == o.duration && product_variation_id == o.product_variation_id && comments == o.comments && enabled_flag == o.enabled_flag && product_id == o.product_id end
Deserializes the data based on type @param string type Data type @param string value Value to be deserialized @return [Object] Deserialized data
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 221 def _deserialize(type, value) case type.to_sym when :DateTime DateTime.parse(value) when :Date Date.parse(value) when :String value.to_s when :Integer value.to_i when :Float value.to_f when :Boolean if value.to_s =~ /\A(true|t|yes|y|1)\z/i true else false end when :Object # generic object (usually a Hash), return directly value when /\AArray<(?<inner_type>.+)>\z/ inner_type = Regexp.last_match[:inner_type] value.map { |v| _deserialize(inner_type, v) } when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/ k_type = Regexp.last_match[:k_type] v_type = Regexp.last_match[:v_type] {}.tap do |hash| value.each do |k, v| hash[_deserialize(k_type, k)] = _deserialize(v_type, v) end end else # model Pipedrive.const_get(type).build_from_hash(value) end end
Outputs non-array value in the form of hash For object, use to_hash. Otherwise, just return the value @param [Object] value Any valid value @return [Hash] Returns the value in the form of hash
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 290 def _to_hash(value) if value.is_a?(Array) value.compact.map { |v| _to_hash(v) } elsif value.is_a?(Hash) {}.tap do |hash| value.each { |k, v| hash[k] = _to_hash(v) } end elsif value.respond_to? :to_hash value.to_hash else value end end
Builds the object from hash @param [Hash] attributes Model attributes in the form of hash @return [Object] Returns the model itself
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 200 def build_from_hash(attributes) return nil unless attributes.is_a?(Hash) self.class.openapi_types.each_pair do |key, type| if type =~ /\AArray<(.*)>/i # check to ensure the input is an array given that the attribute # is documented as an array but the input is not if attributes[self.class.attribute_map[key]].is_a?(Array) self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) }) end elsif !attributes[self.class.attribute_map[key]].nil? self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]])) end # or else data not found in attributes(hash), not an issue as the data can be optional end self end
@see the `==` method @param [Object] Object to be compared
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 180 def eql?(o) self == o end
Calculates hash code according to all attributes. @return [Integer] Hash code
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 186 def hash [item_price, quantity, discount_percentage, duration, product_variation_id, comments, enabled_flag, product_id].hash end
Show invalid properties with the reasons. Usually used together with valid? @return Array for valid properties with the reasons
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 137 def list_invalid_properties invalid_properties = Array.new if @item_price.nil? invalid_properties.push('invalid value for "item_price", item_price cannot be nil.') end if @quantity.nil? invalid_properties.push('invalid value for "quantity", quantity cannot be nil.') end if @product_id.nil? invalid_properties.push('invalid value for "product_id", product_id cannot be nil.') end invalid_properties end
Returns the object in the form of hash @return [Hash] Returns the object in the form of hash
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 272 def to_hash hash = {} self.class.attribute_map.each_pair do |attr, param| value = self.send(attr) if value.nil? is_nullable = self.class.openapi_nullable.include?(attr) next if !is_nullable || (is_nullable && !instance_variable_defined?(:"@#{attr}")) end hash[param] = _to_hash(value) end hash end
Returns the string representation of the object @return [String] String presentation of the object
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 260 def to_s to_hash.to_s end
Check to see if the all the properties in the model are valid @return true if the model is valid
# File lib/pipedrive-openapi-client/models/new_deal_product.rb, line 156 def valid? return false if @item_price.nil? return false if @quantity.nil? return false if @product_id.nil? true end