Beispiel #1
0
    def act_getfile(self):
        this = self[0]
        lang = this.lang if this.lang != NEW_LANG_KEY else False
        mods = sorted(this.mapped('modules.name')) or ['all']

        with contextlib.closing(io.BytesIO()) as buf:
            tools.trans_export(lang, mods, buf, this.format, self._cr)
            out = base64.encodestring(buf.getvalue())

        filename = 'new'
        if lang:
            filename = tools.get_iso_codes(lang)
        elif len(mods) == 1:
            filename = mods[0]
        extension = this.format
        if not lang and extension == 'po':
            extension = 'pot'
        name = "%s.%s" % (filename, extension)
        this.write({'state': 'get', 'data': out, 'name': name})
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'base.language.export',
            'view_mode': 'form',
            'view_type': 'form',
            'res_id': this.id,
            'views': [(False, 'form')],
            'target': 'new',
        }
Beispiel #2
0
    def act_getfile(self):
        this = self[0]
        lang = this.lang if this.lang != NEW_LANG_KEY else False
        mods = sorted(this.mapped('modules.name')) or ['all']

        with contextlib.closing(io.BytesIO()) as buf:
            tools.trans_export(lang, mods, buf, this.format, self._cr)
            out = base64.encodestring(buf.getvalue())

        filename = 'new'
        if lang:
            filename = tools.get_iso_codes(lang)
        elif len(mods) == 1:
            filename = mods[0]
        extension = this.format
        if not lang and extension == 'po':
            extension = 'pot'
        name = "%s.%s" % (filename, extension)
        this.write({'state': 'get', 'data': out, 'name': name})
        return {
            'type': 'ir.actions.act_window',
            'res_model': 'base.language.export',
            'view_mode': 'form',
            'view_type': 'form',
            'res_id': this.id,
            'views': [(False, 'form')],
            'target': 'new',
        }
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with contextlib.closing(io.BytesIO()) as buf:
         tools.trans_export(this.lang, ['all'], buf, 'csv', self._cr)
         tools.trans_load_data(self._cr, buf, 'csv', this.lang, lang_name=lang_name)
     return {'type': 'ir.actions.act_window_close'}
    def button_save_translation(self):

        format_ = 'po'

        i18n_path = os.path.join(get_module_path(self.name), 'i18n')
        if not os.path.isdir(i18n_path):
            os.mkdir(i18n_path)

        lang_obj = self.env['res.lang']
        condition = [('translatable', '=', True), ('code', '!=', 'en_US')]
        langs = lang_obj.search(condition)

        files = [('%s.pot' % self.name, False)]
        for lang in langs:
            iso_code = get_iso_codes(lang.code)
            filename = '%s.%s' % (iso_code, format_)
            files.append((filename, lang.code))

        for filename, lang in files:
            path = os.path.join(i18n_path, filename)
            with open(path, 'w') as buf:
                tools.trans_export(lang, [self.name], buf, format_,
                                   self.env.cr)

        return True
Beispiel #5
0
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(this.lang, ['all'], buf, 'po', self._cr)
         tools.trans_load_data(self._cr, buf, 'po', this.lang, lang_name=lang_name)
     return {'type': 'ir.actions.act_window_close'}
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(this.lang, ['all'], buf, 'po', self._cr)
         context = {'create_empty_translation': True}
         tools.trans_load_data(self._cr, buf, 'po', this.lang, lang_name=lang_name, context=context)
     return {'type': 'ir.actions.act_window_close'}
Beispiel #7
0
 def act_update(self):
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(self.lang, ['all'], buf, 'po', self._cr)
         tools.trans_load_data(self._cr,
                               buf,
                               'po',
                               self.lang,
                               create_empty_translation=True)
     return {'type': 'ir.actions.act_window_close'}
Beispiel #8
0
def export(ctx, language, db_name, module, fix):
    modules = module or ['all']

    from odoo.modules.registry import Registry
    from odooku.api import environment
    from odoo.tools import trans_export

    with tempfile.TemporaryFile() as t:

        # Perform checks (and possible fixes)
        registry = Registry(db_name)
        with registry.cursor() as cr:
            with environment(cr) as env:
                lang = env['res.lang'].with_context(
                    dict(active_test=False)).search([('code', '=', language)])
                if not lang:
                    raise ValueError("Language %s does not exist" % language)
                if not lang[0].active:
                    if not fix:
                        raise ValueError("Language %s is not activated" %
                                         language)
                    else:
                        installed = env['ir.module.module'].search([
                            ('state', '=', 'installed')
                        ])
                        installed._update_translations(language)

                if module:
                    installed = env['ir.module.module'].search([
                        ('name', 'in', module), ('state', '=', 'installed')
                    ])
                    missing = set(module) - set(
                        [mod.name for mod in installed])
                    if missing:
                        if not fix:
                            raise ValueError("Modules '%s' are not installed" %
                                             ", ".join(missing))
                        else:
                            ctx.obj['config']['init'] = {
                                module_name: 1
                                for module_name in module
                            }

        # Export
        registry = Registry.new(db_name, update_module=fix)
        with registry.cursor() as cr:
            with environment(cr) as env:
                trans_export(language, modules, t, 'po', cr)

        t.seek(0)
        # Pipe to stdout
        while True:
            chunk = t.read(CHUNK_SIZE)
            if not chunk:
                break
            sys.stdout.buffer.write(chunk)
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with contextlib.closing(io.BytesIO()) as buf:
         tools.trans_export(this.lang, ['all'], buf, 'csv', self._cr)
         tools.trans_load_data(self._cr,
                               buf,
                               'csv',
                               this.lang,
                               lang_name=lang_name)
     return {'type': 'ir.actions.act_window_close'}
 def act_update(self):
     this = self[0]
     lang_name = self._get_lang_name(this.lang)
     with tempfile.NamedTemporaryFile() as buf:
         tools.trans_export(this.lang, ['all'], buf, 'tgz', self._cr)
         context = {'create_empty_translation': True}
         buf.seek(0)
         tar = tarfile.open(fileobj=buf)
         for file_info in tar:
             module_file = tar.extractfile(file_info)
             tools.trans_load_data(self._cr, module_file, 'po', this.lang, lang_name=lang_name,
                                   module_name=file_info.name.partition('/')[0], context=context)
         tar.close()
     return {'type': 'ir.actions.act_window_close'}
Beispiel #11
0
def export(ctx, language, db_name, module):
    modules = module or ['all']

    from odoo.modules.registry import RegistryManager
    from odoo.api import Environment
    from odoo.tools import trans_export
    with tempfile.TemporaryFile() as t:
        registry = RegistryManager.get(db_name)
        with Environment.manage():
            with registry.cursor() as cr:
                trans_export(language, modules, t, 'po', cr)

        t.seek(0)
        # Pipe to stdout
        while True:
            chunk = t.read(CHUNK_SIZE)
            if not chunk:
                break
            sys.stdout.write(chunk)
Beispiel #12
0
    def get_zip_content(self, report_id):
        ir_report = request.env['ir.actions.report.xml'].browse(report_id)
        if ir_report:
            report_name = ir_report.report_name.split('.')[1]
            module_name = report_name.replace('-', '_')
            dir_path = {
                "report_template_path":
                os.path.join("report", report_name + ".xml"),
                "report_action_path":
                os.path.join("report", "report_action.xml")
            }
            view = request.env['ir.ui.view'].search([('name', 'ilike',
                                                      report_name),
                                                     ('type', '=', 'qweb')])

            report_action = '''<?xml version="1.0" encoding="utf-8"?>
<odoo>
    <data>
        <report
            id="%s"
            string="%s"
            model="%s"
            report_type="%s"
            file="%s"
            name="%s"
        />

        <record id="%s" model="ir.actions.report.xml">
            <field name="is_report_designer">True</field>
            <field name="print_report_name">%s</field>
        </record>
    </data>
</odoo>
''' % (
                "action_report_" + report_name,
                ir_report.name,
                ir_report.model,
                ir_report.report_type,
                module_name + "." + ir_report.report_name.split('.')[1],
                module_name + "." + ir_report.report_name.split('.')[1],
                "action_report_" + report_name,
                "'%s-%s.pdf' % (object.name, object.id)",
            )

            manifest = """# -*- coding: utf-8 -*-
{
    'name': %r,
    'version': '1.0',
    'category': 'Report Designer',
    'description': %s,
    'depends': [%s
    ],
    'data': [%s
    ],
    'application': %s
}
""" % (module_name, 'u"""\n%s\n"""' % "Export report using Report Designer",
            "\n        %r," % "report_designer_73lines", ''.join(
            "\n        %r," % value for key, value in dir_path.items()), False)
            manifest = manifest.encode('utf-8')
            report_action = report_action.encode('utf-8')

            with closing(io.BytesIO()) as buf:
                tools.trans_export(False, [module_name], buf, 'po',
                                   request._cr)
                pot = buf.getvalue()

            with closing(io.BytesIO()) as f:
                with zipfile.ZipFile(f, 'w') as archive:
                    data = E.data()
                    for v in view:
                        data.append(etree.fromstring(v.arch_base))
                        ele = data.findall(".//t[@t-name]")
                        if len(ele):
                            t_name = ele[0].attrib['t-name'].split('.')[1]
                            ele[0].set('id', t_name)
                            ele[0].tag = "template"
                            del ele[0].attrib['t-name']
                        data.append(
                            etree.fromstring('''
    <record id="%s" model="ir.ui.view">
        <field name="model">%s</field>
    </record>''' % (t_name, ir_report.model)))

                    template_xml = etree.tostring(E.odoo(data),
                                                  pretty_print=True,
                                                  encoding='UTF-8',
                                                  xml_declaration=True)
                    archive.writestr(
                        os.path.join(module_name,
                                     dir_path['report_template_path']),
                        template_xml)
                    archive.writestr(
                        os.path.join(module_name,
                                     dir_path['report_action_path']),
                        report_action)
                    archive.writestr(
                        os.path.join(module_name, 'i18n',
                                     module_name + '.pot'), pot)
                    archive.writestr(
                        os.path.join(module_name, '__manifest__.py'), manifest)
                    archive.writestr(os.path.join(module_name, '__init__.py'),
                                     b'')

                return f.getvalue(), (ir_report.name + "-" +
                                      str(ir_report.id)).replace(' ', '-')
        return ()