From 4c46339fbe766d6e969131ba47065544c6e4d67e Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Mon, 4 Feb 2013 21:32:51 +0100 Subject: [PATCH 1/3] [ADD] Module to allow the import of models with _inherits (workaround for lp:930318) --- web_import_models_with_inherits/__init__.py | 1 + .../__openerp__.py | 48 +++++++++++++++++++ .../model/__init__.py | 2 + .../model/basemodel.py | 31 ++++++++++++ .../static/src/js/data_import.js | 28 +++++++++++ 5 files changed, 110 insertions(+) create mode 100644 web_import_models_with_inherits/__init__.py create mode 100644 web_import_models_with_inherits/__openerp__.py create mode 100644 web_import_models_with_inherits/model/__init__.py create mode 100644 web_import_models_with_inherits/model/basemodel.py create mode 100644 web_import_models_with_inherits/static/src/js/data_import.js 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..a2e77646 --- /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/base_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..69d15ffd --- /dev/null +++ b/web_import_models_with_inherits/model/__init__.py @@ -0,0 +1,2 @@ +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..06034a88 --- /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 = openerp.web.DataImport.extend({ + /* 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); + }); + })); + }, + }); +} From 36cba0ac7f7af3229832ce2107b65e099d0a3528 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Mon, 4 Feb 2013 21:54:07 +0100 Subject: [PATCH 2/3] [FIX] Error in file name --- web_import_models_with_inherits/__openerp__.py | 2 +- web_import_models_with_inherits/model/__init__.py | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/web_import_models_with_inherits/__openerp__.py b/web_import_models_with_inherits/__openerp__.py index a2e77646..5d92ed3a 100644 --- a/web_import_models_with_inherits/__openerp__.py +++ b/web_import_models_with_inherits/__openerp__.py @@ -43,6 +43,6 @@ This bug does not affect OpenERP 7.0, in which the import function has been refactored. """, 'js': [ - 'static/src/js/base_import.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 index 69d15ffd..2a843e26 100644 --- a/web_import_models_with_inherits/model/__init__.py +++ b/web_import_models_with_inherits/model/__init__.py @@ -1,2 +1 @@ import basemodel - From f6a22d5cecdaeb76cf46406eb2896858fb6b5122 Mon Sep 17 00:00:00 2001 From: Stefan Rijnhart Date: Tue, 12 Feb 2013 09:47:46 +0100 Subject: [PATCH 3/3] [FIX] Do not use extend() when you can use include() --- web_import_models_with_inherits/static/src/js/data_import.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 index 06034a88..1a958631 100644 --- a/web_import_models_with_inherits/static/src/js/data_import.js +++ b/web_import_models_with_inherits/static/src/js/data_import.js @@ -7,7 +7,7 @@ */ openerp.web_import_models_with_inherits = function(openerp) { - openerp.web.DataImport = openerp.web.DataImport.extend({ + 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