Class: LineDiscount
- Inherits:
-
ApplicationRecord
- Object
- ActiveRecord::Base
- ApplicationRecord
- LineDiscount
- Defined in:
- app/models/line_discount.rb
Overview
== Schema Information
Table name: line_discounts
Database name: primary
id :integer not null, primary key
amount :decimal(10, 2) default(0.0), not null
created_at :datetime
updated_at :datetime
coupon_id :integer
creator_id :integer
discount_id :integer not null
line_item_id :integer
updater_id :integer
Indexes
index_line_discounts_uniqueness (line_item_id,discount_id) UNIQUE
line_discounts_coupon_id_idx (coupon_id)
line_discounts_discount_id_idx (discount_id)
Foreign Keys
line_discounts_coupon_id_fkey (coupon_id => coupons.id)
line_discounts_discount_id_fkey (discount_id => discounts.id) ON DELETE => cascade
line_discounts_line_item_id_fk (line_item_id => line_items.id) ON DELETE => cascade
Constant Summary
Constants included from Schedulable
Schedulable::SIMPLE_FORM_OPTIONS
Instance Attribute Summary collapse
- #amount ⇒ Object readonly
- #coupon_id ⇒ Object readonly
Belongs to collapse
Delegated Instance Attributes collapse
-
#tax_class ⇒ Object
Alias for Line_item#tax_class.
Class Method Summary collapse
-
.auto_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are auto applied.
-
.manually_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are manually applied.
-
.sorted ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are sorted.
-
.visible ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are visible.
Instance Method Summary collapse
Methods inherited from ApplicationRecord
ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation
Methods included from Schedulable
Methods included from Models::AfterCommittable
Methods included from Models::EventPublishable
Instance Attribute Details
#amount ⇒ Object (readonly)
34 |
# File 'app/models/line_discount.rb', line 34 validates :amount, presence: true, numericality: true |
#coupon_id ⇒ Object (readonly)
35 |
# File 'app/models/line_discount.rb', line 35 validates :coupon_id, uniqueness: { scope: :line_item_id } |
Class Method Details
.auto_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are auto applied. Active Record Scope
39 |
# File 'app/models/line_discount.rb', line 39 scope :auto_applied, -> { joins(:coupon).where(Coupon[:auto_apply].eq(true)) } |
.manually_applied ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are manually applied. Active Record Scope
38 |
# File 'app/models/line_discount.rb', line 38 scope :manually_applied, -> { joins(:coupon).where(Coupon[:auto_apply].not_eq(true)) } |
.sorted ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are sorted. Active Record Scope
40 |
# File 'app/models/line_discount.rb', line 40 scope :sorted, -> { joins(:coupon).merge(Coupon.sorted) } |
.visible ⇒ ActiveRecord::Relation<LineDiscount>
A relation of LineDiscounts that are visible. Active Record Scope
37 |
# File 'app/models/line_discount.rb', line 37 scope :visible, -> { where(LineDiscount[:amount].lt(0)) } |
Instance Method Details
#discount ⇒ Discount
30 |
# File 'app/models/line_discount.rb', line 30 belongs_to :discount, autosave: false |
#invisible? ⇒ Boolean
44 45 46 |
# File 'app/models/line_discount.rb', line 44 def invisible? amount == 0 end |
#tax_class ⇒ Object
Alias for Line_item#tax_class
42 |
# File 'app/models/line_discount.rb', line 42 delegate :tax_class, to: :line_item |