Skip to content

Commit

Permalink
Merge pull request #4068 from willianveiga/feature/fix-validation-for…
Browse files Browse the repository at this point in the history
…-nil-inventory-unit

Fix customer return validation for return items without inventory units
  • Loading branch information
kennyadsl authored May 21, 2021
2 parents a39affe + 0e6da3f commit 58f2e0b
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
5 changes: 3 additions & 2 deletions core/app/models/spree/customer_return.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ def amount
# Temporarily tie a customer_return to one order
def order
return nil if return_items.blank?
return_items.first.inventory_unit.order

return_items.first.inventory_unit&.order
end

def fully_reimbursed?
Expand All @@ -65,7 +66,7 @@ def generate_number
end

def return_items_belong_to_same_order
if return_items.reject{ |return_item| return_item.inventory_unit.order_id == order_id }.any?
if return_items.reject{ |return_item| return_item.inventory_unit&.order_id == order_id }.any?
errors.add(:base, I18n.t('spree.return_items_cannot_be_associated_with_multiple_orders'))
end
end
Expand Down
12 changes: 12 additions & 0 deletions core/spec/models/spree/customer_return_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,18 @@
expect(subject).to eq true
end
end

context "inventory is not present" do
before do
customer_return.return_items.clear

customer_return.return_items << Spree::ReturnItem.new
end

it "is invalid" do
expect(subject).to eq false
end
end
end
end

Expand Down

0 comments on commit 58f2e0b

Please sign in to comment.