Bootstrap documents for closing
diff --git a/erpnext/accounts/doctype/accounting_period/accounting_period.py b/erpnext/accounts/doctype/accounting_period/accounting_period.py
index 8760d8f..f2ba578 100644
--- a/erpnext/accounts/doctype/accounting_period/accounting_period.py
+++ b/erpnext/accounts/doctype/accounting_period/accounting_period.py
@@ -10,6 +10,9 @@
def validate(self):
self.validate_overlap()
+ def before_insert(self):
+ self.bootstrap_doctypes_for_closing()
+
def autoname(self):
company_abbr = frappe.db.get_value("Company", self.company, "abbr")
self.name = " - ".join([self.period_name, company_abbr])
@@ -32,3 +35,20 @@
if len(existing_accounting_period) > 0:
frappe.throw("Accounting Period overlaps with {0}".format(existing_accounting_period[0].get("name")))
+ def get_doctypes_for_closing(self):
+ docs_for_closing = []
+ #if not self.closed_documents or len(self.closed_documents) == 0:
+ doctypes = ["Sales Invoice", "Purchase Invoice", "Journal Entry", "Payroll Entry", "Bank Reconciliation", "Asset", "Purchase Order", "Sales Order", "Leave Application", "Leave Allocation", "Stock Entry"]
+ closed_doctypes = [{"document_type": doctype, "closed": 1} for doctype in doctypes]
+ for closed_doctype in closed_doctypes:
+ docs_for_closing.append(closed_doctype)
+
+ return docs_for_closing
+
+ def bootstrap_doctypes_for_closing(self):
+ if self.closed_documents.length == 0:
+ for doctype_for_closing in self.get_doctypes_for_closing():
+ self.append('closed_documents', {
+ "document_type": doctype_for_closing.document_type,
+ "closed": doctype_for_closing.closed
+ })