diff --git a/web_import_models_with_inherits/__init__.py b/web_import_models_with_inherits/__init__.py new file mode 100644 index 00000000..16e8b082 --- /dev/null +++ b/web_import_models_with_inherits/__init__.py @@ -0,0 +1 @@ +import model diff --git a/web_import_models_with_inherits/__openerp__.py b/web_import_models_with_inherits/__openerp__.py new file mode 100644 index 00000000..5d92ed3a --- /dev/null +++ b/web_import_models_with_inherits/__openerp__.py @@ -0,0 +1,48 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## + +{ + "name": "Web: allow import of models with '_inherits'", + "version": "1.0r1", + "author": "Therp BV", + "category": "Tools", + "depends": ['web'], + "description": """ +When a model has its '_inherits' defined, the associated fields are always +set to 'required'. These models cannot be imported in the web client 6.1 +because the web client insists that these fields be present in the import +file. See https://bugs.launchpad.net/bugs/930318. + +This module makes the web client query the content of a model's +'_inherits' so that it can exclude them from the required fields at import +time. + +Due to the applied method of 'monkey patching', the installation of this +module on one database will affect all databases on the same OpenERP +installation. + +This bug does not affect OpenERP 7.0, in which the import function has +been refactored. + """, + 'js': [ + 'static/src/js/data_import.js', + ], +} diff --git a/web_import_models_with_inherits/model/__init__.py b/web_import_models_with_inherits/model/__init__.py new file mode 100644 index 00000000..2a843e26 --- /dev/null +++ b/web_import_models_with_inherits/model/__init__.py @@ -0,0 +1 @@ +import basemodel diff --git a/web_import_models_with_inherits/model/basemodel.py b/web_import_models_with_inherits/model/basemodel.py new file mode 100644 index 00000000..07ab0522 --- /dev/null +++ b/web_import_models_with_inherits/model/basemodel.py @@ -0,0 +1,31 @@ +# -*- coding: utf-8 -*- +############################################################################## +# +# OpenERP, Open Source Management Solution +# This module copyright (C) 2013 Therp BV (). +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Affero General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with this program. If not, see . +# +############################################################################## +from openerp.osv.orm import BaseModel + +def get_fields_inherits(self, cr, uid, context=None): + """ + Pass the values of the _inherits dictionary + """ + if not self._inherits: + return [] + return self._inherits.values() + +BaseModel.get_fields_inherits = get_fields_inherits diff --git a/web_import_models_with_inherits/static/src/js/data_import.js b/web_import_models_with_inherits/static/src/js/data_import.js new file mode 100644 index 00000000..1a958631 --- /dev/null +++ b/web_import_models_with_inherits/static/src/js/data_import.js @@ -0,0 +1,28 @@ +/* + + Copyright (C) 2013 Therp BV + License: GNU AFFERO GENERAL PUBLIC LICENSE + Version 3 or any later version + + */ + +openerp.web_import_models_with_inherits = function(openerp) { + openerp.web.DataImport.include({ + /* At widget start, tag on to the 'ready' queue with a function to + add the model's _inherits fields to the list that contains all + fields that need not be provided by the import file even if they + have the 'required' attribute + */ + start: function() { + var self = this; + this._super(); + this.ready.push(new openerp.web.DataSet( + this, this.model, this.context).call( + 'get_fields_inherits', [], function(fields) { + _.each(fields, function(val) { + self.fields_with_defaults.push(val); + }); + })); + }, + }); +}