Odoo使用binary类型来保存附件数据,可以直接支持附件数据的上传。但是在实际使用中,有可能遇到附件文件大小超过限制的情况,如下图:

但是​​ERP定制​​过程中难免会遇到客户确实需要上传超大附件,那么怎么办呢?

比较好的模块:https://github.com/JZ10UJS/extra-addons

 

 

我们需要到代码中修改相应的配置文件即可,负责定义该最大值的代码在:web/static/src/js/fields/basic_fields.js中。具体代码如下:

 

var AbstractFieldBinary = AbstractField.extend({
events: _.extend({}, AbstractField.prototype.events, {
'change .o_input_file': 'on_file_change',
'click .o_select_file_button': function () {
this.$('.o_input_file').click();
},
'click .o_clear_file_button': '_onClearClick',
}),
init: function (parent, name, record) {
this._super.apply(this, arguments);
this.fields = record.fields;
this.useFileAPI = !!window.FileReader;
this.max_upload_size = 25 * 1024 * 1024; // 25Mo
if (!this.useFileAPI) {
var self = this;
this.fileupload_id = _.uniqueId('o_fileupload');
$(window).on(this.fileupload_id, function () {
var args = [].slice.call(arguments).slice(1);
self.on_file_uploaded.apply(self, args);
});
}
},
destroy: function () {
if (this.fileupload_id) {
$(window).off(this.fileupload_id);
}
this._super.apply(this, arguments);
},

注意:该字段不建议修改,除非特殊情况,上传过大附件速度会非常慢,甚至影响整个系统的使用性能问题,大文件建议分割为多个小文件上传。

 



心有猛虎,细嗅蔷薇