Skip to content

Commit

Permalink
feat: subscription refactor (#30963)
Browse files Browse the repository at this point in the history
* feat: subscription refactor

* fix: linter changes

* chore: linter changes

* chore: linter changes

* chore: Update tests

* chore: Remove commits

---------

Co-authored-by: Deepesh Garg <deepeshgarg6@gmail.com>
  • Loading branch information
hrwX and deepeshgarg007 authored Aug 7, 2023
1 parent b717e2b commit 3880560
Show file tree
Hide file tree
Showing 8 changed files with 438 additions and 466 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@
"column_break_63",
"unrealized_profit_loss_account",
"subscription_section",
"subscription",
"auto_repeat",
"update_auto_repeat_reference",
"column_break_114",
Expand Down Expand Up @@ -1423,6 +1424,12 @@
"options": "Advance Tax",
"read_only": 1
},
{
"fieldname": "subscription",
"fieldtype": "Link",
"label": "Subscription",
"options": "Subscription"
},
{
"default": "0",
"fieldname": "is_old_subcontracting_flow",
Expand Down Expand Up @@ -1577,7 +1584,7 @@
"idx": 204,
"is_submittable": 1,
"links": [],
"modified": "2023-07-04 17:22:59.145031",
"modified": "2023-07-25 17:22:59.145031",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Purchase Invoice",
Expand Down
9 changes: 8 additions & 1 deletion erpnext/accounts/doctype/sales_invoice/sales_invoice.json
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,7 @@
"select_print_heading",
"language",
"subscription_section",
"subscription",
"from_date",
"auto_repeat",
"column_break_140",
Expand Down Expand Up @@ -2017,6 +2018,12 @@
"label": "Amount Eligible for Commission",
"read_only": 1
},
{
"fieldname": "subscription",
"fieldtype": "Link",
"label": "Subscription",
"options": "Subscription"
},
{
"default": "0",
"depends_on": "eval: doc.apply_discount_on == \"Grand Total\"",
Expand Down Expand Up @@ -2157,7 +2164,7 @@
"link_fieldname": "consolidated_invoice"
}
],
"modified": "2023-06-21 16:02:18.988799",
"modified": "2023-07-25 16:02:18.988799",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Sales Invoice",
Expand Down
96 changes: 40 additions & 56 deletions erpnext/accounts/doctype/subscription/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@
// For license information, please see license.txt

