Fix rubocop issues in adjustment_decorator, line_item_decorator and product_decorator

This commit is contained in:
luisramos0
2019-05-28 16:38:15 +01:00
parent ced6264846
commit f2bfb9bedb
3 changed files with 29 additions and 11 deletions

View File

@@ -8,11 +8,14 @@ module Spree
# So we don't need the option `dependent: :destroy` as long as
# AdjustmentMetadata has no destroy logic itself.
has_one :metadata, class_name: 'AdjustmentMetadata'
belongs_to :tax_rate, foreign_key: 'originator_id', conditions: "spree_adjustments.originator_type = 'Spree::TaxRate'"
belongs_to :tax_rate, foreign_key: 'originator_id',
conditions: "spree_adjustments.originator_type = 'Spree::TaxRate'"
scope :enterprise_fee, -> { where(originator_type: 'EnterpriseFee') }
scope :admin, -> { where(source_type: nil, originator_type: nil) }
scope :included_tax, -> { where(originator_type: 'Spree::TaxRate', adjustable_type: 'Spree::LineItem') }
scope :included_tax, -> {
where(originator_type: 'Spree::TaxRate', adjustable_type: 'Spree::LineItem')
}
scope :with_tax, -> { where('spree_adjustments.included_tax > 0') }
scope :without_tax, -> { where('spree_adjustments.included_tax = 0') }

View File

@@ -38,7 +38,10 @@ Spree::LineItem.class_eval do
# Find line items that are from order sorted by variant name and unit value
scope :sorted_by_name_and_unit_value, -> {
joins(variant: :product).
reorder('lower(spree_products.name) asc, lower(spree_variants.display_name) asc, spree_variants.unit_value asc')
reorder("
lower(spree_products.name) asc,
lower(spree_variants.display_name) asc,
spree_variants.unit_value asc")
}
scope :from_order_cycle, lambda { |order_cycle|
@@ -57,14 +60,18 @@ Spree::LineItem.class_eval do
scope :with_tax, -> {
joins(:adjustments).
where('spree_adjustments.originator_type = ?', 'Spree::TaxRate').
select('DISTINCT spree_line_items.*')
where('spree_adjustments.originator_type = ?', 'Spree::TaxRate').
select('DISTINCT spree_line_items.*')
}
# Line items without a Spree::TaxRate-originated adjustment
scope :without_tax, -> {
joins("LEFT OUTER JOIN spree_adjustments ON (spree_adjustments.adjustable_id=spree_line_items.id AND spree_adjustments.adjustable_type = 'Spree::LineItem' AND spree_adjustments.originator_type='Spree::TaxRate')").
where('spree_adjustments.id IS NULL')
joins("
LEFT OUTER JOIN spree_adjustments
ON (spree_adjustments.adjustable_id=spree_line_items.id
AND spree_adjustments.adjustable_type = 'Spree::LineItem'
AND spree_adjustments.originator_type='Spree::TaxRate')").
where('spree_adjustments.id IS NULL')
}
def cap_quantity_at_stock!

View File

@@ -42,10 +42,18 @@ Spree::Product.class_eval do
# -- Joins
scope :with_order_cycles_outer, -> {
joins('LEFT OUTER JOIN spree_variants AS o_spree_variants ON (o_spree_variants.product_id = spree_products.id)').
joins('LEFT OUTER JOIN exchange_variants AS o_exchange_variants ON (o_exchange_variants.variant_id = o_spree_variants.id)').
joins('LEFT OUTER JOIN exchanges AS o_exchanges ON (o_exchanges.id = o_exchange_variants.exchange_id)').
joins('LEFT OUTER JOIN order_cycles AS o_order_cycles ON (o_order_cycles.id = o_exchanges.order_cycle_id)')
joins("
LEFT OUTER JOIN spree_variants AS o_spree_variants
ON (o_spree_variants.product_id = spree_products.id)").
joins("
LEFT OUTER JOIN exchange_variants AS o_exchange_variants
ON (o_exchange_variants.variant_id = o_spree_variants.id)").
joins("
LEFT OUTER JOIN exchanges AS o_exchanges
ON (o_exchanges.id = o_exchange_variants.exchange_id)").
joins("
LEFT OUTER JOIN order_cycles AS o_order_cycles
ON (o_order_cycles.id = o_exchanges.order_cycle_id)")
}
scope :with_order_cycles_inner, -> {