Class: HhPackage::PricingGroup
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- HhPackage::PricingGroup
- Includes:
- IdentityCache
- Defined in:
- app/models/hh_package/pricing_group.rb
Overview
to store Come more pay less (comemorePayless/comemore_payless) feature
Instance Method Summary collapse
- #come_pay_label ⇒ Object
-
#sync_dates_with_restaurant_packages ⇒ Object
Synchronizes the start_date and end_date of the pricing group with the associated restaurant packages.
-
#valid_to_show_as_preview? ⇒ Boolean
if start date and end date are blank, it means it's valid for all dates because for the old pricing_group data in database, we don't have start_date and end_date so we need to show it as preview.
Methods inherited from ApplicationRecord
Instance Method Details
#come_pay_label ⇒ Object
72 73 74 75 76 77 78 79 80 |
# File 'app/models/hh_package/pricing_group.rb', line 72 def come_pay_label package_type = package.package_attr.package_type.to_s # Use safe_constantize to avoid crashing if the class is missing klass = package_type.safe_constantize promo_type = klass ? klass::TYPE_SHORT : '' I18n.t("views.package.promo.come_pay_less.#{promo_type}", locale: :en) end |
#sync_dates_with_restaurant_packages ⇒ Object
Synchronizes the start_date and end_date of the pricing group with the associated restaurant packages. It calculates the earliest start_date and the latest end_date from the restaurant packages and assigns them to the pricing group. If no restaurant packages are present, it does nothing.
52 53 54 55 56 57 58 59 60 |
# File 'app/models/hh_package/pricing_group.rb', line 52 def sync_dates_with_restaurant_packages return if package.blank? || package.restaurant_packages.blank? rp_dates = package.restaurant_packages.pluck(:start_date, :end_date).compact return if rp_dates.blank? self.start_date = rp_dates.map(&:first).compact.min self.end_date = rp_dates.map(&:last).compact.max end |
#valid_to_show_as_preview? ⇒ Boolean
if start date and end date are blank, it means it's valid for all dates because for the old pricing_group data in database, we don't have start_date and end_date so we need to show it as preview
65 66 67 68 69 70 |
# File 'app/models/hh_package/pricing_group.rb', line 65 def valid_to_show_as_preview? return true if start_date.blank? && end_date.blank? return false if end_date.present? && end_date.past? true end |