Class: LineDiscount

Inherits:
ApplicationRecord show all
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

Instance Attribute Summary collapse

Belongs to collapse

Delegated Instance Attributes collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ApplicationRecord

ransackable_associations, ransackable_attributes, ransackable_scopes, ransortable_attributes, #to_relation

Methods included from Models::EventPublishable

#publish_event

Instance Attribute Details

#amountObject (readonly)



33
# File 'app/models/line_discount.rb', line 33

validates :amount, presence: true, numericality: true

#coupon_idObject (readonly)



36
# File 'app/models/line_discount.rb', line 36

validates :coupon_id, uniqueness: { scope: :line_item_id }

Class Method Details

.auto_appliedActiveRecord::Relation<LineDiscount>

A relation of LineDiscounts that are auto applied. Active Record Scope

Returns:

See Also:



40
# File 'app/models/line_discount.rb', line 40

scope :auto_applied, -> { joins(:coupon).where(Coupon[:auto_apply].eq(true)) }

.manually_appliedActiveRecord::Relation<LineDiscount>

A relation of LineDiscounts that are manually applied. Active Record Scope

Returns:

See Also:



39
# File 'app/models/line_discount.rb', line 39

scope :manually_applied, -> { joins(:coupon).where(Coupon[:auto_apply].not_eq(true)) }

.sortedActiveRecord::Relation<LineDiscount>

A relation of LineDiscounts that are sorted. Active Record Scope

Returns:

See Also:



41
# File 'app/models/line_discount.rb', line 41

scope :sorted, -> { joins(:coupon).merge(Coupon.sorted) }

.visibleActiveRecord::Relation<LineDiscount>

A relation of LineDiscounts that are visible. Active Record Scope

Returns:

See Also:



38
# File 'app/models/line_discount.rb', line 38

scope :visible, -> { where(LineDiscount[:amount].lt(0)) }

Instance Method Details

#couponCoupon

Returns:

See Also:

Validations:



30
# File 'app/models/line_discount.rb', line 30

belongs_to :coupon

#discountDiscount

Returns:

See Also:



29
# File 'app/models/line_discount.rb', line 29

belongs_to :discount, autosave: false

#invisible?Boolean

Returns:

  • (Boolean)


45
46
47
# File 'app/models/line_discount.rb', line 45

def invisible?
  amount == 0
end

#line_itemLineItem

Returns:

See Also:

Validations:



31
# File 'app/models/line_discount.rb', line 31

belongs_to :line_item

#tax_classObject

Alias for Line_item#tax_class

Returns:

  • (Object)

    Line_item#tax_class

See Also:



43
# File 'app/models/line_discount.rb', line 43

delegate :tax_class, to: :line_item