2017-07-19 93 views

回答

2

你好指針,

使用odoo 8

試試這個下面的代碼,

your_module_name /視圖/ custome_file_include.xml

<?xml version="1.0" encoding="utf-8"?> 
<openerp> 
    <data> 

     <template id="assets_backend" name="account assets" inherit_id="web.assets_backend"> 
      <xpath expr="." position="inside"> 

       <!-- Include External/Custom/Own JS File. And Order Maintain. --> 
       <script type="text/javascript" src="/your_module_name/static/src/js/custome_file_include.js"></script> 

       <script type="text/javascript" src="/your_module_name/static/src/js/custome_view_form.js"></script> 

      </xpath> 
     </template> 
    </data> 
</openerp> 

your_module_name/SRC/JS/custome_file_include.js

openerp.fm_sale_order_ext_ept = function(instance) { 
    change_tree_view_add_item_name(instance); 
} 

your_mod ule_name/src目錄/ JS/custome_view_form.js

function change_tree_view_add_item_name(instance) { 


    instance.web.form.AddAnItemList.include({ 
     pad_table_to: function (count) { 
      if (!this.view.is_action_enabled('create') || this.is_readonly()) { 
       this._super(count); 
       return; 
      } 

      this._super(count > 0 ? count - 1 : 0); 

      var self = this; 
      var columns = _(this.columns).filter(function (column) { 
       return column.invisible !== '1'; 
      }).length; 
      if (this.options.selectable) { columns++; } 
      if (this.options.deletable) { columns++; } 

      var $cell = $('<td>', { 
       colspan: columns, 
       'class': this._add_row_class || '' 
      }).html(
       $('<a>', {href: '#'}).text(_t("Add new row")) 
        .mousedown(function() { 
         // FIXME: needs to be an official API somehow 
         if (self.view.editor.is_editing()) { 
          self.view.__ignore_blur = true; 
         } 
        }) 
        .click(function (e) { 
         e.preventDefault(); 
         e.stopPropagation(); 
         // FIXME: there should also be an API for that one 
         if (self.view.editor.form.__blur_timeout) { 
          clearTimeout(self.view.editor.form.__blur_timeout); 
          self.view.editor.form.__blur_timeout = false; 
         } 
         self.view.ensure_saved().done(function() { 
          self.view.do_add_record(); 
         }); 
        })); 

      var $padding = this.$current.find('tr:not([data-id]):first'); 
      var $newrow = $('<tr>').append($cell); 
      if ($padding.length) { 
       $padding.replaceWith($newrow); 
      } else { 
       this.$current.replaceWith($newrow) 
      } 
     } 
    }); 
} 

使用odoo9

首先,我們創建新的模塊和下面給出的新模塊的文件結構。

Module_Name 
    static 
      src 
       js 
        File_Name.js 
    views 
      File_Name.xml 
    __openerp__.py 

Module_Name->則須─> File_Name.xml
現在我們在基地odoo 9模塊所以我們創建XML文件和繼承的基礎文件,並添加我們的custome JS,添加custome JS

<?xml version="1.0" encoding="utf-8"?> 
    <openerp> 
     <data> 

      <template id="assets_backend" name="account assets" inherit_id="web.assets_backend"> 
      <xpath expr="." position="inside"> 

       <!-- Include External/Custom/Own JS File. And Order Maintain. --> 
       <script type="text/javascript" src="/Module_Name/static/src/js/File_Name.js"></script> 

      </xpath> 
     </template> 
     </data> 
    </openerp> 

Module_Name-> static-> SRC-> js-> File_Name.js
現在我們繼承的基礎form_relation_widget.js js和修改該法,

odoo.define('Module_Name.File_Name', function (require) { 

    "use strict"; 

    var core = require('web.core'); 
    var ListView = require('web.ListView'); 

    var _t = core._t; 
    var _lt = core._lt; 

    // Include "web.form_relational" 
    var form_relational = require('web.form_relational'); 

    // Include X2ManyList Functionality and Modify X2ManyList Functionality 
    var form_relational = form_relational.X2ManyList.include({ 
     pad_table_to: function (count) { 
      if (!this.view.is_action_enabled('create') || this.view.x2m.get('effective_readonly')) { 
       this._super(count); 
       return; 
      } 

      this._super(count > 0 ? count - 1 : 0); 

      var self = this; 
      var columns = _(this.columns).filter(function (column) { 
       return column.invisible !== '1'; 
      }).length; 
      if (this.options.selectable) { columns++; } 
      if (this.options.deletable) { columns++; } 

      var $cell = $('<td>', { 
       colspan: columns, 
       'class': 'oe_form_field_x2many_list_row_add' 
      }).append(
       $('<a>', {href: '#'}).text(_t("Add new row")) 
        .click(function (e) { 
         e.preventDefault(); 
         e.stopPropagation(); 
         // FIXME: there should also be an API for that one 
         if (self.view.editor.form.__blur_timeout) { 
          clearTimeout(self.view.editor.form.__blur_timeout); 
          self.view.editor.form.__blur_timeout = false; 
         } 
         self.view.save_edition().done(function() { 
          self.view.do_add_record(); 
         }); 
        })); 

      var $padding = this.$current.find('tr:not([data-id]):first'); 
      var $newrow = $('<tr>').append($cell); 
      if ($padding.length) { 
       $padding.replaceWith($newrow); 
      } else { 
       this.$current.replaceWith($newrow); 
      } 
     }, 
    }); 

}); 

Module_Name->的OpenERP的.py

# -*- coding: utf-8 -*- 
# Part of Odoo. See LICENSE file for full copyright and licensing details. 

{ 
    'name': 'Module Name', 
    'version': '1.0', 
    'category': '', 
    'sequence': 1, 
    'summary': '', 
    'description': """ Give the Description of Module """, 
    'website': '', 
    'depends': ['web'], 
    'data': [ 
     'views/File_Name.xml' 
    ], 
    'demo': [], 
    'css': [], 
    'js' : [], 
    'installable': True, 
    'auto_install': False, 
    'application': True, 
} 

odoo_v9->基於web> static-> SRC-> js->則須─> form_relation_widget。 js

添加X2M anyList:X2ManyList這條線在基地JS(odoo9模塊)form_relation_widget.js

return { 
    FieldMany2ManyTags: FieldMany2ManyTags, 
    AbstractManyField: AbstractManyField, 
    X2ManyList : X2ManyList, ////Add this line in this file 
}; 

我希望我的回答是很有幫助的。 如果有任何查詢請這麼評論。

+1

Tnx求助,我複製你的代碼,但文本沒有改變! – Pointer

+0

這個模塊在odoo 8中創建。我可以正常運行這個 –

+0

好吧,我嘗試了odoo 9不適合我。 – Pointer

1

一個選項可能是您在調試模式下進入。

然後,轉到配置 - >應用條款 - >同步條款。在下拉語言中,選擇英語並等待完成。

轉到譯名,在搜索欄中寫上「添加項目」,並替換爲平移值列中的文本。

值得一提的是,這種變化將存儲在數據庫中,所有的二維關係都將受到影響。