def unlink_res_ids(self, cr, uid, ids, model, res_ids, context):
     unlink_line_ids = []
     for template in self.browse(cr, uid, ids, context):
         if template.model != model:
             raise except_orm(
                 _('Error'),
                 _("unlink_res_ids: model(%s) does not match template model (%s, %s)"
                   ) % (model, template.id, template.model))
         export_line_ids = self.pool.get('ir.model.export.line').search(
             cr,
             uid, [
                 ('export_id.export_tmpl_id', '=', template.id),
                 ('res_id', 'in', res_ids),
             ],
             context=context)
         if export_line_ids:
             real_res_ids = [
                 line['res_id']
                 for line in self.pool.get('ir.model.export.line').read(
                     cr, uid, export_line_ids, ['res_id'], context)
             ]
             logger = SmileDBLogger(cr.dbname, 'ir.model.export.template',
                                    template.id, uid)
             logger.info(
                 'Unlinking model: %s, res_ids: %s - real_res_ids found: %s'
                 % (model, res_ids, real_res_ids))
             self.pool.get('ir.model.export.line').unlink(
                 cr, uid, export_line_ids, context)
             unlink_line_ids.extend(export_line_ids)
     return unlink_line_ids
Exemple #2
0
    def _run_now(self, cr, uid, trigger_id, context):
        logger = SmileDBLogger(cr.dbname, self._name, trigger_id, uid)

        # Get sequence in order to differentiate logs per run
        context.setdefault('pid_list',
                           []).append(str(logger.pid).rjust(8, '0'))
        pid = '-'.join((str(x) for x in context['pid_list']))
        if not pid:
            logger.critical(
                'Action Trigger failed: impossible to get a pid for dbname %s'
                % (cr.dbname))
            return

        # Get sequence in order to differentiate logs per run
        if context.get('test_mode', False):
            logger.info('[%s] Trigger in test mode' % (pid, ))
        logger.debug('[%s] Trigger on %s' %
                     (pid, context.get('trigger', 'manual')))
        logger.debug('[%s] Context: %s' % (pid, context))
        trigger = self.browse(cr, uid, trigger_id, context)

        # Filter objects
        filtered_object_ids = []
        try:
            filtered_object_ids = self._get_filtered_object_ids(
                cr, uid, trigger, context)
            logger.debug('[%s] Successful Objects Filtering: %s' %
                         (pid, filtered_object_ids))
        except Exception, e:
            logger.exception('[%s] Objects Filtering failed: %s' %
                             (pid, _get_exception_message(e)))
            if trigger.exception_handling == 'continue' or trigger.exception_warning == 'none':
                return True
            else:
                cr.rollback()
                logger.time_info("[%s] Transaction rolled back" % (pid, ))
                if trigger.exception_warning == 'custom':
                    raise orm.except_orm(
                        _('Error'),
                        _('%s\n[Pid: %s]') % (trigger.exception_message, pid))
                elif trigger.exception_warning == 'native':
                    raise orm.except_orm(
                        _('Error'),
                        _('%s\n[Pid: %s]') % (_get_exception_message(e), pid))