2016-04-26 74 views
0

新的导入按钮,我有两个类:建立在我的Python代码odoo

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

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

我想创建在object.one的表单视图定制的导入按钮为了导入object.two的数据,我试图在base_import模块的文件中搜索,但是徒劳,所以如果有人知道从哪里(哪个xml文件)创建原始导入按钮将会有帮助

enter image description here

回答

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')); 
}, 

希望这可以帮助你理解改变进口工作。