End of day commit
This commit is contained in:
+13
-4
@@ -2,14 +2,23 @@ class Employee
|
||||
include SimplyStored::Couch
|
||||
include ActiveModel::SerializerSupport
|
||||
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable #, :omniauthable, :omniauth_providers => [:facebook] #, :token_authenticatable , :registerable
|
||||
view :by_confirmation_token, key: :confirmation_token # devise confirmable
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
||||
property :unconfirmed_email
|
||||
|
||||
property :name
|
||||
property :email
|
||||
#property :email
|
||||
|
||||
view :by_email, key: :email
|
||||
|
||||
validates :email, email: true
|
||||
belongs_to :supplier
|
||||
class << self
|
||||
def count_by_email(email)
|
||||
database.view by_email(key: email, reduce: true)
|
||||
end
|
||||
end
|
||||
|
||||
#validates :email, email: true
|
||||
has_and_belongs_to_many :suppliers, storing_keys: false
|
||||
has_many :orders
|
||||
has_and_belongs_to_many :lists, storing_keys: false
|
||||
|
||||
|
||||
+28
-21
@@ -3,9 +3,7 @@ class Supplier
|
||||
include ActiveModel::SerializerSupport
|
||||
include Supplier::Counters
|
||||
|
||||
view :by_confirmation_token, key: :confirmation_token # devise confirmable
|
||||
devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
||||
property :unconfirmed_email
|
||||
#devise :database_authenticatable, :recoverable, :rememberable, :trackable, :registerable, :confirmable
|
||||
|
||||
property :name
|
||||
property :open, type: :boolean, default: false
|
||||
@@ -19,6 +17,7 @@ class Supplier
|
||||
property :country, default: 'Netherlands'
|
||||
property :facebook_promotion_url
|
||||
property :week_starts_on_monday, type: :boolean, default: true
|
||||
property :employee_settings_storage
|
||||
|
||||
#LOCATION
|
||||
property :lat, type: Float #, default: 52.08062426379751
|
||||
@@ -41,16 +40,13 @@ class Supplier
|
||||
#has_many :lists, through: :tables
|
||||
has_many :orders, dependent: :destroy
|
||||
has_many :sections, dependent: :destroy
|
||||
has_many :employees
|
||||
has_and_belongs_to_many :employees, storing_keys: true
|
||||
|
||||
after_create :add_section_on_create
|
||||
|
||||
view :by_email, key: :email
|
||||
|
||||
validates :name, presence: true
|
||||
validates :email, email: true
|
||||
validates :iens_profile, numericality: {allow_blank: true}
|
||||
validates :password, confirmation: true, presence: {if: ->(r){ r.new_record? }}
|
||||
#validates :password, confirmation: true, presence: {if: ->(r){ r.new_record? }}
|
||||
|
||||
def location=(val)
|
||||
lat, lng = val.is_a?(Array) ? val : val.strip.split(/[ ,]+/).map(&:to_f)
|
||||
@@ -62,6 +58,17 @@ class Supplier
|
||||
[lat, lng].join(',')
|
||||
end
|
||||
|
||||
def add_manager(employee)
|
||||
add_employee employee unless employee_ids.include? employee.id
|
||||
settings = employee_settings.for_employee(employee)
|
||||
settings.is_manager!
|
||||
save and employee
|
||||
end
|
||||
|
||||
def employee_settings
|
||||
SupplierEmployeesSettings.new(self)
|
||||
end
|
||||
|
||||
def active_orders(options = {})
|
||||
return @active_orders if @active_orders && @active_orders_options == options
|
||||
@active_orders_options = options
|
||||
@@ -122,22 +129,22 @@ class Supplier
|
||||
# Options must have the confirmation_token
|
||||
#
|
||||
# Overwrite devise method for mail sending
|
||||
def self.confirm_by_token(confirmation_token)
|
||||
confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
|
||||
send_creation_mail = confirmable.errors.empty? && !confirmable.confirmed?
|
||||
confirmable.confirm! if confirmable.persisted?
|
||||
confirmable.send_creation_notifications if send_creation_mail
|
||||
confirmable
|
||||
end
|
||||
#def self.confirm_by_token(confirmation_token)
|
||||
#confirmable = find_or_initialize_with_error_by(:confirmation_token, confirmation_token)
|
||||
#send_creation_mail = confirmable.errors.empty? && !confirmable.confirmed?
|
||||
#confirmable.confirm! if confirmable.persisted?
|
||||
#confirmable.send_creation_notifications if send_creation_mail
|
||||
#confirmable
|
||||
#end
|
||||
|
||||
# Send confirmation instructions by email
|
||||
def send_confirmation_instructions(*args)
|
||||
self.confirmation_token = nil if reconfirmation_required?
|
||||
@reconfirmation_required = false
|
||||
#def send_confirmation_instructions(*args)
|
||||
#self.confirmation_token = nil if reconfirmation_required?
|
||||
#@reconfirmation_required = false
|
||||
|
||||
@bypass_postpone = true and generate_confirmation_token! if self.confirmation_token.blank?
|
||||
self.devise_mailer.confirmation_instructions(self, confirmation_token).deliver_now
|
||||
end
|
||||
#@bypass_postpone = true and generate_confirmation_token! if self.confirmation_token.blank?
|
||||
#self.devise_mailer.confirmation_instructions(self, confirmation_token).deliver_now
|
||||
#end
|
||||
|
||||
def find_order(id)
|
||||
order = Order.find(id)
|
||||
|
||||
Reference in New Issue
Block a user