mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-24 23:49:19 +00:00
refactor: process subscriptions in batch wise
(cherry picked from commit 283d69c0bd)
This commit is contained in:
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
from frappe.utils import getdate
|
from frappe.utils import create_batch, getdate
|
||||||
|
|
||||||
from erpnext.accounts.doctype.subscription.subscription import DateTimeLikeObject, process_all
|
from erpnext.accounts.doctype.subscription.subscription import DateTimeLikeObject, process_all
|
||||||
|
|
||||||
@@ -23,7 +23,23 @@ class ProcessSubscription(Document):
|
|||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
def on_submit(self):
|
def on_submit(self):
|
||||||
process_all(subscription=self.subscription, posting_date=self.posting_date)
|
self.process_all_subscription()
|
||||||
|
|
||||||
|
def process_all_subscription(self):
|
||||||
|
filters = {"status": ("!=", "Cancelled")}
|
||||||
|
|
||||||
|
if self.subscription:
|
||||||
|
filters["name"] = self.subscription
|
||||||
|
|
||||||
|
subscriptions = frappe.get_all("Subscription", filters, pluck="name")
|
||||||
|
|
||||||
|
for subscription in create_batch(subscriptions, 500):
|
||||||
|
frappe.enqueue(
|
||||||
|
method="erpnext.accounts.doctype.subscription.subscription.process_all",
|
||||||
|
queue="long",
|
||||||
|
subscription=subscription,
|
||||||
|
posting_date=self.posting_date,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def create_subscription_process(
|
def create_subscription_process(
|
||||||
|
|||||||
@@ -756,18 +756,14 @@ def get_prorata_factor(
|
|||||||
return diff / plan_days
|
return diff / plan_days
|
||||||
|
|
||||||
|
|
||||||
def process_all(subscription: str | None = None, posting_date: DateTimeLikeObject | None = None) -> None:
|
def process_all(subscription: list, posting_date: DateTimeLikeObject | None = None) -> None:
|
||||||
"""
|
"""
|
||||||
Task to updates the status of all `Subscription` apart from those that are cancelled
|
Task to updates the status of all `Subscription` apart from those that are cancelled
|
||||||
"""
|
"""
|
||||||
filters = {"status": ("!=", "Cancelled")}
|
|
||||||
|
|
||||||
if subscription:
|
for subscription_name in subscription:
|
||||||
filters["name"] = subscription
|
|
||||||
|
|
||||||
for subscription in frappe.get_all("Subscription", filters, pluck="name"):
|
|
||||||
try:
|
try:
|
||||||
subscription = frappe.get_doc("Subscription", subscription)
|
subscription = frappe.get_doc("Subscription", subscription_name)
|
||||||
subscription.process(posting_date)
|
subscription.process(posting_date)
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
except frappe.ValidationError:
|
except frappe.ValidationError:
|
||||||
|
|||||||
Reference in New Issue
Block a user