Пример #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
 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