fix: force fetch updates for subcription

(cherry picked from commit 1ef890db73)

# Conflicts:
#	erpnext/accounts/doctype/subscription/subscription.js
This commit is contained in:
ruthra kumar
2024-08-12 17:37:48 +05:30
committed by Mergify
parent a5b5b5e62c
commit f35bc43242
2 changed files with 55 additions and 0 deletions

View File

@@ -29,6 +29,7 @@ frappe.ui.form.on("Subscription", {
},
refresh: function (frm) {
<<<<<<< HEAD
if (!frm.is_new()) {
if (frm.doc.status !== "Cancelled") {
frm.add_custom_button(__("Cancel Subscription"), () =>
@@ -42,6 +43,34 @@ frappe.ui.form.on("Subscription", {
frm.events.renew_this_subscription(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(
__("Force Fetch Subscription Updates"),
() => frm.trigger("force_fetch_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")
);
>>>>>>> 1ef890db73 (fix: force fetch updates for subcription)
}
},
@@ -96,4 +125,11 @@ frappe.ui.form.on("Subscription", {
},
});
},
force_fetch_subscription_updates: function (frm) {
frm.call("force_fetch_subscription_updates").then((r) => {
if (!r.exec) {
frm.reload_doc();
}
});
},
});

View File

@@ -674,6 +674,25 @@ class Subscription(Document):
if invoice:
return invoice.precision("grand_total")
@frappe.whitelist()
def force_fetch_subscription_updates(self):
"""
Process Subscription and create Invoices even if current date doesn't lie between current_invoice_start and currenct_invoice_end
It makes use of 'Proces Subscription' to force processing in a specific 'posting_date'
"""
processing_date = None
if self.generate_invoice_at == "Beginning of the current subscription period":
processing_date = self.current_invoice_start
elif self.generate_invoice_at == "End of the current subscription period":
processing_date = self.current_invoice_end
elif self.generate_invoice_at == "Days before the current subscription period":
processing_date = add_days(self.current_invoice_start, -self.number_of_days)
process_subscription = frappe.new_doc("Process Subscription")
process_subscription.posting_date = processing_date
process_subscription.subscription = self.name
process_subscription.save().submit()
def get_calendar_months(billing_interval):
calendar_months = []