# Path: jasper_erpnext_report/utils/file.py
# def remove_directory(path, ignore_errors=True):
# 	import shutil
# 	shutil.rmtree(path, ignore_errors)


import frappe
import os
from frappe import _
from frappe.model.document import Document
from jasper_erpnext_report.utils.file import remove_directory
# Copyright (c) 2013, Luis Fernandes and contributors
# For license information, please see license.txt

from __future__ import unicode_literals

class JasperEmailReport(Document):

	def validate(self):
		if not self.jasper_email_report_name:
			raise frappe.PermissionError(_("You are not allowed to add this document."))

	def on_trash(self):
		if frappe.local.session['user'] == "Administrator":
			file_path = self.jasper_report_path
			if os.path.exists(file_path):
				root_path = file_path.rsplit("/",1)

# Path: jasper_erpnext_report/utils/file.py
# def remove_directory(path, ignore_errors=True):
# 	import shutil
# 	shutil.rmtree(path, ignore_errors)


# Path: jasper_erpnext_report/jasper_erpnext_report/doctype/jasper_email_report/jasper_email_report.py
import frappe
import os
from frappe import _
from frappe.model.document import Document
from jasper_erpnext_report.utils.file import remove_directory

# Copyright (c) 2013, Luis Fernandes and contributors
# For license information, please see license.txt

from __future__ import unicode_literals

class JasperEmailReport(Document):

	def validate(self):
		if not self.jasper_email_report_name:
			raise frappe.PermissionError(_("You are not allowed to add this document."))

	def on_trash(self):
		if frappe.local.session['user'] == "Administrator":
			file_path = self.jasper_report_path
			if os.path.exists(file_path):
				root_path = file_path.rsplit("/",1)

				remove_directory(root_path[0])