예제 #1
0
    def _jasper_execute(self, ex, current_document, js_conf, pdf_list, reload=False,
                        ids=None, context=None):
        """
        After retrieve datas to launch report, execute it and return the content
        """
        # Issue 934068 with web client with model is missing from the context
        if not self.model:
            self.model = current_document.model_id.model
            self.model_obj = self.pool.get(self.model)

        if context is None:
            context = self.context.copy()

        if ids is None:
            ids = []

        cur_obj = self.model_obj.browse(self.cr, self.uid, ex, context=context)
        aname = False
        if self.attrs['attachment']:
            try:
                aname = eval(self.attrs['attachment'], {'object': cur_obj, 'time': time})
            except SyntaxError, e:
                logger.warning('Error %s' % str(e))
                raise EvalError(_('Attachment Error'), _('Syntax error when evaluate attachment\n\nMessage: "%s"') % str(e))
            except NameError, e:
                logger.warning('Error %s' % str(e))
                raise EvalError(_('Attachment Error'), _('Error when evaluate attachment\n\nMessage: "%s"') % str(e))
예제 #2
0
 def _eval_duplicate(self, cur_obj, current_document):
     """
     Evaluate the duplicate field
     """
     try:
         return int(eval(current_document.duplicate, {'o': cur_obj}))
     except SyntaxError, e:
         _logger.warning('Error %s' % str(e))
         raise EvalError(
             _('Duplicate Error'),
             _('Syntax error when evaluate duplicate\n\nMessage: "%s"') %
             str(e))  # noqa
예제 #3
0
 def _eval_field(self, cur_obj, fieldcontent):
     """
     Evaluate the field
     """
     try:
         return eval(fieldcontent, {'object': cur_obj, 'time': time})
     except SyntaxError, e:
         _logger.warning('Error %s' % str(e))
         raise EvalError(
             _('Field Eval Error'),
             _('Syntax error when evaluate field\n\nMessage: "%s"') %
             str(e))  # noqa
예제 #4
0
 def _eval_lang(self, cur_obj, current_document):
     """
     Evaluate the lang field
     """
     try:
         return eval(current_document.lang, {'o': cur_obj})
     except SyntaxError, e:
         logger.warning('Error %s' % str(e))
         raise EvalError(
             _('Language Error'),
             _('Syntax error when evaluate language\n\nMessage: "%s"') %
             str(e))
예제 #5
0
    def _jasper_execute(self,
                        ex,
                        current_document,
                        js_conf,
                        pdf_list,
                        ids=None,
                        context=None):
        """
        After retrieve datas to launch report, execute it and return the content
        """
        if context is None:
            context = self.context.copy()

        if ids is None:
            ids = []

        doc_obj = self.pool.get('jasper.document')
        js_obj = self.pool.get('jasper.server')
        cur_obj = self.model_obj.browse(self.cr, self.uid, ex, context=context)
        aname = False
        if self.attrs['attachment']:
            try:
                aname = eval(self.attrs['attachment'], {
                    'object': cur_obj,
                    'time': time
                })
            except SyntaxError, e:
                _logger.warning('Error %s' % str(e))
                raise EvalError(
                    _('Attachment Error'),
                    _('Syntax error when evaluate attachment\n\nMessage: "%s"')
                    % str(e))
            except NameError, e:
                _logger.warning('Error %s' % str(e))
                raise EvalError(
                    _('Attachment Error'),
                    _('Error when evaluate attachment\n\nMessage: "%s"') %
                    str(e))
예제 #6
0
    def _eval_lang(self, cur_obj, current_document, context=None):
        """
        Evaluate the lang field
        """
        if context is None:
            context = {}

        try:
            return eval(current_document.lang, {'o': cur_obj, 'ctx': context})
        except SyntaxError, e:
            _logger.warning('Error %s' % str(e))
            raise EvalError(
                _('Language Error'),
                _('Syntax error when evaluate language\n\nMessage: "%s"') %
                str(e))  # noqa
예제 #7
0
 def _eval_attachment(self, cur_obj):
     """
     Launch eval on attachement field, and return the value
     """
     try:
         return eval(self.attrs['attachment'], {
             'object': cur_obj,
             'time': time
         })
     except SyntaxError, e:
         _logger.warning('Error %s' % str(e))
         raise EvalError(
             _('Attachment Error'),
             _('Syntax error when evaluate attachment\n\nMessage: "%s"') %
             str(e))  # noqa
