Ejemplo n.º 1
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            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()
            self.destroy()
            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', 'tryton_')
                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.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, data)
        else:
            self.destroy()
Ejemplo n.º 2
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')
Ejemplo n.º 3
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            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", "tryton_")
                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.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, data)
        self.destroy()
Ejemplo n.º 4
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
Ejemplo n.º 5
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            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.wid_action.get_active()
            self.destroy()
            result = self.datas_read(self.ids,
                                     self.model,
                                     fields,
                                     context=self.context)

            if action == 0:
                fileno, fname = tempfile.mkstemp('.csv', 'tryton_')
                self.export_csv(fname,
                                fields2,
                                result,
                                self.wid_write_field_names.get_active(),
                                popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
            else:
                fname = common.file_selection(
                    _('Save As...'), action=gtk.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, result,
                                    self.wid_write_field_names.get_active())
            return True
        else:
            self.destroy()
            return False
Ejemplo n.º 6
0
    def response(self, dialog, response):
        if response == gtk.RESPONSE_OK:
            fields = []
            fields2 = []
            iter = self.model2.get_iter_root()
            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.wid_action.get_active()
            self.destroy()
            result = self.datas_read(self.ids, self.model, fields,
                    context=self.context)

            if action == 0:
                fileno, fname = tempfile.mkstemp('.csv', 'tryton_')
                self.export_csv(fname, fields2, result,
                        self.wid_write_field_names.get_active(), popup=False)
                os.close(fileno)
                common.file_open(fname, 'csv')
            else:
                fname = common.file_selection(_('Save As...'),
                        action=gtk.FILE_CHOOSER_ACTION_SAVE)
                if fname:
                    self.export_csv(fname, fields2, result,
                            self.wid_write_field_names.get_active())
            return True
        else:
            self.destroy()
            return False
Ejemplo n.º 7
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,
             name.replace(os.sep, '_').replace(os.altsep or os.sep, '_') \
                     + os.extsep + 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
Ejemplo n.º 8
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()
Ejemplo n.º 9
0
 def open_data(attachment, context):
     try:
         value, = RPCExecute('model', 'ir.attachment', 'read',
             [attachment['id']], ['data'], context=context)
     except RPCException:
         return
     filepath = file_write(attachment['name'], value['data'])
     file_open(filepath)
Ejemplo n.º 10
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()
Ejemplo n.º 11
0
 def callback(result):
     try:
         result = result()
     except RPCException:
         return
     type, data, print_p, name = result
     if not print_p and direct_print:
         print_p = True
     fp_name = file_write((name, type), data)
     file_open(fp_name, type, print_p=print_p)
Ejemplo n.º 12
0
 def open_(self, widget=None):
     if not self.filename_field:
         return
     filename = self.filename_field.get(self.record)
     if not filename:
         return
     file_path = file_write(filename, self.get_data())
     root, type_ = os.path.splitext(filename)
     if type_:
         type_ = type_[1:]
     file_open(file_path, type_)
Ejemplo n.º 13
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
Ejemplo n.º 14
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).replace(
             os.sep, '_').replace(os.altsep or os.sep, '_')
     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_)
Ejemplo n.º 15
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).replace(
         os.sep, '_').replace(os.altsep or os.sep, '_')
     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_)
Ejemplo n.º 16
0
 def open_binary(self, renderer, path):
     if not self.filename:
         return
     record, field = self._get_record_field(path)
     filename_field = record.group.fields.get(self.filename)
     filename = filename_field.get(record)
     if not filename:
         return
     file_path = file_write(filename, self.get_data(record, field))
     root, type_ = os.path.splitext(filename)
     if type_:
         type_ = type_[1:]
     file_open(file_path, type_)
Ejemplo n.º 17
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_)
Ejemplo n.º 18
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).replace(
         os.sep, '_').replace(os.altsep or os.sep, '_')
     if not filename:
         return
     file_path = os.path.join(dtemp, filename)
     with open(file_path, 'wb') as fp:
         fp.write(field.get_data(record))
     root, type_ = os.path.splitext(filename)
     if type_:
         type_ = type_[1:]
     file_open(file_path, type_)
Ejemplo n.º 19
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).replace(
         os.sep, '_').replace(os.altsep or os.sep, '_')
     if not filename:
         return
     file_path = os.path.join(dtemp, filename)
     with open(file_path, 'wb') as fp:
         fp.write(field.get_data(record))
     root, type_ = os.path.splitext(filename)
     if type_:
         type_ = type_[1:]
     file_open(file_path, type_)
Ejemplo n.º 20
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')
Ejemplo n.º 21
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_)
Ejemplo n.º 22
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_)
Ejemplo n.º 23
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