bsc.rb
1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
class BscPlugin::Bsc < Enterprise
has_many :enterprises
has_many :enterprise_requests, :class_name => 'BscPlugin::AssociateEnterprise'
has_many :products, :finder_sql => 'select * from products where profile_id in (#{enterprises.map(&:id).join(",")})'
has_many :contracts, :class_name => 'BscPlugin::Contract'
validates_presence_of :nickname
validates_presence_of :company_name
validates_presence_of :cnpj
validates_uniqueness_of :nickname
validates_uniqueness_of :company_name
validates_uniqueness_of :cnpj
before_validation do |bsc|
bsc.name = bsc.business_name || 'Sample name'
end
def already_requested?(enterprise)
enterprise_requests.pending.map(&:enterprise).include?(enterprise)
end
def enterprises_to_token_input
enterprises.map { |enterprise| {:id => enterprise.id, :name => enterprise.name} }
end
def control_panel_settings_button
{:title => _('Bsc info and settings'), :icon => 'edit-profile-enterprise'}
end
def create_product?
false
end
def self.identification
'Bsc'
end
end