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

Module::DelegationError (Spree::Order#invoice_number delegated to invoice.number, but invoice is nil #155

Open
ewenjc opened this issue Dec 7, 2020 · 0 comments

Comments

@ewenjc
Copy link

ewenjc commented Dec 7, 2020

Hi
I'm getting the following error each time I attempt to add an item to the cart; "Module::DelegationError (Spree::Order#invoice_number delegated to invoice.number, but invoice is nil", while running `ensure_cart'.

I have a clean install of spree 4.1. However I've imported order data from a spree 2.4 implementation, so possibly that is causing the issue. Within order I still have the invoice_number and invoice_date.

EDIT:
Error message solved
The error was caused by still having the invoice_number field on orders. I renamed the columns invoice_number and invoice date and the error went away.

Data migration still a problem
I tried to migrate the invoice numbers from the old 2.4 setup into the new spree 4.1 setup. I added the following migration;

`class RenameInvoiceNumberOnOrder < ActiveRecord::Migration[6.0]
def change
up_only {
Spree::Order.complete.where.not(invoice_number: nil).find_each do |order|
order.bookkeeping_documents.delete_all
order.invoice_for_order
order.invoice.update(number: order.invoice_number, created_at: order.completed_at.to_date)
order.packaging_slip.update(number: order.invoice_number, created_at: order.completed_at.to_date)
end
}
rename_column :spree_orders, :invoice_number, :old_invoice_number
rename_column :spree_orders, :invoice_date, :old_invoice_date
end

end
`

It recreated the invoices but the invoice numbers didn't set as the old numbers. The order numbers didn't set to the old number but a number a few thousand higher. Possibly it is taking the next invoice number and adding the old number to it?
Also attempting to set the number on the packaging_slip to the old invoice number had no effect and it kept the packaging slip number as the order number.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant