Esempio n. 1
0
    def exec_report(name, data, direct_print=False, email_print=False,
            email=None, context=None):
        if context is None:
            context = {}
        if email is None:
            email = {}
        data = data.copy()
        ctx = rpc.CONTEXT.copy()
        ctx.update(context)
        ctx['direct_print'] = direct_print
        ctx['email_print'] = email_print
        ctx['email'] = email
        args = ('report', name, 'execute', data.get('ids', []), data, ctx)
        try:
            res = RPCProgress('execute', args).run()
        except RPCException:
            return False
        if not res:
            return False
        (type, data, print_p, name) = res
        if not print_p and direct_print:
            print_p = True
        dtemp = tempfile.mkdtemp(prefix='tryton_')

        fp_name = os.path.join(dtemp,
            slugify(name) + os.extsep + slugify(type))
        with open(fp_name, 'wb') as file_d:
            file_d.write(data)
        if email_print:
            mailto(to=email.get('to'), cc=email.get('cc'),
                subject=email.get('subject'), body=email.get('body'),
                attachment=fp_name)
        else:
            file_open(fp_name, type, print_p=print_p)
        return True
Esempio n. 2
0
    def exec_report(name,
                    data,
                    direct_print=False,
                    email_print=False,
                    email=None,
                    context=None):
        if context is None:
            context = {}
        if email is None:
            email = {}
        data = data.copy()
        ctx = rpc.CONTEXT.copy()
        ctx.update(context)
        ctx['direct_print'] = direct_print
        ctx['email_print'] = email_print
        ctx['email'] = email
        args = ('report', name, 'execute', data.get('ids', []), data, ctx)
        try:
            res = RPCProgress('execute', args).run()
        except RPCException:
            return False
        if not res:
            return False
        (types, datas, print_p, names) = res
        fp_names = []
        if not print_p and direct_print:
            print_p = True
        dtemp = tempfile.mkdtemp(prefix='tryton_')

        # ABE : #5658 : Manage multiple attachments
        if type(names) is not list:
            names = [names]
        if type(datas) is not list:
            datas = [datas]
        if type(types) is not list:
            types = [types]
        for data, name, type_ in zip(datas, names, types):
            fp_name = os.path.join(dtemp,
                                   slugify(name) + os.extsep + slugify(type_))
            with open(fp_name, 'wb') as file_d:
                file_d.write(data)
            fp_names.append((fp_name, type_))
        if email_print:
            mailto(to=email.get('to'),
                   cc=email.get('cc'),
                   bcc=email.get('bcc'),
                   subject=email.get('subject'),
                   body=email.get('body'),
                   attachment=','.join([x[0] for x in fp_names]))
        else:
            for fp_name, type_ in fp_names:
                file_open(fp_name, type_, print_p=print_p)
        return True
Esempio n. 3
0
    def exec_report(name,
                    data,
                    direct_print=False,
                    email_print=False,
                    email=None,
                    context=None):
        if context is None:
            context = {}
        if email is None:
            email = {}
        data = data.copy()
        ctx = rpc.CONTEXT.copy()
        ctx.update(context)
        ctx['direct_print'] = direct_print
        ctx['email_print'] = email_print
        ctx['email'] = email
        args = ('report', name, 'execute', data.get('ids', []), data, ctx)
        try:
            res = RPCProgress('execute', args).run()
        except RPCException:
            return False
        if not res:
            return False
        (type, data, print_p, name) = res
        if not print_p and direct_print:
            print_p = True

        fp_name = file_write((name, type), data)
        if email_print:
            mailto(to=email.get('to'),
                   cc=email.get('cc'),
                   subject=email.get('subject'),
                   body=email.get('body'),
                   attachment=fp_name)
        else:
            file_open(fp_name, type, print_p=print_p)
        return True