Exemplo 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
Exemplo 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
        (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
Exemplo n.º 3
0
Arquivo: ipc.py Projeto: xt0ph/tryton
 def __init__(self, hostname, port, database):
     from tryton.common import slugify
     if Server.instance:
         Server.instance.stop()
     self.hostname = slugify(hostname).lower()
     self.port = port
     self.database = slugify(database)
     self.config = os.path.join(get_config_dir(), '%s@%s@%s' %
             (self.hostname, self.port, self.database))
     self.tmpdir = tempfile.mkdtemp(prefix='.tryton')
     Server.instance = self
Exemplo n.º 4
0
 def __init__(self, hostname, port, database):
     from tryton.common import slugify
     if Server.instance:
         Server.instance.stop()
     self.hostname = slugify(hostname)
     self.port = port
     self.database = slugify(database)
     self.config = os.path.join(get_config_dir(), '%s@%s@%s' %
             (self.hostname, self.port, self.database))
     self.tmpdir = tempfile.mkdtemp(prefix='.tryton')
     Server.instance = self
Exemplo n.º 5
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
Exemplo n.º 6
0
    def response(self, dialog, response):
        if response == Gtk.ResponseType.OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_first()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)
            action = self.saveas.get_active()
            try:
                data = RPCExecute('model',
                                  self.model,
                                  'export_data',
                                  self.ids,
                                  fields,
                                  context=self.context)
            except RPCException:
                data = []

            if action == 0:
                fileno, fname = tempfile.mkstemp(
                    '.csv',
                    common.slugify(self.name) + '_')
                self.export_csv(fname, fields2, data, popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
            else:
                fname = common.file_selection(
                    _('Save As...'), action=Gtk.FileChooserAction.SAVE)
                if fname:
                    self.export_csv(fname, fields2, data)
        self.destroy()
Exemplo n.º 7
0
 def do_export(self, widget, export):
     if not self.modified_save():
         return
     if (self.screen.current_view
             and self.screen.current_view.view_type == 'tree'
             and self.screen.current_view.children_field):
         ids = [r.id for r in self.screen.listed_records]
         paths = self.screen.listed_paths
     else:
         ids = [r.id for r in self.screen.selected_records]
         paths = self.screen.selected_paths
     fields = [f['name'] for f in export['export_fields.']]
     data = RPCExecute(
         'model', self.model, 'export_data', ids, fields,
         context=self.screen.context)
     delimiter = ','
     if os.name == 'nt' and ',' == locale.localeconv()['decimal_point']:
         delimiter = ';'
     fileno, fname = tempfile.mkstemp(
         '.csv', common.slugify(export['name']) + '_')
     with open(fname, 'w') as fp:
         writer = csv.writer(fp, delimiter=delimiter)
         writer.writerow(fields)
         for row, path in zip_longest(data, paths or []):
             indent = len(path) - 1 if path else 0
             if row:
                 writer.writerow(WinExport.format_row(row, indent=indent))
     os.close(fileno)
     common.file_open(fname, 'csv')
Exemplo n.º 8
0
 def sig_open(self, widget=None):
     if not self.filename_field:
         return
     dtemp = tempfile.mkdtemp(prefix='tryton_')
     filename = self.filename_field.get(self.record)
     if not filename:
         return
     root, ext = os.path.splitext(filename)
     filename = ''.join([slugify(root), os.extsep, slugify(ext)])
     file_path = os.path.join(dtemp, filename)
     with open(file_path, 'wb') as fp:
         fp.write(self.field.get_data(self.record))
     root, type_ = os.path.splitext(filename)
     if type_:
         type_ = type_[1:]
     file_open(file_path, type_)
Exemplo n.º 9
0
    def response(self, dialog, response):
        if response == Gtk.ResponseType.OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_first()
            while iter:
                fields.append(self.model2.get_value(iter, 1))
                fields2.append(self.model2.get_value(iter, 0))
                iter = self.model2.iter_next(iter)

            if self.selected_records.get_active():
                ids = [r.id for r in self.screen.selected_records]
                paths = self.screen.selected_paths
                try:
                    data = RPCExecute(
                        'model', self.model, 'export_data',
                        ids, fields,
                        context=self.context)
                except RPCException:
                    data = []
            elif self.screen_is_tree:
                ids = [r.id for r in self.screen.listed_records]
                paths = self.screen.listed_paths
                try:
                    data = RPCExecute(
                        'model', self.model, 'export_data',
                        ids, fields,
                        context=self.context)
                except RPCException:
                    data = []
            else:
                paths = None
                domain = self.screen.search_domain(
                    self.screen.screen_container.get_text())
                if self.ignore_search_limit.get_active():
                    offset, limit = 0, None
                else:
                    offset, limit = self.screen.offset, self.screen.limit
                try:
                    data = RPCExecute(
                        'model', self.model, 'export_data_domain',
                        domain, fields, offset, limit, self.screen.order,
                        context=self.context)
                except RPCException:
                    data = []

            if self.saveas.get_active():
                fname = common.file_selection(_('Save As...'),
                        action=Gtk.FileChooserAction.SAVE)
                if fname:
                    self.export_csv(fname, fields2, data, paths)
            else:
                fileno, fname = tempfile.mkstemp(
                    '.csv', common.slugify(self.name) + '_')
                self.export_csv(fname, fields2, data, paths, popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
        self.destroy()
Exemplo n.º 10
0
 def open_binary(self, renderer, path):
     if not self.filename:
         return
     dtemp = tempfile.mkdtemp(prefix='tryton_')
     record, field = self._get_record_field(path)
     filename_field = record.group.fields.get(self.filename)
     filename = filename_field.get(record)
     if not filename:
         return
     root, ext = os.path.splitext(filename)
     filename = ''.join([slugify(root), os.extsep, slugify(ext)])
     file_path = os.path.join(dtemp, filename)
     with open(file_path, 'wb') as fp:
         if hasattr(field, 'get_data'):
             fp.write(field.get_data(record))
         else:
             fp.write(field.get(record))
     root, type_ = os.path.splitext(filename)
     if type_:
         type_ = type_[1:]
     file_open(file_path, type_)
Exemplo n.º 11
0
 def open_binary(self, renderer, path):
     if not self.filename:
         return
     dtemp = tempfile.mkdtemp(prefix='tryton_')
     record, field = self._get_record_field(path)
     filename_field = record.group.fields.get(self.filename)
     filename = filename_field.get(record)
     if not filename:
         return
     root, ext = os.path.splitext(filename)
     filename = ''.join([slugify(root), os.extsep, slugify(ext)])
     file_path = os.path.join(dtemp, filename)
     with open(file_path, 'wb') as fp:
         if hasattr(field, 'get_data'):
             fp.write(field.get_data(record))
         else:
             fp.write(field.get(record))
     root, type_ = os.path.splitext(filename)
     if type_:
         type_ = type_[1:]
     file_open(file_path, type_)
Exemplo n.º 12
0
 def do_export(self, widget, export):
     if not self.modified_save():
         return
     ids = [r.id for r in self.screen.selected_records]
     fields = [f['name'] for f in export['export_fields.']]
     data = RPCExecute(
         'model', self.model, 'export_data', ids, fields,
         context=self.screen.context)
     delimiter = ','
     if os.name == 'nt' and ',' == locale.localeconv()['decimal_point']:
         delimiter = ';'
     fileno, fname = tempfile.mkstemp(
         '.csv', common.slugify(export['name']) + '_')
     with open(fname, 'w') as fp:
         writer = csv.writer(fp, delimiter=delimiter)
         writer.writerow(fields)
         writer.writerows(data)
     os.close(fileno)
     common.file_open(fname, 'csv')