Skip to content

Commit

Permalink
fix: force fetch updates for subcription
Browse files Browse the repository at this point in the history
(cherry picked from commit 1ef890d)
  • Loading branch information
ruthra-kumar authored and mergify[bot] committed Aug 13, 2024
1 parent e9b3a24 commit 582fffc
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 0 deletions.
13 changes: 13 additions & 0 deletions erpnext/accounts/doctype/subscription/subscription.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@ frappe.ui.form.on("Subscription", {
__("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"),
Expand Down Expand Up @@ -82,4 +88,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();
}
});
},
});
19 changes: 19 additions & 0 deletions erpnext/accounts/doctype/subscription/subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,25 @@ def restart_subscription(self, posting_date: DateTimeLikeObject | None = None) -
self.update_subscription_period(posting_date or nowdate())
self.save()

@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 is_prorate() -> int:
return cint(frappe.db.get_single_value("Subscription Settings", "prorate"))
Expand Down

0 comments on commit 582fffc

Please sign in to comment.