Bootstrap documents for closing
This commit is contained in:
parent
32b3aa257c
commit
2fe38c3ff5
@ -10,6 +10,9 @@ class AccountingPeriod(Document):
|
||||
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 @@ class AccountingPeriod(Document):
|
||||
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
|
||||
})
|
||||
|
Loading…
x
Reference in New Issue
Block a user