Commit 01e4652f9952cd9007302f366abae4805fdd7dfc
1 parent
16f70434
Exists in
master
and in
29 other branches
products: Replace enterprise with profile
Showing
1 changed file
with
14 additions
and
13 deletions
Show diff stats
app/models/product.rb
@@ -17,13 +17,14 @@ class Product < ActiveRecord::Base | @@ -17,13 +17,14 @@ class Product < ActiveRecord::Base | ||
17 | 'full' | 17 | 'full' |
18 | end | 18 | end |
19 | 19 | ||
20 | - belongs_to :enterprise, :foreign_key => :profile_id, :class_name => 'Profile' | ||
21 | belongs_to :profile | 20 | belongs_to :profile |
21 | + # backwards compatibility | ||
22 | + belongs_to :enterprise, :foreign_key => :profile_id, :class_name => 'Profile' | ||
22 | alias_method :enterprise=, :profile= | 23 | alias_method :enterprise=, :profile= |
23 | alias_method :enterprise, :profile | 24 | alias_method :enterprise, :profile |
24 | 25 | ||
25 | - has_one :region, :through => :enterprise | ||
26 | - validates_presence_of :enterprise | 26 | + has_one :region, :through => :profile |
27 | + validates_presence_of :profile | ||
27 | 28 | ||
28 | belongs_to :product_category | 29 | belongs_to :product_category |
29 | 30 | ||
@@ -54,10 +55,10 @@ class Product < ActiveRecord::Base | @@ -54,10 +55,10 @@ class Product < ActiveRecord::Base | ||
54 | after_update :save_image | 55 | after_update :save_image |
55 | 56 | ||
56 | def lat | 57 | def lat |
57 | - self.enterprise.lat | 58 | + self.profile.lat |
58 | end | 59 | end |
59 | def lng | 60 | def lng |
60 | - self.enterprise.lng | 61 | + self.profile.lng |
61 | end | 62 | end |
62 | 63 | ||
63 | xss_terminate :only => [ :name ], :on => 'validation' | 64 | xss_terminate :only => [ :name ], :on => 'validation' |
@@ -71,7 +72,7 @@ class Product < ActiveRecord::Base | @@ -71,7 +72,7 @@ class Product < ActiveRecord::Base | ||
71 | filter_iframes :description | 72 | filter_iframes :description |
72 | 73 | ||
73 | def iframe_whitelist | 74 | def iframe_whitelist |
74 | - enterprise && enterprise.environment && enterprise.environment.trusted_sites_for_iframe | 75 | + self.profile && self.profile.environment && self.profile.environment.trusted_sites_for_iframe |
75 | end | 76 | end |
76 | 77 | ||
77 | def name | 78 | def name |
@@ -109,16 +110,16 @@ class Product < ActiveRecord::Base | @@ -109,16 +110,16 @@ class Product < ActiveRecord::Base | ||
109 | end | 110 | end |
110 | 111 | ||
111 | def url | 112 | def url |
112 | - enterprise.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id) | 113 | + self.profile.public_profile_url.merge(:controller => 'manage_products', :action => 'show', :id => id) |
113 | end | 114 | end |
114 | 115 | ||
115 | def public? | 116 | def public? |
116 | - enterprise.public? | 117 | + self.profile.public? |
117 | end | 118 | end |
118 | 119 | ||
119 | def formatted_value(method) | 120 | def formatted_value(method) |
120 | value = self[method] || self.send(method) | 121 | value = self[method] || self.send(method) |
121 | - ("%.2f" % value).to_s.gsub('.', enterprise.environment.currency_separator) if value | 122 | + ("%.2f" % value).to_s.gsub('.', self.profile.environment.currency_separator) if value |
122 | end | 123 | end |
123 | 124 | ||
124 | def price_with_discount | 125 | def price_with_discount |
@@ -223,16 +224,16 @@ class Product < ActiveRecord::Base | @@ -223,16 +224,16 @@ class Product < ActiveRecord::Base | ||
223 | end | 224 | end |
224 | 225 | ||
225 | def available_production_costs | 226 | def available_production_costs |
226 | - self.enterprise.environment.production_costs + self.enterprise.production_costs | 227 | + self.profile.environment.production_costs + self.profile.production_costs |
227 | end | 228 | end |
228 | 229 | ||
229 | include Rails.application.routes.url_helpers | 230 | include Rails.application.routes.url_helpers |
230 | def price_composition_bar_display_url | 231 | def price_composition_bar_display_url |
231 | - url_for({:host => enterprise.default_hostname, :controller => 'manage_products', :action => 'display_price_composition_bar', :profile => enterprise.identifier, :id => self.id }.merge(Noosfero.url_options)) | 232 | + url_for({:host => self.profile.default_hostname, :controller => 'manage_products', :action => 'display_price_composition_bar', :profile => self.profile.identifier, :id => self.id }.merge(Noosfero.url_options)) |
232 | end | 233 | end |
233 | 234 | ||
234 | def inputs_cost_update_url | 235 | def inputs_cost_update_url |
235 | - url_for({:host => enterprise.default_hostname, :controller => 'manage_products', :action => 'display_inputs_cost', :profile => enterprise.identifier, :id => self.id }.merge(Noosfero.url_options)) | 236 | + url_for({:host => self.profile.default_hostname, :controller => 'manage_products', :action => 'display_inputs_cost', :profile => self.profile.identifier, :id => self.id }.merge(Noosfero.url_options)) |
236 | end | 237 | end |
237 | 238 | ||
238 | def percentage_from_solidarity_economy | 239 | def percentage_from_solidarity_economy |
@@ -249,7 +250,7 @@ class Product < ActiveRecord::Base | @@ -249,7 +250,7 @@ class Product < ActiveRecord::Base | ||
249 | end | 250 | end |
250 | end | 251 | end |
251 | 252 | ||
252 | - delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :enterprise | 253 | + delegate :enabled, :region, :region_id, :environment, :environment_id, :to => :profile, allow_nil: true |
253 | 254 | ||
254 | protected | 255 | protected |
255 | 256 |