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
Merged

New subscription Management #13146

merged 78 commits into from Apr 30, 2018

Conversation

@tundebabzy
Copy link
Contributor

@tundebabzy tundebabzy 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 30 commits Feb 24, 2018
- Encapsulates a subscriber to a service or product
- Contains subscription specific information
- 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
- encapsulates subscription
- linked to a subscriber
- subscription can contain many plans
- contains history of generated invoices
- set current_invoice_start
- set current_invoice_end
- ensure trial period dates are in order
- if subscription is not in trial period, generate sales invoice
@tundebabzy
Copy link
Contributor Author

@tundebabzy tundebabzy 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'){
Copy link
Member

@nabinhait nabinhait Mar 28, 2018

Check spelling "Cancelled"

Copy link
Contributor Author

@tundebabzy tundebabzy Apr 17, 2018

@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)?

Copy link
Member

@nabinhait nabinhait Apr 17, 2018

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')
Copy link
Member

@nabinhait nabinhait Mar 28, 2018

auto_repeat

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

@nabinhait nabinhait Mar 28, 2018

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',
Copy link
Member

@nabinhait nabinhait Mar 28, 2018

Is it done by mistake?

Copy link
Contributor Author

@tundebabzy tundebabzy Apr 17, 2018

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)
Copy link
Member

@nabinhait nabinhait Mar 28, 2018

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

Copy link
Contributor Author

@tundebabzy tundebabzy Apr 17, 2018

True

@tundebabzy
Copy link
Contributor Author

@tundebabzy tundebabzy commented Apr 17, 2018

@nabinhait changes made

@tundebabzy
Copy link
Contributor Author

@tundebabzy tundebabzy commented Apr 22, 2018

spelling corrected

@nabinhait nabinhait merged commit dbdf462 into frappe:develop Apr 30, 2018
2 of 3 checks passed
@agritheory
Copy link
Contributor

@agritheory agritheory commented Apr 30, 2018

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

@chdecultot
Copy link
Collaborator

@chdecultot chdecultot 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
Copy link
Contributor Author

@tundebabzy tundebabzy 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
Copy link
Contributor Author

@tundebabzy tundebabzy 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
Copy link
Contributor

@agritheory agritheory 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
Copy link

@cudokmark cudokmark 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
Copy link

@henwoodluke henwoodluke 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
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

10 participants