예제 #8
0
class Report(object):
    """
    compose the SOAP Query, launch the query and return the value
    """
    def __init__(self, name, cr, uid, ids, data, context):
        """Initialise the report"""
        self.name = name
        self.service = name.replace('report.jasper.report_', '')
        self.cr = cr
        self.uid = uid
        self.ids = ids
        self.data = data
        self.attrs = data.get('form', {})
        self.custom = data.get('jasper', {})
        self.model = data.get('model', False)
        self.pool = pooler.get_pool(cr.dbname)
        self.outputFormat = 'PDF'
        self.path = None

        # Reuse object pool
        self.model_obj = self.pool.get(self.model)
        self.doc_obj = self.pool.get('jasper.document')
        self.js_obj = self.pool.get('jasper.server')
        self.obj = None

        # If no context, retrieve one on the current user
        self.context = context or self.pool.get('res.users').context_get(
            cr, uid, uid)

    def add_attachment(self,
                       res_id,
                       aname,
                       content,
                       mimetype='binary',
                       context=None):
        """
        Add attachment for this report
        """
        name = aname + '.' + self.outputFormat.lower()
        ctx = context.copy()
        ctx['type'] = mimetype
        ctx['default_type'] = 'binary'

        return self.pool.get('ir.attachment').create(
            self.cr,
            self.uid, {
                'name': name,
                'datas': base64.encodestring(content),
                'datas_fname': name,
                'file_type': mimetype,
                'res_model': self.model,
                'res_id': res_id
            },
            context=ctx)

    def _eval_field(self, cur_obj, fieldcontent):
        """
        Evaluate the field
        """
        try:
            return eval(fieldcontent, {'object': cur_obj, 'time': time})
        except SyntaxError, e:
            _logger.warning('Error %s' % str(e))
            raise EvalError(
                _('Field Eval Error'),
                _('Syntax error when evaluate field\n\nMessage: "%s"') %
                str(e))  # noqa
        except NameError, e:
            _logger.warning('Error %s' % str(e))
            raise EvalError(_('Field Eval Error'),
                            _('Error when evaluate field\n\nMessage: "%s"') %
                            str(e))  # noqa
예제 #9
0
    def _jasper_execute(self,
                        ex,
                        current_document,
                        js_conf,
                        pdf_list,
                        reload=False,
                        ids=None,
                        context=None):
        """
        After retrieve datas to launch report, execute it and
        return the content
        """
        # Issue 934068 with web client with model is missing from the context
        if not self.model:
            self.model = current_document.model_id.model
            self.model_obj = self.pool.get(self.model)

        if context is None:
            context = self.context.copy()

        if ids is None:
            ids = []

        cur_obj = self.model_obj.browse(self.cr, self.uid, ex, context=context)
        aname = False
        if self.attrs['attachment']:
            aname = self._eval_attachment(cur_obj)

        duplicate = 1
        if current_document.duplicate:
            duplicate = self._eval_duplicate(cur_obj, current_document)

        log_debug('Number of duplicate copy: %d' % int(duplicate))

        language = context.get('lang', 'en_US')
        if current_document.lang:
            language = self._eval_lang(cur_obj,
                                       current_document,
                                       context=context)

        # Check if we can launch this reports
        # Test can be simple, or un a function
        if current_document.check_sel != 'none':
            try:
                if current_document.check_sel == 'simple' and \
                   not eval(current_document.check_simple, {'o': cur_obj}):
                    raise JasperException(
                        _('Check Print Error'),
                        current_document.message_simple)  # noqa
                elif current_document.check_sel == 'func' and \
                        not hasattr(self.model_obj, 'check_print'):
                    raise JasperException(
                        _('Check Print Error'),
                        _('"check_print" function not found in "%s" object') %
                        self.model)  # noqa
                elif current_document.check_sel == 'func' and \
                        hasattr(self.model_obj, 'check_print') and \
                        not self.model_obj.check_print(self.cr, self.uid,
                                                       cur_obj,
                                                       context=context):
                    raise JasperException(
                        _('Check Print Error'),
                        _('Function "check_print" return an error'))  # noqa

            except SyntaxError, e:
                _logger.warning('Error %s' % str(e))
                raise EvalError(
                    _('Check Error'),
                    _('Syntax error when check condition\n\nMessage: "%s"') %
                    str(e))  # noqa
            except NameError, e:
                _logger.warning('Error %s' % str(e))
                raise EvalError(
                    _('Check Error'),
                    _('Error when check condition\n\nMessage: "%s"') %
                    str(e))  # noqa
