Files
Reem-Notas/app/models/consolidacao_entrega.rb

33 lines
1.1 KiB
Ruby

# app/models/consolidacao_entrega.rb
class ConsolidacaoEntrega < ApplicationRecord
belongs_to :consolidacao
enum tipo: {
entrega_normal: 0,
retirada: 1,
bonus: 2,
desconto: 3
}
TIPO_CORES = {
'entrega_normal' => { bg: 'bg-orange-500', text: 'text-white', label: 'Entrega Normal' },
'retirada' => { bg: 'bg-orange-800', text: 'text-white', label: 'Retirada' },
'bonus' => { bg: 'bg-white border border-orange-500', text: 'text-black', label: 'Bônus' },
'desconto' => { bg: 'bg-gray-900', text: 'text-white', label: 'Desconto' }
}.freeze
validates :tracking_id, presence: true, uniqueness: { scope: :consolidacao_id }
validates :motorista_nome, presence: true
validates :tipo, presence: true
validates :valor_aplicado, presence: true, numericality: { greater_than_or_equal_to: 0 }
# Busca a entrega original (leitura do banco existente)
def entrega_original
@entrega_original ||= Entrega.find_by(tracking_id: tracking_id)
end
def tipo_cor
TIPO_CORES[tipo] || TIPO_CORES['entrega_normal']
end
end