-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix class/module nesting #2098
Fix class/module nesting #2098
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,27 @@ | ||
module Spree | ||
class Reimbursement::Credit < Spree::Base | ||
class_attribute :default_creditable_class | ||
self.default_creditable_class = Spree::StoreCredit | ||
class Reimbursement < Spree::Base | ||
class Credit < Spree::Base | ||
class_attribute :default_creditable_class | ||
self.default_creditable_class = Spree::StoreCredit | ||
|
||
belongs_to :reimbursement, inverse_of: :credits | ||
belongs_to :creditable, polymorphic: true | ||
belongs_to :reimbursement, inverse_of: :credits | ||
belongs_to :creditable, polymorphic: true | ||
|
||
validates :creditable, presence: true | ||
validates :creditable, presence: true | ||
|
||
class << self | ||
def total_amount_reimbursed_for(reimbursement) | ||
reimbursement.credits.to_a.sum(&:amount) | ||
class << self | ||
def total_amount_reimbursed_for(reimbursement) | ||
reimbursement.credits.to_a.sum(&:amount) | ||
end | ||
end | ||
end | ||
|
||
def description | ||
creditable.class.name.demodulize | ||
end | ||
def description | ||
creditable.class.name.demodulize | ||
end | ||
|
||
def display_amount | ||
Spree::Money.new(amount, { currency: creditable.try(:currency) || "USD" }) | ||
def display_amount | ||
Spree::Money.new(amount, { currency: creditable.try(:currency) || "USD" }) | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,28 @@ | ||
module Spree | ||
class Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
attr_reader :errors | ||
class ReturnItem < Spree::Base | ||
module EligibilityValidator | ||
class BaseValidator | ||
attr_reader :errors | ||
|
||
def initialize(return_item) | ||
@return_item = return_item | ||
@errors = {} | ||
end | ||
def initialize(return_item) | ||
@return_item = return_item | ||
@errors = {} | ||
end | ||
|
||
def eligible_for_return? | ||
raise NotImplementedError, Spree.t(:implement_eligible_for_return) | ||
end | ||
def eligible_for_return? | ||
raise NotImplementedError, Spree.t(:implement_eligible_for_return) | ||
end | ||
|
||
def requires_manual_intervention? | ||
raise NotImplementedError, Spree.t(:implement_requires_manual_intervention) | ||
end | ||
def requires_manual_intervention? | ||
raise NotImplementedError, Spree.t(:implement_requires_manual_intervention) | ||
end | ||
|
||
private | ||
private | ||
|
||
def add_error(key, error) | ||
@errors[key] = error | ||
def add_error(key, error) | ||
@errors[key] = error | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,30 +1,34 @@ | ||
module Spree | ||
class ReturnItem::EligibilityValidator::Default < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
class_attribute :permitted_eligibility_validators | ||
self.permitted_eligibility_validators = [ | ||
ReturnItem::EligibilityValidator::OrderCompleted, | ||
ReturnItem::EligibilityValidator::TimeSincePurchase, | ||
ReturnItem::EligibilityValidator::RMARequired, | ||
ReturnItem::EligibilityValidator::InventoryShipped, | ||
ReturnItem::EligibilityValidator::NoReimbursements | ||
] | ||
class ReturnItem < Spree::Base | ||
module EligibilityValidator | ||
class Default < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
class_attribute :permitted_eligibility_validators | ||
self.permitted_eligibility_validators = [ | ||
ReturnItem::EligibilityValidator::OrderCompleted, | ||
ReturnItem::EligibilityValidator::TimeSincePurchase, | ||
ReturnItem::EligibilityValidator::RMARequired, | ||
ReturnItem::EligibilityValidator::InventoryShipped, | ||
ReturnItem::EligibilityValidator::NoReimbursements | ||
] | ||
|
||
def eligible_for_return? | ||
validators.all?(&:eligible_for_return?) | ||
end | ||
def eligible_for_return? | ||
validators.all?(&:eligible_for_return?) | ||
end | ||
|
||
def requires_manual_intervention? | ||
validators.any?(&:requires_manual_intervention?) | ||
end | ||
def requires_manual_intervention? | ||
validators.any?(&:requires_manual_intervention?) | ||
end | ||
|
||
def errors | ||
validators.map(&:errors).reduce({}, :merge) | ||
end | ||
def errors | ||
validators.map(&:errors).reduce({}, :merge) | ||
end | ||
|
||
private | ||
private | ||
|
||
def validators | ||
@validators ||= permitted_eligibility_validators.map{ |v| v.new(@return_item) } | ||
def validators | ||
@validators ||= permitted_eligibility_validators.map{ |v| v.new(@return_item) } | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
module Spree | ||
class ReturnItem::EligibilityValidator::InventoryShipped < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.shipped? | ||
return true | ||
else | ||
add_error(:inventory_unit_shipped, Spree.t('return_item_inventory_unit_ineligible')) | ||
return false | ||
end | ||
end | ||
class ReturnItem < Spree::Base | ||
module EligibilityValidator | ||
class InventoryShipped < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.shipped? | ||
return true | ||
else | ||
add_error(:inventory_unit_shipped, Spree.t('return_item_inventory_unit_ineligible')) | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
end | ||
end | ||
|
||
def requires_manual_intervention? | ||
@errors.present? | ||
def requires_manual_intervention? | ||
@errors.present? | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,21 @@ | ||
module Spree | ||
class ReturnItem::EligibilityValidator::NoReimbursements < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.return_items.reimbursed.valid.any? | ||
add_error(:inventory_unit_reimbursed, Spree.t('return_item_inventory_unit_reimbursed')) | ||
return false | ||
else | ||
return true | ||
end | ||
end | ||
class ReturnItem < Spree::Base | ||
module EligibilityValidator | ||
class NoReimbursements < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
|
||
def requires_manual_intervention? | ||
@errors.present? | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.return_items.reimbursed.valid.any? | ||
add_error(:inventory_unit_reimbursed, Spree.t('return_item_inventory_unit_reimbursed')) | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
else | ||
return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
end | ||
end | ||
|
||
def requires_manual_intervention? | ||
@errors.present? | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
module Spree | ||
class ReturnItem::EligibilityValidator::OrderCompleted < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.order.completed? | ||
return true | ||
else | ||
add_error(:order_not_completed, Spree.t('return_item_order_not_completed')) | ||
return false | ||
end | ||
end | ||
class ReturnItem < Spree::Base | ||
module EligibilityValidator | ||
class OrderCompleted < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.inventory_unit.order.completed? | ||
return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
else | ||
add_error(:order_not_completed, Spree.t('return_item_order_not_completed')) | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
end | ||
end | ||
|
||
def requires_manual_intervention? | ||
false | ||
def requires_manual_intervention? | ||
false | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
module Spree | ||
class ReturnItem::EligibilityValidator::RMARequired < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.return_authorization.present? | ||
return true | ||
else | ||
add_error(:rma_required, Spree.t('return_item_rma_ineligible')) | ||
return false | ||
end | ||
end | ||
class ReturnItem < Spree::Base | ||
module EligibilityValidator | ||
class RMARequired < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if @return_item.return_authorization.present? | ||
return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
else | ||
add_error(:rma_required, Spree.t('return_item_rma_ineligible')) | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
end | ||
end | ||
|
||
def requires_manual_intervention? | ||
false | ||
def requires_manual_intervention? | ||
false | ||
end | ||
end | ||
end | ||
end | ||
end |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,20 @@ | ||
module Spree | ||
class ReturnItem::EligibilityValidator::TimeSincePurchase < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if (@return_item.inventory_unit.order.completed_at + Spree::Config[:return_eligibility_number_of_days].days) > Time.current | ||
return true | ||
else | ||
add_error(:number_of_days, Spree.t('return_item_time_period_ineligible')) | ||
return false | ||
end | ||
end | ||
class ReturnItem < Spree::Base | ||
module EligibilityValidator | ||
class TimeSincePurchase < Spree::ReturnItem::EligibilityValidator::BaseValidator | ||
def eligible_for_return? | ||
if (@return_item.inventory_unit.order.completed_at + Spree::Config[:return_eligibility_number_of_days].days) > Time.current | ||
return true | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
else | ||
add_error(:number_of_days, Spree.t('return_item_time_period_ineligible')) | ||
return false | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Redundant return detected. |
||
end | ||
end | ||
|
||
def requires_manual_intervention? | ||
false | ||
def requires_manual_intervention? | ||
false | ||
end | ||
end | ||
end | ||
end | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant return detected.