Previous user count is incorrect when changing products and seat count during renewal
Problem
When a subscription is renewed, and the user changes the product and the number of active users at the same time, the previous_user_count
is the same as the new user_count
.
This is because Subscription#previous
finds the last version of the subscription and we use the result of this to get the previous_user_count
. This is an issue when changing products and seats, because we generate an amendment of the subscription with the new product and the new seat count before processing the renewal amendment. This means the previous version at that point is the version with the new product and the new user count.
Example
^ In this example, we renew the initial subscription (V1) and change the product from premium to ultimate. We also change the user count (which was 10 in V1 and is then 15 in V3). When we process the renewal, we look for the most recent previous version and this is returning V3 currently. This means we're creating the license with user_count: 15, previous_user_count: 15
but it should be user_count: 15, previous_user_count: 10
🐛 Steps to reproduce
- Create a new self-managed license via CustomersDot
- Navigate to the renewal page for that license
- Renew the license with:
- Changed product (ie Premium -> Ultimate)
- Changed number of users
- View the license in the db:
previous_users_count == user_count
📸 Screenshots
Proposal
I'm not entirely sure how to address this, it will likely require some investigation. We need to get the version of the subscription before we made the renewal amendments, or we need to store the previous_user_count
somewhere else and look it up from there.