Merge pull request #2303 from neilLasrado/fiscal-year-auto-create
Fiscal year auto create
This commit is contained in:
commit
90fb64f7e8
@ -4,7 +4,8 @@
|
||||
from __future__ import unicode_literals
|
||||
import frappe
|
||||
from frappe import msgprint, _
|
||||
from frappe.utils import getdate
|
||||
from frappe.utils import getdate, add_days, add_years
|
||||
from datetime import timedelta
|
||||
|
||||
from frappe.model.document import Document
|
||||
|
||||
@ -34,11 +35,32 @@ class FiscalYear(Document):
|
||||
|
||||
if (getdate(self.year_end_date) - getdate(self.year_start_date)).days > 366:
|
||||
frappe.throw(_("Fiscal Year Start Date and Fiscal Year End Date cannot be more than a year apart."))
|
||||
|
||||
check_duplicate_fiscal_year(self)
|
||||
|
||||
year_start_end_dates = frappe.db.sql("""select name, year_start_date, year_end_date
|
||||
from `tabFiscal Year` where name!=%s""", (self.name))
|
||||
|
||||
for fiscal_year, ysd, yed in year_start_end_dates:
|
||||
if (getdate(self.year_start_date) == ysd and getdate(self.year_end_date) == yed) \
|
||||
and (not frappe.flags.in_test):
|
||||
@frappe.whitelist()
|
||||
def check_duplicate_fiscal_year(doc):
|
||||
year_start_end_dates = frappe.db.sql("""select name, year_start_date, year_end_date from `tabFiscal Year` where name!=%s""", (doc.name))
|
||||
for fiscal_year, ysd, yed in year_start_end_dates:
|
||||
if (getdate(doc.year_start_date) == ysd and getdate(doc.year_end_date) == yed) and (not frappe.flags.in_test):
|
||||
frappe.throw(_("Fiscal Year Start Date and Fiscal Year End Date are already set in Fiscal Year {0}").format(fiscal_year))
|
||||
|
||||
|
||||
@frappe.whitelist()
|
||||
def auto_create_fiscal_year():
|
||||
for d in frappe.db.sql("""select name from `tabFiscal Year` where year_end_date =(current_date + 3)"""):
|
||||
try:
|
||||
current_fy = frappe.get_doc("Fiscal Year", d[0])
|
||||
|
||||
new_fy = frappe.copy_doc(current_fy)
|
||||
|
||||
new_fy.year_start_date = add_days(current_fy.year_end_date, 1)
|
||||
new_fy.year_end_date = add_years(current_fy.year_end_date, 1)
|
||||
|
||||
start_year = new_fy.year_start_date[:4]
|
||||
end_year = new_fy.year_end_date[:4]
|
||||
new_fy.year = start_year if start_year==end_year else (start_year + "-" + end_year)
|
||||
|
||||
new_fy.insert()
|
||||
except:
|
||||
pass
|
@ -45,6 +45,7 @@ scheduler_events = {
|
||||
"erpnext.stock.utils.reorder_item",
|
||||
"erpnext.setup.doctype.email_digest.email_digest.send",
|
||||
"erpnext.support.doctype.support_ticket.support_ticket.auto_close_tickets"
|
||||
"erpnext.accounts.doctype.fiscal_year.fiscal_year.auto_create_fiscal_year"
|
||||
],
|
||||
"daily_long": [
|
||||
"erpnext.setup.doctype.backup_manager.backup_manager.take_backups_daily"
|
||||
|
Loading…
Reference in New Issue
Block a user