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

replace AbstractRecurringUserPlan.has_automatic_renewal with AbstractRecurringUserPlan.renewal_triggered_by #188

Merged

Conversation

radekholy24
Copy link
Contributor

@radekholy24 radekholy24 commented Mar 31, 2024

has_automatic_renewal can indicate whether the renewal is initiated by this app or by the user. However, there is no way to indicate that the renewal is initiated by another (3rd party) mechanism such as by the payment provider's server (PayPal). This new field provides such functionality while preserving has_automatic_renewal property for backward compatibility.

@@ -533,11 +585,28 @@ class AbstractRecurringUserPlan(BaseMixin, models.Model):
_("tax"), max_digits=4, decimal_places=2, db_index=True, null=True, blank=True
) # Tax=None is when tax is not applicable
currency = models.CharField(_("currency"), max_length=3)
renewal_trigger = models.IntegerField(
_("renewal trigger"),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe renewal triggered by or renewal triggered from?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with renewal triggered by

"TASK = autorenew_account-task-initiated renewal, OTHER = renewal is triggered using another mechanism, "
"None = use has_automatic_renewal value (deprecated)). Overrides has_automatic_renewal, if not None."
),
# TODO: Nullable deprecated. Set to False in the next major release.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this. In order to be backwards compatible we would have to populate the value at some point anyway. Will we make data migration in the next major release?

Or wouldn't it be better to populate the value now and add a mechanism that will guess it's value for legacy usages?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure about this. In order to be backwards compatible we would have to populate the value at some point anyway. Will we make data migration in the next major release?

Hm, I think that if it is a major release, we may ask users to populate the value on their own.

Or wouldn't it be better to populate the value now and add a mechanism that will guess it's value for legacy usages?

I am fine with that but is it possible to make a data migration for all subclasses of AbstractRecurringUserPlan? Can you point me to such mechanism please?

Copy link
Contributor Author

@radekholy24 radekholy24 Apr 5, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hm... But... If we made the data migration, what would we do with users that won't migrate to renewal_trigger renewal_triggered_by but keep changing only has_automatic_renewal? At some point in the past, I had a __getattribute__ mechanism that synchronized these two values. Would that work for you? (That ofc assumes that users do not manipulate the data in the DB directly.)

Copy link
Contributor Author

@radekholy24 radekholy24 Apr 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@PetrDlouhy, I made the changes discussed in person.
edit: OMG, I forgot to write the data migration 🤦 mmnt...
edit: Migration added

plans/tasks.py Outdated
userplan__expire__lt=datetime.date.today()
+ datetime.timedelta(
days=PLANS_AUTORENEW_BEFORE_DAYS, hours=PLANS_AUTORENEW_BEFORE_HOURS
(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two subsequent filter() calls instead of & might make this a bit clearer.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replaced with double-filter

@codecov-commenter
Copy link

Codecov Report

Attention: Patch coverage is 93.75000% with 2 lines in your changes are missing coverage. Please review.

Project coverage is 86.81%. Comparing base (4742b76) to head (e01a4ca).

Files Patch % Lines
plans/admin.py 83.33% 1 Missing ⚠️
plans/base/models.py 95.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #188      +/-   ##
==========================================
+ Coverage   86.73%   86.81%   +0.07%     
==========================================
  Files          64       65       +1     
  Lines        2375     2404      +29     
==========================================
+ Hits         2060     2087      +27     
- Misses        315      317       +2     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@radekholy24 radekholy24 changed the title add AbstractRecurringUserPlan.renewal_trigger add AbstractRecurringUserPlan.renewal_triggered_by Apr 5, 2024
@radekholy24 radekholy24 changed the title add AbstractRecurringUserPlan.renewal_triggered_by replace AbstractRecurringUserPlan.has_automatic_renewal with AbstractRecurringUserPlan.renewal_triggered_by Apr 9, 2024
@radekholy24 radekholy24 force-pushed the automatic_renewal_trigger branch 2 times, most recently from c0dbb98 to f1d1ee3 Compare April 10, 2024 13:44
@PetrDlouhy PetrDlouhy merged commit 0c0f178 into django-getpaid:master Apr 12, 2024
25 checks passed
@PetrDlouhy
Copy link
Collaborator

@radekholy24 Thank you very much.

@radekholy24 radekholy24 deleted the automatic_renewal_trigger branch April 12, 2024 16:03
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

Successfully merging this pull request may close these issues.

3 participants