mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-16 11:39:18 +00:00
Update recurring_document.py
This commit is contained in:
@@ -44,12 +44,13 @@ def manage_recurring_documents(doctype, next_date=None, commit=True):
|
|||||||
exception_list = []
|
exception_list = []
|
||||||
for ref_document, recurring_id in recurring_documents:
|
for ref_document, recurring_id in recurring_documents:
|
||||||
if not frappe.db.sql("""select name from `tab%s`
|
if not frappe.db.sql("""select name from `tab%s`
|
||||||
where %s=%s and recurring_id=%s and docstatus=1"""
|
where %s=%s and recurring_id=%s and (docstatus=1 or docstatus=0)"""
|
||||||
% (doctype, date_field, '%s', '%s'), (next_date, recurring_id)):
|
% (doctype, date_field, '%s', '%s'), (next_date, recurring_id)):
|
||||||
try:
|
try:
|
||||||
reference_doc = frappe.get_doc(doctype, ref_document)
|
reference_doc = frappe.get_doc(doctype, ref_document)
|
||||||
new_doc = make_new_document(reference_doc, date_field, next_date)
|
new_doc = make_new_document(reference_doc, date_field, next_date)
|
||||||
send_notification(new_doc)
|
if reference_doc.notify_by_email:
|
||||||
|
send_notification(new_doc)
|
||||||
if commit:
|
if commit:
|
||||||
frappe.db.commit()
|
frappe.db.commit()
|
||||||
except:
|
except:
|
||||||
@@ -92,7 +93,8 @@ def make_new_document(reference_doc, date_field, posting_date):
|
|||||||
date_field: posting_date,
|
date_field: posting_date,
|
||||||
"from_date": from_date,
|
"from_date": from_date,
|
||||||
"to_date": to_date,
|
"to_date": to_date,
|
||||||
"fiscal_year": get_fiscal_year(posting_date)[0]
|
"fiscal_year": get_fiscal_year(posting_date)[0],
|
||||||
|
"next_date": get_next_date(from_date, mcount,cint(reference_doc.repeat_on_day_of_month))
|
||||||
})
|
})
|
||||||
|
|
||||||
# copy document fields
|
# copy document fields
|
||||||
@@ -110,7 +112,11 @@ def make_new_document(reference_doc, date_field, posting_date):
|
|||||||
|
|
||||||
new_document.run_method("on_recurring", reference_doc=reference_doc)
|
new_document.run_method("on_recurring", reference_doc=reference_doc)
|
||||||
|
|
||||||
new_document.submit()
|
if not reference_doc.notify_by_email:
|
||||||
|
new_document.docstatus=0
|
||||||
|
new_document.insert()
|
||||||
|
else:
|
||||||
|
new_document.submit()
|
||||||
|
|
||||||
return new_document
|
return new_document
|
||||||
|
|
||||||
@@ -181,18 +187,19 @@ def convert_to_recurring(doc, posting_date):
|
|||||||
#
|
#
|
||||||
|
|
||||||
def validate_notification_email_id(doc):
|
def validate_notification_email_id(doc):
|
||||||
if doc.notification_email_address:
|
if doc.notify_by_email:
|
||||||
email_list = split_emails(doc.notification_email_address.replace("\n", ""))
|
if doc.notification_email_address:
|
||||||
|
email_list = split_emails(doc.notification_email_address.replace("\n", ""))
|
||||||
|
|
||||||
from frappe.utils import validate_email_add
|
from frappe.utils import validate_email_add
|
||||||
for email in email_list:
|
for email in email_list:
|
||||||
if not validate_email_add(email):
|
if not validate_email_add(email):
|
||||||
throw(_("{0} is an invalid email address in 'Notification \
|
throw(_("{0} is an invalid email address in 'Notification \
|
||||||
Email Address'").format(email))
|
Email Address'").format(email))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
frappe.throw(_("'Notification Email Addresses' not specified for recurring %s") \
|
frappe.throw(_("'Notification Email Addresses' not specified for recurring %s") \
|
||||||
% doc.doctype)
|
% doc.doctype)
|
||||||
|
|
||||||
def set_next_date(doc, posting_date):
|
def set_next_date(doc, posting_date):
|
||||||
""" Set next date on which recurring document will be created"""
|
""" Set next date on which recurring document will be created"""
|
||||||
@@ -200,7 +207,7 @@ def set_next_date(doc, posting_date):
|
|||||||
if not doc.repeat_on_day_of_month:
|
if not doc.repeat_on_day_of_month:
|
||||||
msgprint(_("Please enter 'Repeat on Day of Month' field value"), raise_exception=1)
|
msgprint(_("Please enter 'Repeat on Day of Month' field value"), raise_exception=1)
|
||||||
|
|
||||||
next_date = get_next_date(posting_date, month_map[doc.recurring_type],
|
next_date = doc.next_date or get_next_date(doc.from_date, month_map[doc.recurring_type],
|
||||||
cint(doc.repeat_on_day_of_month))
|
cint(doc.repeat_on_day_of_month))
|
||||||
|
|
||||||
frappe.db.set(doc, 'next_date', next_date)
|
frappe.db.set(doc, 'next_date', next_date)
|
||||||
|
|||||||
Reference in New Issue
Block a user