|
@@ -50,13 +50,13 @@ class Promotion < ActiveRecord::Base
|
|
|
source =
|
|
source =
|
|
|
if category_id.present?
|
|
if category_id.present?
|
|
|
"category_id = #{category_id}"
|
|
"category_id = #{category_id}"
|
|
|
- elsif subcategory_id.present?
|
|
|
|
|
|
|
+ elsif subcategory_id.present? && subcategory_id != "0"
|
|
|
"subcategory_id = #{subcategory_id}"
|
|
"subcategory_id = #{subcategory_id}"
|
|
|
elsif product_id.present?
|
|
elsif product_id.present?
|
|
|
"product_id = #{product_id}"
|
|
"product_id = #{product_id}"
|
|
|
end
|
|
end
|
|
|
if source
|
|
if source
|
|
|
- exists_already = Promotion.where(source).where("start_date < ? and end_date > ?", end_date, start_date).any?
|
|
|
|
|
|
|
+ exists_already = Promotion.activas.where(source).where("start_date < ? AND end_date > ?", end_date, start_date).any?
|
|
|
errors.add(:base, 'Ya existe una promoción activa con los parámetros seleccionados') if exists_already
|
|
errors.add(:base, 'Ya existe una promoción activa con los parámetros seleccionados') if exists_already
|
|
|
end
|
|
end
|
|
|
end
|
|
end
|