fix in scheduler related import issue
This commit is contained in:
parent
b37f22dc97
commit
f9e4b16731
@ -23,7 +23,6 @@ from webnotes.model.doc import Document, addchild, removechild, getchildren, mak
|
|||||||
from webnotes.model.doclist import getlist, copy_doclist
|
from webnotes.model.doclist import getlist, copy_doclist
|
||||||
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
|
from webnotes.model.code import get_obj, get_server_obj, run_server_obj, updatedb, check_syntax
|
||||||
from webnotes import session, form, is_testing, msgprint, errprint
|
from webnotes import session, form, is_testing, msgprint, errprint
|
||||||
from webnotes.utils.scheduler import set_event, cancel_event, Scheduler
|
|
||||||
|
|
||||||
in_transaction = webnotes.conn.in_transaction
|
in_transaction = webnotes.conn.in_transaction
|
||||||
convert_to_lists = webnotes.conn.convert_to_lists
|
convert_to_lists = webnotes.conn.convert_to_lists
|
||||||
@ -692,29 +691,6 @@ class DocType(TransactionBase):
|
|||||||
elif self.doc.recurring_id:
|
elif self.doc.recurring_id:
|
||||||
webnotes.conn.sql("""update `tabReceivable Voucher` set convert_into_recurring_invoice = 0 where recurring_id = %s""", self.doc.recurring_id)
|
webnotes.conn.sql("""update `tabReceivable Voucher` set convert_into_recurring_invoice = 0 where recurring_id = %s""", self.doc.recurring_id)
|
||||||
|
|
||||||
self.manage_scheduler()
|
|
||||||
|
|
||||||
def manage_scheduler(self):
|
|
||||||
""" set/cancel event in scheduler """
|
|
||||||
event = 'accounts.doctype.gl_control.gl_control.manage_recurring_invoices'
|
|
||||||
|
|
||||||
if webnotes.conn.sql("select name from `tabReceivable Voucher` where ifnull(convert_into_recurring_invoice, 0) = 1 and next_date <= end_date"):
|
|
||||||
if not self.check_event_exists(event):
|
|
||||||
set_event(event, interval = 60*60, recurring = 1)
|
|
||||||
else:
|
|
||||||
cancel_event(event)
|
|
||||||
|
|
||||||
|
|
||||||
def check_event_exists(self, event):
|
|
||||||
try:
|
|
||||||
ev = Scheduler().get_events()
|
|
||||||
except:
|
|
||||||
msgprint("Scheduler database not exists. Please mail to support@erpnext.com", raise_exception=1)
|
|
||||||
|
|
||||||
if event in [d['event'] for d in ev]:
|
|
||||||
return 1
|
|
||||||
|
|
||||||
|
|
||||||
def set_next_date(self):
|
def set_next_date(self):
|
||||||
""" Set next date on which auto invoice will be created"""
|
""" Set next date on which auto invoice will be created"""
|
||||||
|
|
||||||
|
@ -422,49 +422,6 @@ class DocType:
|
|||||||
#webnotes.errprint(webnotes.getTraceback())
|
#webnotes.errprint(webnotes.getTraceback())
|
||||||
|
|
||||||
|
|
||||||
def on_update(self):
|
|
||||||
"""
|
|
||||||
|
|
||||||
"""
|
|
||||||
import webnotes
|
|
||||||
args = {
|
|
||||||
'db_name': webnotes.conn.get_value('Control Panel', '', 'account_id'),
|
|
||||||
'event': 'setup.doctype.email_digest.email_digest.send'
|
|
||||||
}
|
|
||||||
from webnotes.utils.scheduler import Scheduler
|
|
||||||
#print "before scheduler"
|
|
||||||
sch = Scheduler()
|
|
||||||
sch.connect()
|
|
||||||
|
|
||||||
if self.doc.enabled == 1:
|
|
||||||
# Create scheduler entry
|
|
||||||
res = sch.conn.sql("""
|
|
||||||
SELECT * FROM Event
|
|
||||||
WHERE
|
|
||||||
db_name = %(db_name)s AND
|
|
||||||
event = %(event)s
|
|
||||||
""", args)
|
|
||||||
|
|
||||||
if not (res and res[0]):
|
|
||||||
args['next_execution'] = self.get_next_execution()
|
|
||||||
sch.conn.begin()
|
|
||||||
sch.conn.sql("""
|
|
||||||
INSERT INTO Event (db_name, event, `interval`, next_execution, recurring)
|
|
||||||
VALUES (%(db_name)s, %(event)s, 86400, %(next_execution)s, 1)
|
|
||||||
""", args)
|
|
||||||
sch.conn.commit()
|
|
||||||
|
|
||||||
else:
|
|
||||||
# delete scheduler entry if no other email digest is enabled
|
|
||||||
res = webnotes.conn.sql("""
|
|
||||||
SELECT * FROM `tabEmail Digest`
|
|
||||||
WHERE enabled=1
|
|
||||||
""")
|
|
||||||
if not (res and res[0]):
|
|
||||||
sch.clear(args['db_name'], args['event'])
|
|
||||||
#print "after on update"
|
|
||||||
|
|
||||||
|
|
||||||
def get_next_sending(self):
|
def get_next_sending(self):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
@ -17,13 +17,40 @@
|
|||||||
"""will be called by scheduler"""
|
"""will be called by scheduler"""
|
||||||
|
|
||||||
import webnotes
|
import webnotes
|
||||||
|
from webnotes.utils import scheduler
|
||||||
|
|
||||||
def execute_all():
|
def execute_all():
|
||||||
"""get support email"""
|
"""
|
||||||
|
* get support email
|
||||||
|
* recurring invoice
|
||||||
|
"""
|
||||||
|
try:
|
||||||
from support.doctype.support_ticket import get_support_mails
|
from support.doctype.support_ticket import get_support_mails
|
||||||
get_support_mails()
|
get_support_mails()
|
||||||
|
except Exception, e:
|
||||||
|
scheduler.log('get_support_mails')
|
||||||
|
|
||||||
|
try:
|
||||||
|
from accounts.doctype.gl_control.gl_control import manage_recurring_invoices
|
||||||
|
manage_recurring_invoices()
|
||||||
|
except Exception, e:
|
||||||
|
scheduler.log('manage_recurring_invoices')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def execute_daily():
|
def execute_daily():
|
||||||
"""email digest"""
|
"""email digest"""
|
||||||
|
try:
|
||||||
from setup.doctype.email_digest.email_digest import send
|
from setup.doctype.email_digest.email_digest import send
|
||||||
send()
|
send()
|
||||||
|
except Exception, e:
|
||||||
|
scheduler.log('email_digest.send')
|
||||||
|
|
||||||
|
def execute_weekly():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def execute_monthly():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def execute_hourly():
|
||||||
|
pass
|
||||||
|
Loading…
x
Reference in New Issue
Block a user