From 2225decb2ba430896d95bc002d71aa98c2ef8a53 Mon Sep 17 00:00:00 2001 From: Valmik Jangla Date: Tue, 14 Jun 2016 17:41:28 +0530 Subject: [PATCH] Restrict Newsletter lists --- .../crm/doctype/newsletter_list/newsletter_list.py | 11 +++++++++++ erpnext/hooks.py | 4 ++++ 2 files changed, 15 insertions(+) diff --git a/erpnext/crm/doctype/newsletter_list/newsletter_list.py b/erpnext/crm/doctype/newsletter_list/newsletter_list.py index c3604f8326..68c445fe6d 100644 --- a/erpnext/crm/doctype/newsletter_list/newsletter_list.py +++ b/erpnext/crm/doctype/newsletter_list/newsletter_list.py @@ -89,3 +89,14 @@ def add_subscribers(name, email_list): frappe.msgprint(_("{0} subscribers added").format(count)) return frappe.get_doc("Newsletter List", name).update_total_subscribers() + +def restrict_newsletter_list(doc, method): + from frappe.limits import get_limits + + newsletter_list_limit = get_limits().get('newsletter_recipients') + if not newsletter_list_limit: + return + + nl = frappe.get_doc("Newsletter List", doc.newsletter_list) + if nl.get_total_subscribers() >= newsletter_list_limit: + frappe.throw(_("Please Upgrade to add more than {0} subscribers").format(newsletter_list_limit)) \ No newline at end of file diff --git a/erpnext/hooks.py b/erpnext/hooks.py index 2bb2ca6065..0c8de2a186 100644 --- a/erpnext/hooks.py +++ b/erpnext/hooks.py @@ -136,6 +136,10 @@ doc_events = { "validate": "erpnext.shopping_cart.cart.set_customer_in_address" }, + "Newsletter List Subscriber": { + "validate": "erpnext.crm.doctype.newsletter_list.newsletter_list.restrict_newsletter_list" + }, + # bubble transaction notification on master ('Opportunity', 'Quotation', 'Sales Order', 'Delivery Note', 'Sales Invoice', 'Supplier Quotation', 'Purchase Order', 'Purchase Receipt',