From 935f4a474bf9f32836865debf32c43b006529d56 Mon Sep 17 00:00:00 2001 From: Ameya Shenoy Date: Tue, 3 Jul 2018 10:48:59 +0530 Subject: [PATCH] Prevent creation of more than 500 item variants (#14790) --- erpnext/controllers/item_variant.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/erpnext/controllers/item_variant.py b/erpnext/controllers/item_variant.py index bf8c88cfb02..5e7ddbbd542 100644 --- a/erpnext/controllers/item_variant.py +++ b/erpnext/controllers/item_variant.py @@ -176,6 +176,14 @@ def create_variant(item, args): @frappe.whitelist() def enqueue_multiple_variant_creation(item, args): # There can be innumerable attribute combinations, enqueue + if isinstance(args, basestring): + variants = json.loads(args) + total_variants = 1 + for key in variants: + total_variants *= len(variants[key]) + if total_variants >= 600: + frappe.msgprint("Please do not create more than 500 items at a time", raise_exception=1) + return frappe.enqueue("erpnext.controllers.item_variant.create_multiple_variants", item=item, args=args, now=frappe.flags.in_test);