mirror of
https://github.com/frappe/erpnext.git
synced 2026-08-18 17:08:42 +00:00
fix: do not allow closing the accounting period for future dates (#56551)
(cherry picked from commit 5e60e4faa7)
Co-authored-by: rohitwaghchaure <rohitw1991@gmail.com>
This commit is contained in:
@@ -5,6 +5,7 @@
|
|||||||
import frappe
|
import frappe
|
||||||
from frappe import _
|
from frappe import _
|
||||||
from frappe.model.document import Document
|
from frappe.model.document import Document
|
||||||
|
from frappe.utils import getdate, nowdate
|
||||||
|
|
||||||
|
|
||||||
class OverlapError(frappe.ValidationError):
|
class OverlapError(frappe.ValidationError):
|
||||||
@@ -34,8 +35,20 @@ class AccountingPeriod(Document):
|
|||||||
# end: auto-generated types
|
# end: auto-generated types
|
||||||
|
|
||||||
def validate(self):
|
def validate(self):
|
||||||
|
self.validate_dates()
|
||||||
self.validate_overlap()
|
self.validate_overlap()
|
||||||
|
|
||||||
|
def validate_dates(self):
|
||||||
|
if getdate(self.start_date) > getdate(self.end_date):
|
||||||
|
frappe.throw(_("Start Date cannot be after End Date"))
|
||||||
|
|
||||||
|
if getdate(self.end_date) > getdate(nowdate()):
|
||||||
|
frappe.throw(
|
||||||
|
_(
|
||||||
|
"Accounting Period cannot be created for a future date. End Date {0} is after today."
|
||||||
|
).format(frappe.bold(frappe.format(self.end_date, "Date")))
|
||||||
|
)
|
||||||
|
|
||||||
def before_insert(self):
|
def before_insert(self):
|
||||||
self.bootstrap_doctypes_for_closing()
|
self.bootstrap_doctypes_for_closing()
|
||||||
|
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
import frappe
|
import frappe
|
||||||
from frappe.utils import add_months, nowdate
|
from frappe.utils import nowdate
|
||||||
|
|
||||||
from erpnext.accounts.doctype.accounting_period.accounting_period import (
|
from erpnext.accounts.doctype.accounting_period.accounting_period import (
|
||||||
ClosedAccountingPeriod,
|
ClosedAccountingPeriod,
|
||||||
@@ -47,7 +47,7 @@ def create_accounting_period(**args):
|
|||||||
|
|
||||||
accounting_period = frappe.new_doc("Accounting Period")
|
accounting_period = frappe.new_doc("Accounting Period")
|
||||||
accounting_period.start_date = args.start_date or nowdate()
|
accounting_period.start_date = args.start_date or nowdate()
|
||||||
accounting_period.end_date = args.end_date or add_months(nowdate(), 1)
|
accounting_period.end_date = args.end_date or nowdate()
|
||||||
accounting_period.company = args.company or "_Test Company"
|
accounting_period.company = args.company or "_Test Company"
|
||||||
accounting_period.period_name = args.period_name or "_Test_Period_Name_1"
|
accounting_period.period_name = args.period_name or "_Test_Period_Name_1"
|
||||||
accounting_period.append("closed_documents", {"document_type": "Sales Invoice", "closed": 1})
|
accounting_period.append("closed_documents", {"document_type": "Sales Invoice", "closed": 1})
|
||||||
|
|||||||
Reference in New Issue
Block a user