Add company to messages sent by tryton when execution of cron fails
This commit is contained in:
parent
407eda25c0
commit
e639033053
|
@ -0,0 +1,44 @@
|
|||
diff -r 32a7b3eab9eb trytond/ir/cron.py
|
||||
--- a/trytond/trytond/ir/cron.py Tue May 10 08:46:45 2016 +0200
|
||||
+++ b/trytond/trytond/ir/cron.py Tue May 17 16:35:25 2016 +0200
|
||||
@@ -125,22 +125,34 @@
|
||||
return _INTERVALTYPES[cron.interval_type](cron.interval_number)
|
||||
|
||||
@classmethod
|
||||
- def send_error_message(cls, cron):
|
||||
+ def create_subject_message(cls):
|
||||
+ return cls.raise_user_error('request_title',
|
||||
+ raise_exception=False)
|
||||
+
|
||||
+ @classmethod
|
||||
+ def create_body_message(cls, cron):
|
||||
tb_s = ''.join(traceback.format_exception(*sys.exc_info()))
|
||||
tb_s = tb_s.decode('utf-8', 'ignore')
|
||||
- subject = cls.raise_user_error('request_title',
|
||||
- raise_exception=False)
|
||||
- body = cls.raise_user_error('request_body',
|
||||
+ return cls.raise_user_error('request_body',
|
||||
(cron.name, cron.__url__, tb_s),
|
||||
raise_exception=False)
|
||||
|
||||
- from_addr = config.get('email', 'from')
|
||||
- to_addr = cron.request_user.email
|
||||
+ @classmethod
|
||||
+ def create_error_message(cls, cron, from_addr, to_addr):
|
||||
+ subject = cls.create_subject_message()
|
||||
+ body = cls.create_body_message(cron)
|
||||
|
||||
msg = MIMEText(body, _charset='utf-8')
|
||||
msg['To'] = to_addr
|
||||
msg['From'] = from_addr
|
||||
msg['Subject'] = Header(subject, 'utf-8')
|
||||
+ return msg
|
||||
+
|
||||
+ @classmethod
|
||||
+ def send_error_message(cls, cron):
|
||||
+ from_addr = config.get('email', 'from')
|
||||
+ to_addr = cron.request_user.email
|
||||
+ msg = cls.create_error_message(cron, from_addr, to_addr)
|
||||
logger = logging.getLogger(__name__)
|
||||
if not to_addr:
|
||||
logger.error(msg.as_string())
|
|
@ -0,0 +1,26 @@
|
|||
diff -r 3af0565f0bad cron.py
|
||||
--- a/trytond/trytond/modules/company/cron.py Wed Dec 23 00:13:47 2015 +0100
|
||||
+++ b/trytond/trytond/modules/company/cron.py Tue May 17 16:18:02 2016 +0200
|
||||
@@ -15,6 +15,22 @@
|
||||
'Companies', help='Companies registered for this cron')
|
||||
|
||||
@classmethod
|
||||
+ def __setup__(cls):
|
||||
+ super(Cron, cls).__setup__()
|
||||
+ cls._error_messages.update({
|
||||
+ 'company': 'Company: %s\n',
|
||||
+ })
|
||||
+
|
||||
+ @classmethod
|
||||
+ def create_body_message(cls, cron):
|
||||
+ Company = Pool().get('company.company')
|
||||
+ company = Company(Transaction().context.get('company'))
|
||||
+ msg = cls.raise_user_error('company', (company.party.name,),
|
||||
+ raise_exception=False)
|
||||
+ msg += super(Cron, cls).create_body_message(cron)
|
||||
+ return msg
|
||||
+
|
||||
+ @classmethod
|
||||
def _callback(cls, cron):
|
||||
User = Pool().get('res.user')
|
||||
if not cron.companies:
|
Loading…
Reference in New Issue