24 lines
586 B
Ruby
Executable File
24 lines
586 B
Ruby
Executable File
class Commission < ApplicationRecord
|
|
self.primary_key = 'commission_id'
|
|
|
|
# primary key - need to be unique
|
|
before_create :generate_custom_id
|
|
|
|
belongs_to :menu_item, foreign_key: 'product_code'
|
|
has_many :commissioners
|
|
has_many :product_commissions
|
|
|
|
# validations
|
|
validates_presence_of :name, :commission_type, :amount
|
|
scope :active, -> {where(is_active: true)}
|
|
private
|
|
def generate_custom_id
|
|
prefix = "COM"
|
|
if ENV["SERVER_MODE"] == 'cloud'
|
|
prefix = "CCOM"
|
|
end
|
|
|
|
self.commission_id = SeedGenerator.generate_id(self.class.name, prefix)
|
|
end
|
|
end
|