Class: MercadoPublicoCl::Resources::PurchaseOrder
- Inherits:
-
Data
- Object
- Data
- MercadoPublicoCl::Resources::PurchaseOrder
- Extended by:
- Base::ClassMethods
- Defined in:
- lib/mercado_publico_cl/resources/purchase_order.rb
Instance Attribute Summary collapse
-
#buyer ⇒ Object
readonly
Returns the value of attribute buyer.
-
#charge_amount ⇒ Object
readonly
Returns the value of attribute charge_amount.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#country ⇒ Object
readonly
Returns the value of attribute country.
-
#currency ⇒ Object
readonly
Returns the value of attribute currency.
-
#currency_code ⇒ Object
readonly
Returns the value of attribute currency_code.
-
#dates ⇒ Object
readonly
Returns the value of attribute dates.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#discount_amount ⇒ Object
readonly
Returns the value of attribute discount_amount.
-
#dispatch_type ⇒ Object
readonly
Returns the value of attribute dispatch_type.
-
#dispatch_type_code ⇒ Object
readonly
Returns the value of attribute dispatch_type_code.
-
#funding_source ⇒ Object
readonly
Returns the value of attribute funding_source.
-
#has_items ⇒ Object
readonly
Returns the value of attribute has_items.
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#iva_percentage ⇒ Object
readonly
Returns the value of attribute iva_percentage.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#net_amount ⇒ Object
readonly
Returns the value of attribute net_amount.
-
#payment_type ⇒ Object
readonly
Returns the value of attribute payment_type.
-
#payment_type_code ⇒ Object
readonly
Returns the value of attribute payment_type_code.
-
#purchase_order_type ⇒ Object
readonly
Returns the value of attribute purchase_order_type.
-
#purchase_order_type_code ⇒ Object
readonly
Returns the value of attribute purchase_order_type_code.
-
#purchase_order_type_label ⇒ Object
readonly
Returns the value of attribute purchase_order_type_label.
-
#rating ⇒ Object
readonly
Returns the value of attribute rating.
-
#rating_count ⇒ Object
readonly
Returns the value of attribute rating_count.
-
#raw ⇒ Object
readonly
Returns the value of attribute raw.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
-
#status_code ⇒ Object
readonly
Returns the value of attribute status_code.
-
#status_label ⇒ Object
readonly
Returns the value of attribute status_label.
-
#supplier_status ⇒ Object
readonly
Returns the value of attribute supplier_status.
-
#supplier_status_code ⇒ Object
readonly
Returns the value of attribute supplier_status_code.
-
#supplier_status_label ⇒ Object
readonly
Returns the value of attribute supplier_status_label.
-
#tax_amount ⇒ Object
readonly
Returns the value of attribute tax_amount.
-
#tender_code ⇒ Object
readonly
Returns the value of attribute tender_code.
-
#total_amount ⇒ Object
readonly
Returns the value of attribute total_amount.
-
#vendor ⇒ Object
readonly
Returns the value of attribute vendor.
Class Method Summary collapse
- .all ⇒ Object
- .endpoint ⇒ Object
- .extract_attributes(raw) ⇒ Object
- .find(code) ⇒ Object
- .from_payload(raw) ⇒ Object
- .presence(value) ⇒ Object
- .where(date: nil, status: nil, supplier_code: nil, agency_code: nil) ⇒ Object
Instance Method Summary collapse
- #acceptance_date ⇒ Object
- #agency_code ⇒ Object
- #agency_name ⇒ Object
- #cancellation_date ⇒ Object
- #creation_date ⇒ Object
- #has_items? ⇒ Boolean
- #inspect ⇒ Object (also: #to_s)
- #last_modified_at ⇒ Object
- #sent_date ⇒ Object
- #summary? ⇒ Boolean
- #supplier_code ⇒ Object
- #supplier_name ⇒ Object
Methods included from Base::ClassMethods
client, detail_payload, extract_list, fetch_list, fetch_single, list_key
Instance Attribute Details
#buyer ⇒ Object (readonly)
Returns the value of attribute buyer
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def buyer @buyer end |
#charge_amount ⇒ Object (readonly)
Returns the value of attribute charge_amount
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def charge_amount @charge_amount end |
#code ⇒ Object (readonly)
Returns the value of attribute code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def code @code end |
#country ⇒ Object (readonly)
Returns the value of attribute country
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def country @country end |
#currency ⇒ Object (readonly)
Returns the value of attribute currency
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def currency @currency end |
#currency_code ⇒ Object (readonly)
Returns the value of attribute currency_code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def currency_code @currency_code end |
#dates ⇒ Object (readonly)
Returns the value of attribute dates
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def dates @dates end |
#description ⇒ Object (readonly)
Returns the value of attribute description
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def description @description end |
#discount_amount ⇒ Object (readonly)
Returns the value of attribute discount_amount
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def discount_amount @discount_amount end |
#dispatch_type ⇒ Object (readonly)
Returns the value of attribute dispatch_type
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def dispatch_type @dispatch_type end |
#dispatch_type_code ⇒ Object (readonly)
Returns the value of attribute dispatch_type_code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def dispatch_type_code @dispatch_type_code end |
#funding_source ⇒ Object (readonly)
Returns the value of attribute funding_source
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def funding_source @funding_source end |
#has_items ⇒ Object (readonly)
Returns the value of attribute has_items
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def has_items @has_items end |
#items ⇒ Object (readonly)
Returns the value of attribute items
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def items @items end |
#iva_percentage ⇒ Object (readonly)
Returns the value of attribute iva_percentage
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def iva_percentage @iva_percentage end |
#name ⇒ Object (readonly)
Returns the value of attribute name
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def name @name end |
#net_amount ⇒ Object (readonly)
Returns the value of attribute net_amount
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def net_amount @net_amount end |
#payment_type ⇒ Object (readonly)
Returns the value of attribute payment_type
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def payment_type @payment_type end |
#payment_type_code ⇒ Object (readonly)
Returns the value of attribute payment_type_code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def payment_type_code @payment_type_code end |
#purchase_order_type ⇒ Object (readonly)
Returns the value of attribute purchase_order_type
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def purchase_order_type @purchase_order_type end |
#purchase_order_type_code ⇒ Object (readonly)
Returns the value of attribute purchase_order_type_code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def purchase_order_type_code @purchase_order_type_code end |
#purchase_order_type_label ⇒ Object (readonly)
Returns the value of attribute purchase_order_type_label
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def purchase_order_type_label @purchase_order_type_label end |
#rating ⇒ Object (readonly)
Returns the value of attribute rating
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def @rating end |
#rating_count ⇒ Object (readonly)
Returns the value of attribute rating_count
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def @rating_count end |
#raw ⇒ Object (readonly)
Returns the value of attribute raw
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def raw @raw end |
#status ⇒ Object (readonly)
Returns the value of attribute status
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def status @status end |
#status_code ⇒ Object (readonly)
Returns the value of attribute status_code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def status_code @status_code end |
#status_label ⇒ Object (readonly)
Returns the value of attribute status_label
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def status_label @status_label end |
#supplier_status ⇒ Object (readonly)
Returns the value of attribute supplier_status
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def supplier_status @supplier_status end |
#supplier_status_code ⇒ Object (readonly)
Returns the value of attribute supplier_status_code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def supplier_status_code @supplier_status_code end |
#supplier_status_label ⇒ Object (readonly)
Returns the value of attribute supplier_status_label
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def supplier_status_label @supplier_status_label end |
#tax_amount ⇒ Object (readonly)
Returns the value of attribute tax_amount
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def tax_amount @tax_amount end |
#tender_code ⇒ Object (readonly)
Returns the value of attribute tender_code
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def tender_code @tender_code end |
#total_amount ⇒ Object (readonly)
Returns the value of attribute total_amount
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def total_amount @total_amount end |
#vendor ⇒ Object (readonly)
Returns the value of attribute vendor
5 6 7 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 5 def vendor @vendor end |
Class Method Details
.all ⇒ Object
55 56 57 58 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 55 def self.all query = Query.new(resource: :purchase_order, params: { status: :all }) fetch_list(query.to_h) end |
.endpoint ⇒ Object
44 45 46 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 44 def self.endpoint "/servicios/v1/publico/ordenesdecompra.json" end |
.extract_attributes(raw) ⇒ Object
71 72 73 74 75 76 77 78 79 80 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 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 71 def self.extract_attributes(raw) status_code = Base.to_int(raw["CodigoEstado"]) supplier_status_code = Base.to_int(raw["CodigoEstadoProveedor"]) po_type_code = Base.to_int(raw["CodigoTipo"]) currency_code = raw["TipoMoneda"] || raw["Moneda"] dispatch_code = Base.to_int(raw["TipoDespacho"] || raw["CodigoTipoDespacho"]) payment_code = Base.to_int(raw["FormaPago"] || raw["CodigoTipoPago"]) { code: raw["Codigo"] || raw["CodigoExterno"], name: raw["Nombre"], description: raw["Descripcion"], status: Enums::PurchaseOrderStatus.to_symbol(status_code), status_code: status_code, status_label: raw["Estado"], supplier_status: Enums::SupplierOrderStatus.to_symbol(supplier_status_code), supplier_status_code: supplier_status_code, supplier_status_label: raw["EstadoProveedor"], tender_code: presence(raw["CodigoLicitacion"]), purchase_order_type: Enums::PurchaseOrderType.to_symbol(po_type_code), purchase_order_type_code: po_type_code, purchase_order_type_label: raw["Tipo"], currency: Enums::Currency.to_symbol(currency_code), currency_code: currency_code, total_amount: Base.to_float(raw["Total"] || raw["MontoTotal"]), net_amount: Base.to_float(raw["TotalNeto"]), tax_amount: Base.to_float(raw["Impuestos"]), iva_percentage: Base.to_float(raw["PorcentajeIva"]), discount_amount: Base.to_float(raw["Descuentos"]), charge_amount: Base.to_float(raw["Cargos"]), dispatch_type: Enums::DispatchType.to_symbol(dispatch_code), dispatch_type_code: dispatch_code, payment_type: Enums::PurchaseOrderPaymentMethod.to_symbol(payment_code), payment_type_code: payment_code, funding_source: raw["Financiamiento"], country: raw["Pais"], has_items: Base.to_bool(raw["TieneItems"]), rating: Base.to_float(raw["PromedioCalificacion"]), rating_count: Base.to_int(raw["CantidadEvaluacion"]), buyer: POBuyer.from_payload(raw["Comprador"]), vendor: POVendor.from_payload(raw["Proveedor"]), items: Array(raw.dig("Items", "Listado")).map { |item| POItem.from_payload(item) }, dates: PODates.from_payload(raw["Fechas"]), raw: raw } end |
.find(code) ⇒ Object
48 49 50 51 52 53 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 48 def self.find(code) raise InvalidQueryError, "code is required" if code.nil? || code.to_s.strip.empty? query = Query.new(resource: :purchase_order, params: { code: code }) fetch_single(query.to_h) end |
.from_payload(raw) ⇒ Object
67 68 69 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 67 def self.from_payload(raw) new(**extract_attributes(raw)) end |
.presence(value) ⇒ Object
118 119 120 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 118 def self.presence(value) value.nil? || value.to_s.empty? ? nil : value end |
.where(date: nil, status: nil, supplier_code: nil, agency_code: nil) ⇒ Object
60 61 62 63 64 65 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 60 def self.where(date: nil, status: nil, supplier_code: nil, agency_code: nil) params = { date: date, status: status, supplier_code: supplier_code, agency_code: agency_code } .reject { |_, v| v.nil? } query = Query.new(resource: :purchase_order, params: params) fetch_list(query.to_h) end |
Instance Method Details
#acceptance_date ⇒ Object
150 151 152 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 150 def acceptance_date dates&.acceptance end |
#agency_code ⇒ Object
134 135 136 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 134 def agency_code buyer&.code end |
#agency_name ⇒ Object
138 139 140 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 138 def agency_name buyer&.name end |
#cancellation_date ⇒ Object
154 155 156 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 154 def cancellation_date dates&.cancellation end |
#creation_date ⇒ Object
142 143 144 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 142 def creation_date dates&.creation end |
#has_items? ⇒ Boolean
122 123 124 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 122 def has_items? has_items == true end |
#inspect ⇒ Object Also known as: to_s
166 167 168 169 170 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 166 def inspect "#<MercadoPublicoCl::PurchaseOrder code=#{code.inspect} status=#{status.inspect} " \ "type=#{purchase_order_type.inspect} total=#{total_amount.inspect} " \ "supplier=#{supplier_name.inspect} agency=#{agency_name.inspect}>" end |
#last_modified_at ⇒ Object
158 159 160 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 158 def last_modified_at dates&.last_modified end |
#sent_date ⇒ Object
146 147 148 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 146 def sent_date dates&.sent end |
#summary? ⇒ Boolean
162 163 164 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 162 def summary? raw["Comprador"].nil? && raw["Proveedor"].nil? && raw["Items"].nil? && raw["Fechas"].nil? end |
#supplier_code ⇒ Object
126 127 128 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 126 def supplier_code vendor&.code end |
#supplier_name ⇒ Object
130 131 132 |
# File 'lib/mercado_publico_cl/resources/purchase_order.rb', line 130 def supplier_name vendor&.name end |