コード例 #1
0
 def _filter(self, records, filter_type):
     self.ensure_one()
     logger = SmileDBLogger(self._cr.dbname, self._name, self.id, self._uid)
     pid = os.getpid()
     params = [
         pid, filter_type, self.name, self.model_id.model,
         tuple(records.ids)
     ]
     try:
         records = getattr(super(BaseAutomation, self),
                           '_filter_%s' % filter_type)(records)
         records = self._filter_max_executions(records)
         logger.debug('[%s] Successful %s-filtering: %s - '
                      'Input records: %s%s - Output records: %s%s' %
                      tuple(params + [self.model_id.model,
                                      tuple(records)]))
         return records
     except Exception as e:
         logger.error('[%s] %s-filtering failed: %s - '
                      'Input records: %s%s - Error: %s' %
                      tuple(params + [repr(e)]))
         if self.exception_handling == 'continue' or \
                 self.exception_warning == 'none':
             return []
         if self.exception_warning == 'custom':
             raise UserError(self.exception_message)
         e.traceback = sys.exc_info()
         raise
コード例 #2
0
ファイル: impex.py プロジェクト: Viranson/odoo_addons
 def _process(self):
     self.ensure_one()
     logger = SmileDBLogger(self._cr.dbname, self._name, self.id, self._uid)
     logger.setLevel(self.log_level)
     self = self.with_context(logger=logger)
     hostname = get_hostname()
     self.write({
         'state': 'running',
         'from_date': fields.Datetime.now(),
         'pid': os.getpid(),
         'hostname': hostname,
         'to_date': False
     })
     try:
         result = self._execute()
         vals = {'state': 'done', 'to_date': fields.Datetime.now()}
         if self.log_returns:
             vals['returns'] = repr(result)
         self.write(vals)
         if self.test_mode:
             self._cr.rollback()
         return result
     except Exception, e:
         logger.error(repr(e))
         try:
             self.write({
                 'state': 'exception',
                 'to_date': fields.Datetime.now()
             })
         except Exception:
             logger.warning("Cannot set import to exception")
         e.traceback = sys.exc_info()
         raise
コード例 #3
0
ファイル: export.py プロジェクト: Viranson/odoo_addons
 def create_export(self, *args):
     self._try_lock(_('Export already in progress'))
     try:
         export_recs = self._create_export(*args)
     except Exception, e:
         tmpl_logger = SmileDBLogger(self._cr.dbname, self._name, self.id, self._uid)
         tmpl_logger.error(repr(e))
         raise UserError(repr(e))
コード例 #4
0
 def create_import(self, *args):
     self._try_lock(_('Import already in progress'))
     try:
         import_rec = self._create_import(*args)
     except Exception as e:
         tmpl_logger = SmileDBLogger(self._cr.dbname, self._name, self.id,
                                     self._uid)
         tmpl_logger.error(repr(e))
         raise UserError(repr(e))
     else:
         return import_rec.process()
コード例 #5
0
 def create_export(self, *args):
     self._try_lock(_('Export already in progress'))
     try:
         export_recs = self._create_export(*args)
     except Exception as e:
         tmpl_logger = SmileDBLogger(self._cr.dbname, self._name, self.id,
                                     self._uid)
         tmpl_logger.error(repr(e))
         raise UserError(repr(e))
     else:
         res = export_recs.process()
         if self.do_not_store_record_ids:
             export_recs.write({'record_ids': ''})
         return res
コード例 #6
0
 def _process(self, records, domain_post=None):
     logger = SmileDBLogger(self._cr.dbname, self._name, self.id, self._uid)
     pid = os.getpid()
     params = [pid, self.name, self.model_id.model, tuple(records.ids)]
     logger.debug('[%s] Launching action: %s - Records: %s%s' %
                  tuple(params))
     try:
         # Check if __action_done is in context
         if '__action_done' not in self._context:
             self = self.with_context(__action_done={})
         # Force action execution even if records list is empty
         if not records and self.action_server_id and \
                 self.force_actions_execution:
             ctx = {
                 'active_model': records._name,
                 'active_ids': [],
                 'active_id': False,
             }
             self.action_server_id.with_context(**ctx).run()
             logger.time_info('[%s] Successful action: %s - '
                              'Records: %s%s' % tuple(params))
         else:
             super(BaseAutomation, self)._process(records, domain_post)
             # Update execution counters
             if self.max_executions:
                 self._update_execution_counter(records)
             if records:
                 logger.time_info('[%s] Successful action: %s - '
                                  'Records: %s%s' % tuple(params))
         return True
     except Exception as e:
         logger.error('[%s] Action failed: %s - '
                      'Records: %s%s - Error: %s' %
                      tuple(params + [repr(e)]))
         if self.exception_handling == 'continue' or \
                 self.exception_warning == 'none':
             return True
         if self.exception_warning == 'custom':
             raise UserError(self.exception_message)
         e.traceback = sys.exc_info()
         raise
コード例 #7
0
 def run(self):
     Intervention = self.env['smile.script.intervention']
     if not self._context.get('test_mode') and self.state == 'draft':
         raise UserError(_('You can only run validated scripts!'))
     intervention = Intervention.create({
         'script_id':
         self.id,
         'test_mode':
         self._context.get('test_mode'),
     })
     logger = SmileDBLogger(self._cr.dbname, 'smile.script.intervention',
                            intervention.id, self._uid)
     if not self._context.get('do_not_use_new_cursor'):
         intervention_cr = db_connect(self._cr.dbname).cursor()
     else:
         intervention_cr = self._cr
     intervention_vals = {}
     try:
         logger.info('Running script: %s\nCode:\n%s' %
                     (self.name, self.code))
         result = self.with_env(self.env(cr=intervention_cr))._run(logger)
         if not self._context.get('do_not_use_new_cursor'):
             if self._context.get('test_mode'):
                 logger.info('TEST MODE: Script rollbacking')
                 intervention_cr.rollback()
             else:
                 intervention_cr.commit()
         intervention_vals.update({'state': 'done', 'result': result})
         logger.info('Script execution SUCCEEDED: %s\n' % (self.name, ))
     except Exception as e:
         intervention_vals.update({
             'state': 'exception',
             'result': _get_exception_message(e),
         })
         logger.error('Script execution FAILED: %s\nError:\n%s' %
                      (self.name, _get_exception_message(e)))
     finally:
         if not self._context.get('do_not_use_new_cursor'):
             intervention_cr.close()
     intervention_vals.update({'end_date': fields.Datetime.now()})
     return intervention.write(intervention_vals)