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

New subscription Management #13146

Merged
merged 78 commits into from Apr 30, 2018

Conversation

Projects
None yet
10 participants
@tundebabzy
Copy link
Collaborator

commented Mar 2, 2018

This PR aims to add a full featured Doctype for managing subscriptions. Once a Subscription has been saved, it doesn't require user interaction as ERPNext will automatically update the Subscription as changes occur.

subscription-1

How It Works

Create a Subscriber

subscriber

Create a Subscription Plan

subscription-plan

Create the subscription
  • Add the Subscriber
  • Add required dates and quantity as needed
  • Add Subscription Plan(s)
  • Add Sales Taxes and Charges Template if required
  • Add Discount information if required
  • Save
After that...

ERPNext will constantly check each saved Subscription to change their status and generate new invoices as needed.

Subscription Status

There are five:

  • Trialling: Subscription in trial period
  • Active: Subscription that has no uncleared invoice
  • Past Due Date: Subscription that has an overdue invoice
  • Unpaid: Subscription that has an invoice overdue beyond the grace period
  • Canceled: Subscription that has an invoice overdue beyond the grace period and is canceled

Manually Updating A Subscription

Simply open the required Subscription and make changes. Note that changes will only reflect in subsequent invoices. Past invoices will remain the same.

If the Subscription seems not to be in sync with reality, simply click the 'Fetch Subscription Updates' button so ERPNext can immediately update it.

Subscription Cancellation

If you need to immediately cancel a Subscription, open the Subscription and click the 'Cancel Subscription' button. If the subscription is active at the time of cancellation, ERPNext will generate a final invoice that will be prorated by default. If you want the invoice to be for the full amount, you can adjust this in Subscription Settings

Restarting Subscriptions

You can restart a canceled Subscription. Open the Subscription you want to restart and click the 'Restart Subscription' button. Note that restarting a Subscription will cause you to lose the history of invoices generated by the Subscription. This doesn't mean that the actual invoices will be lost, the Subscription will only 'forget' the invoices it has generated before the Subscription got restarted.

This closes #12797

tundebabzy added some commits Feb 24, 2018

New doctype - Subscriber:
- Encapsulates a subscriber to a service or product
- Contains subscription specific information
New doctype - Subscription Plan:
- Plan is to be linked to a Product
- Plan will be used to create Invoice items
- Subscriber can have multiple plans
- Contains billing cycle information
adds new doctype - Subscriptions
- encapsulates subscription
- linked to a subscriber
- subscription can contain many plans
- contains history of generated invoices
adds `before_insert` methods:
- set current_invoice_start
- set current_invoice_end
adds validation:
- ensure trial period dates are in order
set `after_insert` methods:
- if subscription is not in trial period, generate sales invoice
@tundebabzy

This comment has been minimized.

Copy link
Collaborator Author

commented Mar 12, 2018

Depends on frappe/frappe#5183 which moves the present Subscription into frappe as Auto Repeat

}
);
if(!frm.is_new()){
if(frm.doc.status !== 'Canceled'){

This comment has been minimized.

Copy link
@nabinhait

nabinhait Mar 28, 2018

Member

Check spelling "Cancelled"

This comment has been minimized.

Copy link
@tundebabzy

tundebabzy Apr 17, 2018

Author Collaborator

@nabinhait I actually mistakenly used the American spelling (VS Code spell checker caused it)... and it's not just here. Should I leave it as 'canceled' since it's technically a correct spelling (American)?

This comment has been minimized.

Copy link
@nabinhait

nabinhait Apr 17, 2018

Member

It will be good changing it to "Cancelled" because we have used that spelling everywhere.

frappe.reload_doc('accounts', 'doctype', 'journal_entry')
frappe.reload_doc('buying', 'doctype', 'purchase_order')
frappe.reload_doc('buying', 'doctype', 'supplier_quotation')
frappe.reload_doc('desk', 'doctype', 'Auto Repeat')

This comment has been minimized.

Copy link
@nabinhait

nabinhait Mar 28, 2018

Member

auto_repeat

for doc in subscriptions:
doc['doctype'] = 'Auto Repeat'
auto_repeat = frappe.get_doc(doc)
auto_repeat.insert()

This comment has been minimized.

Copy link
@nabinhait

nabinhait Mar 28, 2018

Member

We can use db_insert here, to make it faster

@@ -39,8 +39,8 @@ def add_custom_fields():

custom_fields = {
'Address': [
dict(fieldname='gst_state_number', label='GST State Number',
fieldtype='Int', insert_after='gst_state'),
dict(fieldname='auto_repeat', label='Auto Repeat',

This comment has been minimized.

Copy link
@nabinhait

nabinhait Mar 28, 2018

Member

Is it done by mistake?

This comment has been minimized.

Copy link
@tundebabzy

tundebabzy Apr 17, 2018

Author Collaborator

Definitely a mistake. I have no idea why I did this. Reverting



def execute():
subscriptions = frappe.db.sql('SELECT name from `tabSubscription`', as_dict=True)

This comment has been minimized.

Copy link
@nabinhait

nabinhait Mar 28, 2018

Member

May be we can delete directly using frappe.db.sql('delete from `tabSubscription`')

This comment has been minimized.

Copy link
@tundebabzy

tundebabzy Apr 17, 2018

Author Collaborator

True

@nabinhait nabinhait self-assigned this Mar 28, 2018

@tundebabzy

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 17, 2018

@nabinhait changes made

tundebabzy added some commits Apr 22, 2018

@tundebabzy

This comment has been minimized.

Copy link
Collaborator Author

commented Apr 22, 2018

spelling corrected

@nabinhait nabinhait merged commit dbdf462 into frappe:develop Apr 30, 2018

2 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build could not complete due to an error
Details
Codacy/PR Quality Review Up to standards. A positive pull request.
Details
security/snyk No dependency changes
Details
@agritheory

This comment has been minimized.

Copy link
Contributor

commented Apr 30, 2018

This is great. Are you still open to working in holiday and date management?

@chdecultot

This comment has been minimized.

Copy link
Contributor

commented May 22, 2018

Hi @tundebabzy, thanks for your great work with this refactored module!

Just one question, why did you add a cost field in the plan doctype instead of just proposing to select a pricing list ?

I have the feeling that it adds an extra configuration step, whereas the price could be directly handled through the price list with potential pricing rules... It's just a thought and I'm interested to know if that has been done on purpose ? 😃

@tundebabzy

This comment has been minimized.

Copy link
Collaborator Author

commented May 23, 2018

Hi @chdecultot

Just one question, why did you add a cost field in the plan doctype instead of just proposing to select a pricing list ?

Actually it was done on purpose because my mental model of the price is price of the plan, not price of the item(s) in the plan.

@tundebabzy

This comment has been minimized.

Copy link
Collaborator Author

commented May 23, 2018

@agritheory

This is great. Are you still open to working in holiday and date management?

Sorry for taking so long to reply. You mean improvement in holiday and date management?

@agritheory

This comment has been minimized.

Copy link
Contributor

commented Jun 5, 2018

@tundebabzy My thought on this was to have the subscription dates be pushed around weekends and holidays using the company's holiday schedule or a designated alternative. I had a PR pulled in that added these manually, but I think the holiday list is the best place to manage this.

@cudokmark

This comment has been minimized.

Copy link

commented Aug 21, 2018

Hi all,

In what version is this available. We run ERPNext: v10.1.48 (master) and Frappe Framework: v10.1.45 (master). Thank you.

@henwoodluke

This comment has been minimized.

Copy link

commented Sep 26, 2018

When will this be available?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.