frappe.ui.form.on('Subscription', {
setup: function(frm) {
frm.set_query('party_type', function() {
setup: function (frm) {
frm.set_query('party_type', function () {
return {
filters : {
filters: {
name: ['in', ['Customer', 'Supplier']]
}
}
});

frm.set_query('cost_center', function() {
frm.set_query('cost_center', function () {
return {
filters: {
company: frm.doc.company
Expand All @@ -20,76 +20,60 @@ frappe.ui.form.on('Subscription', {
});
},

refresh: function(frm) {
if(!frm.is_new()){
if(frm.doc.status !== 'Cancelled'){
frm.add_custom_button(
__('Cancel Subscription'),
() => frm.events.cancel_this_subscription(frm)
);
frm.add_custom_button(
__('Fetch Subscription Updates'),
() => frm.events.get_subscription_updates(frm)
);
}
else if(frm.doc.status === 'Cancelled'){
frm.add_custom_button(
__('Restart Subscription'),
() => frm.events.renew_this_subscription(frm)
);
}
refresh: function (frm) {
if (frm.is_new()) return;

if (frm.doc.status !== 'Cancelled') {
frm.add_custom_button(
__('Fetch Subscription Updates'),
() => frm.trigger('get_subscription_updates'),
__('Actions')
);

frm.add_custom_button(
__('Cancel Subscription'),
() => frm.trigger('cancel_this_subscription'),
__('Actions')
);
} else if (frm.doc.status === 'Cancelled') {
frm.add_custom_button(
__('Restart Subscription'),
() => frm.trigger('renew_this_subscription'),
__('Actions')
);
}
},

cancel_this_subscription: function(frm) {
const doc = frm.doc;
cancel_this_subscription: function (frm) {
frappe.confirm(
__('This action will stop future billing. Are you sure you want to cancel this subscription?'),
function() {
frappe.call({
method:
"erpnext.accounts.doctype.subscription.subscription.cancel_subscription",
args: {name: doc.name},
callback: function(data){
if(!data.exc){
frm.reload_doc();
}
() => {
frm.call('cancel_subscription').then(r => {
if (!r.exec) {
frm.reload_doc();
}
});
}
);
},

renew_this_subscription: function(frm) {
const doc = frm.doc;
renew_this_subscription: function (frm) {
frappe.confirm(
__('You will lose records of previously generated invoices. Are you sure you want to restart this subscription?'),
function() {
frappe.call({
method:
"erpnext.accounts.doctype.subscription.subscription.restart_subscription",
args: {name: doc.name},
callback: function(data){
if(!data.exc){
frm.reload_doc();
}
__('Are you sure you want to restart this subscription?'),
() => {
frm.call('restart_subscription').then(r => {
if (!r.exec) {
frm.reload_doc();
}
});
}
);
},

get_subscription_updates: function(frm) {
const doc = frm.doc;
frappe.call({
method:
"erpnext.accounts.doctype.subscription.subscription.get_subscription_updates",
args: {name: doc.name},
freeze: true,
callback: function(data){
if(!data.exc){
frm.reload_doc();
}
get_subscription_updates: function (frm) {
frm.call('process').then(r => {
if (!r.exec) {
frm.reload_doc();
}
});
}
Expand Down
43 changes: 18 additions & 25 deletions erpnext/accounts/doctype/subscription/subscription.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"trial_period_end",
"follow_calendar_months",
"generate_new_invoices_past_due_date",
"submit_invoice",
"column_break_11",
"current_invoice_start",
"current_invoice_end",
Expand All @@ -35,12 +36,8 @@
"cb_2",
"additional_discount_percentage",
"additional_discount_amount",
"sb_3",
"submit_invoice",
"invoices",
"accounting_dimensions_section",
"cost_center",
"dimension_col_break"
"cost_center"
],
"fields": [
{
Expand Down Expand Up @@ -162,29 +159,12 @@
"fieldtype": "Currency",
"label": "Additional DIscount Amount"
},
{
"depends_on": "eval:doc.invoices",
"fieldname": "sb_3",
"fieldtype": "Section Break",
"label": "Invoices"
},
{
"collapsible": 1,
"fieldname": "invoices",
"fieldtype": "Table",
"label": "Invoices",
"options": "Subscription Invoice"
},
{
"collapsible": 1,
"fieldname": "accounting_dimensions_section",
"fieldtype": "Section Break",
"label": "Accounting Dimensions"
},
{
"fieldname": "dimension_col_break",
"fieldtype": "Column Break"
},
{
"fieldname": "party_type",
"fieldtype": "Link",
Expand Down Expand Up @@ -259,15 +239,27 @@
"default": "1",
"fieldname": "submit_invoice",
"fieldtype": "Check",
"label": "Submit Invoice Automatically"
"label": "Submit Generated Invoices"
}
],
"index_web_pages_for_search": 1,
"links": [],
"modified": "2021-04-19 15:24:27.550797",
"links": [
{
"group": "Buying",
"link_doctype": "Purchase Invoice",
"link_fieldname": "subscription"
},
{
"group": "Selling",
"link_doctype": "Sales Invoice",
"link_fieldname": "subscription"
}
],
"modified": "2022-02-18 23:24:57.185054",
"modified_by": "Administrator",
"module": "Accounts",
"name": "Subscription",
"naming_rule": "Expression (old style)",
"owner": "Administrator",
"permissions": [
{
Expand Down Expand Up @@ -309,5 +301,6 @@
],
"sort_field": "modified",
"sort_order": "DESC",
"states": [],
"track_changes": 1
}
Loading

0 comments on commit 3880560

Please sign in to comment.