예제 #10
0
            return eval(fieldcontent, {'object': cur_obj, 'time': time})
        except SyntaxError, e:
            _logger.warning('Error %s' % str(e))
            raise EvalError(
                _('Field Eval Error'),
                _('Syntax error when evaluate field\n\nMessage: "%s"') %
                str(e))  # noqa
        except NameError, e:
            _logger.warning('Error %s' % str(e))
            raise EvalError(_('Field Eval Error'),
                            _('Error when evaluate field\n\nMessage: "%s"') %
                            str(e))  # noqa
        except AttributeError, e:
            _logger.warning('Error %s' % str(e))
            raise EvalError(
                _('Field Eval Error'),
                _('Attribute error when evaluate field\nVerify if specify field exists and valid\n\nMessage: "%s"'
                  ) % str(e))  # noqa
        except Exception, e:
            _logger.warning('Error %s' % str(e))
            raise EvalError(
                _('Field Eval Error'),
                _('Unknown error when evaluate field\nMessage: "%s"') %
                str(e))  # noqa

    def _eval_attachment(self, cur_obj):
        """
        Launch eval on attachement field, and return the value
        """
        try:
            return eval(self.attrs['attachment'], {
                'object': cur_obj,
예제 #11
0
class Report(object):
    """
    compose the SOAP Query, launch the query and return the value
    """
    def __init__(self, name, cr, uid, ids, data, context):
        """Initialise the report"""
        self.name = name
        self.service = name.replace('report.jasper.', '')
        self.cr = cr
        self.uid = uid
        self.ids = ids
        self.data = data
        self.attrs = data.get('form', {})
        self.custom = data.get('jasper', {})
        self.model = data.get('model', False)
        self.pool = pooler.get_pool(cr.dbname)
        self.outputFormat = 'pdf'
        self.path = None

        # Reuse object pool
        self.model_obj = self.pool.get(self.model)
        self.doc_obj = self.pool.get('jasper.document')
        self.js_obj = self.pool.get('jasper.server')
        self.obj = None

        # If no context, retrieve one on the current user
        self.context = context or self.pool.get('res.users').context_get(cr, uid, uid)

    def add_attachment(self, id, aname, content, context=None):
        """
        Add attachment for this report
        """
        name = aname + '.' + self.outputFormat
        ctx = context.copy()
        ctx['type'] ='binary'
        ctx['default_type'] ='binary'
        
        return self.pool.get('ir.attachment').create(self.cr, self.uid, {
                    'name': aname,
                    'datas': base64.encodestring(content),
                    'datas_fname': name,
                    'res_model': self.model,
                    'res_id': id,
                    }, context=ctx
        )

    def _jasper_execute(self, ex, current_document, js_conf, pdf_list, reload=False,
                        ids=None, context=None):
        """
        After retrieve datas to launch report, execute it and return the content
        """
        # Issue 934068 with web client with model is missing from the context
        if not self.model:
            self.model = current_document.model_id.model
            self.model_obj = self.pool.get(self.model)

        if context is None:
            context = self.context.copy()

        if ids is None:
            ids = []

        cur_obj = self.model_obj.browse(self.cr, self.uid, ex, context=context)
        aname = False
        if self.attrs['attachment']:
            try:
                aname = eval(self.attrs['attachment'], {'object': cur_obj, 'time': time})
            except SyntaxError, e:
                logger.warning('Error %s' % str(e))
                raise EvalError(_('Attachment Error'), _('Syntax error when evaluate attachment\n\nMessage: "%s"') % str(e))
            except NameError, e:
                logger.warning('Error %s' % str(e))
                raise EvalError(_('Attachment Error'), _('Error when evaluate attachment\n\nMessage: "%s"') % str(e))
            except AttributeError, e:
                logger.warning('Error %s' % str(e))
                raise EvalError(_('Attachment Error'), _('Attribute error when evaluate attachment\nVerify if specify field exists and valid\n\nMessage: "%s"') % str(e))
예제 #12
0
class Report(object):
    """
    compose the SOAP Query, launch the query and return the value
    """
    def __init__(self, name, cr, uid, ids, data, context):
        """Initialise the report"""
        self.name = name
        self.service = name.replace('report.jasper.', '')
        self.cr = cr
        self.uid = uid
        self.ids = ids
        self.data = data
        self.attrs = data.get('form', {})
        self.custom = data.get('jasper', {})
        self.model = data.get('model', False)
        self.pool = pooler.get_pool(cr.dbname)
        self.model_obj = self.pool.get(self.model)
        self.obj = None
        self.outputFormat = 'pdf'
        self.path = None
        # If no context, retrieve one on the current user
        self.context = context or self.pool.get('res.users').context_get(
            cr, uid, uid)

    def _jasper_execute(self,
                        ex,
                        current_document,
                        js_conf,
                        pdf_list,
                        ids=None,
                        context=None):
        """
        After retrieve datas to launch report, execute it and return the content
        """
        if context is None:
            context = self.context.copy()

        if ids is None:
            ids = []

        doc_obj = self.pool.get('jasper.document')
        js_obj = self.pool.get('jasper.server')
        cur_obj = self.model_obj.browse(self.cr, self.uid, ex, context=context)
        aname = False
        if self.attrs['attachment']:
            try:
                aname = eval(self.attrs['attachment'], {
                    'object': cur_obj,
                    'time': time
                })
            except SyntaxError, e:
                _logger.warning('Error %s' % str(e))
                raise EvalError(
                    _('Attachment Error'),
                    _('Syntax error when evaluate attachment\n\nMessage: "%s"')
                    % str(e))
            except NameError, e:
                _logger.warning('Error %s' % str(e))
                raise EvalError(
                    _('Attachment Error'),
                    _('Error when evaluate attachment\n\nMessage: "%s"') %
                    str(e))
            except AttributeError, e:
                _logger.warning('Error %s' % str(e))
                raise EvalError(
                    _('Attachment Error'),
                    _('Attribute error when evaluate attachment\nVerify if specify field exists and valid\n\nMessage: "%s"'
                      ) % str(e))