Browse Source

[ADD] Module to allow the import of models with _inherits

(workaround for lp:930318)
pull/2/head
Stefan Rijnhart 12 years ago
parent
commit
4c46339fbe
  1. 1
      web_import_models_with_inherits/__init__.py
  2. 48
      web_import_models_with_inherits/__openerp__.py
  3. 2
      web_import_models_with_inherits/model/__init__.py
  4. 31
      web_import_models_with_inherits/model/basemodel.py
  5. 28
      web_import_models_with_inherits/static/src/js/data_import.js

1
web_import_models_with_inherits/__init__.py

@ -0,0 +1 @@
import model

48
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 (<http://therp.nl>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
{
"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',
],
}

2
web_import_models_with_inherits/model/__init__.py

@ -0,0 +1,2 @@
import basemodel

31
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 (<http://therp.nl>).
#
# 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 <http://www.gnu.org/licenses/>.
#
##############################################################################
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

28
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);
});
}));
},
});
}
Loading…
Cancel
Save