Skip to content
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

When a reimbursement is created, a store credit is not created only a store reimbursement credit. #2645

Closed
prdanelli opened this issue Mar 22, 2018 · 2 comments
Labels
type:bug Error, flaw or fault

Comments

@prdanelli
Copy link

prdanelli commented Mar 22, 2018

Steps to reproduce

Ship order
Create returns authorisation
Create customer return with reimbursement type of Spree::StoreCredit
Create reimbursement

Expected behavior

Spree::StoreCredit created

Actual behavior

Reimbursement credit is created with a creditable_type of Spree::StoreCredit but a creditable_id of nil.

System configuration

Solidus Version: 2.4.2

After falling down the rabbit hole debugging this I think I have worked out what is going on.

module Spree::ReimbursementType::ReimbursementHelpers
  #...
  def create_creditable(reimbursement, unpaid_amount)
    Spree::Reimbursement::Credit.default_creditable_class.new(
      user: reimbursement.order.user,
      amount: unpaid_amount,
      category: Spree::StoreCreditCategory.reimbursement_category(reimbursement),
      created_by: Spree::StoreCredit.default_created_by,
      memo: "Refund for uncreditable payments on order #{reimbursement.order.number}",
      currency: reimbursement.order.currency
    )
  end
end

The first issue is that the create_creditable method requires a created_by attribute to be set, and Spree::StoreCredit.default_created_by, which turns out to be...

class Spree::StoreCredit < Spree::PaymentSource
  #...
  DEFAULT_CREATED_BY_EMAIL = "[email protected]"
  #....
  class << self
    def default_created_by
      Spree.user_class.find_by(email: DEFAULT_CREATED_BY_EMAIL)
    end
  end
end

So unless you still have a user with [email protected] as an email address in your database the store credits will never save.

@kennyadsl
Copy link
Member

I confirm the bug on master sandbox. I'm trying to create a spec to reproduce the issue but still can't do that, it seems like our specs on that are correctly creating the creditable object.

@kennyadsl
Copy link
Member

This can be closed with #2802

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:bug Error, flaw or fault
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants