在odoo中创建一个新的导入按钮

问题描述 投票:0回答:2

在我的python代码中,我有两个类:

class object_one(osv.osv):
    _name = "object.one"

class object_two(osv.osv):
    _name = "object.two"

我想在object.one的窗体视图中创建一个自定义导入按钮,以便导入object.two的数据,我试图在base_import模块的文件中搜索,但是徒劳无功,所以如果有人知道从哪里(哪个xml)会很有帮助file)创建原始导入按钮

enter image description here

python xml import openerp odoo-8
2个回答
1
投票

Here is the code for xml

 <t t-extend="ListView.buttons">
    <t t-if='widget.options.import_enabled' t-jquery="button.o_list_button_add" t-operation="after">
        <button type="button" class="btn btn-sm btn-default o_list_button_import">
            Import
        </button>
    </t>
</t>

here is code for js

 if(add_button) {
        this.$buttons.on('click', '.o_list_button_import', function() {
            self.do_action({
                type: 'ir.actions.client',
                tag: 'import',
                params: {
                    model: self.dataset.model,
                    // self.dataset.get_context() could be a compound?
                    // not sure. action's context should be evaluated
                    // so safer bet. Odd that timezone & al in it
                    // though
                    context: self.getParent().action.context,
                }
            }, {
                on_reverse_breadcrumb: function () {
                    return self.reload();
                },
            });
            return false;
        });
    }

基本上,ImportView是ODOO中用于导入数据的小部件。

onfile_loaded方法中,odoo称为Controller /base_import/set_file

    onfile_loaded: function () {
    this.$buttons.filter('.o_import_button').add(this.$('.oe_import_file_reload'))
            .prop('disabled', true);
    if (!this.$('input.oe_import_file').val()) { return; }

    this.$el.removeClass('oe_import_preview oe_import_error');
    this.$el.find('.oe_import_toggle').toggle((this.$('input.oe_import_file')[0].files[0].type == "text/csv"));
    jsonp(this.$el, {
        url: '/base_import/set_file'
    }, this.proxy('settings_changed'));
},

希望这可以帮助您理解/改变导入的工作。


0
投票

至少在Odoo V11中,您可以在XML中执行以下代码,在单击按钮后打开导入视图到特定模型:

in XML :
    <!--Action Definition-->
    <record id="action_import_employee_data" model="ir.actions.client">
        <field name="name">Employees Import</field>
        <field name="tag">import</field>
        <field name="params">{ 'model': 'hr.employee' }</field>
    </record>

    <!--Button Definition on Form View or Wizard-->
    <button name="%(action_import_employee_data)d" string="Import Employees Data" type="action"/>
© www.soinside.com 2019 - 2024. All rights reserved.