Browse Source
[IMP] base_export_manager: Several things:
[IMP] base_export_manager: Several things:
* Improve UX for base_export_manager. - Improve user instructions in README. - Require some required fields. - Allow to select models from a list. - Allow to select up to 3 fields from dynamic lists. - Improve translations. - More tests. - Translate column labels. Some methods have been renamed, so version tag is raised to 8.0.2.0.0. * Make inverse method be called at view time. * Hardcode constraints in the `create` method instead of using normal ones. Depending on the context where the record is created, it gets `resource` or `model_id`. The problem is that Odoo checks constrains before inverses, so constrains would fail always. Test added to ensure future versions contemplate all use cases. * Allow to reorder fields.pull/22/head
Jairo Llopis
9 years ago
committed by
Pedro M. Baeza
14 changed files with 428 additions and 221 deletions
-
56base_export_manager/README.rst
-
24base_export_manager/__init__.py
-
33base_export_manager/__openerp__.py
-
8base_export_manager/data/ir_exports_data.xml
-
50base_export_manager/i18n/base_exports_manager.pot
-
41base_export_manager/i18n/es.po
-
26base_export_manager/models/__init__.py
-
67base_export_manager/models/ir_exports.py
-
211base_export_manager/models/ir_exports_line.py
-
26base_export_manager/static/src/js/main.js
-
7base_export_manager/tests/__init__.py
-
54base_export_manager/tests/test_ir_exports.py
-
6base_export_manager/tests/test_ir_exports_line.py
-
38base_export_manager/views/ir_exports_view.xml
@ -1,25 +1,5 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# Python source code encoding : https://www.python.org/dev/peps/pep-0263/ |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright : |
|
||||
# (c) 2015 Antiun Ingenieria, SL (Madrid, Spain, http://www.antiun.com) |
|
||||
# Antonio Espinosa <antonioea@antiun.com> |
|
||||
# |
|
||||
# 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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from . import models |
from . import models |
@ -1,40 +1,25 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# Python source code encoding : https://www.python.org/dev/peps/pep-0263/ |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Odoo Source Management Solution |
|
||||
# Copyright (c) 2015 Antiun Ingeniería S.L. (http://www.antiun.com) |
|
||||
# Antonio Espinosa <antonioea@antiun.com> |
|
||||
# |
|
||||
# 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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
{ |
{ |
||||
'name': "Manages model export profiles", |
|
||||
|
'name': "Manage model export profiles", |
||||
'category': 'Personalization', |
'category': 'Personalization', |
||||
'version': '8.0.1.0.0', |
|
||||
|
'version': '8.0.2.0.0', |
||||
'depends': [ |
'depends': [ |
||||
'web', |
'web', |
||||
], |
], |
||||
'data': [ |
'data': [ |
||||
|
'data/ir_exports_data.xml', |
||||
'views/assets.xml', |
'views/assets.xml', |
||||
'views/ir_exports_view.xml', |
'views/ir_exports_view.xml', |
||||
], |
], |
||||
'qweb': [ |
'qweb': [ |
||||
"static/src/xml/base.xml", |
"static/src/xml/base.xml", |
||||
], |
], |
||||
'author': 'Antiun Ingeniería S.L.,Odoo Community Association (OCA)', |
|
||||
|
'author': 'Antiun Ingeniería S.L., ' |
||||
|
'Tecnativa, ' |
||||
|
'Odoo Community Association (OCA)', |
||||
'website': 'http://www.antiun.com', |
'website': 'http://www.antiun.com', |
||||
'license': 'AGPL-3', |
'license': 'AGPL-3', |
||||
'installable': True, |
'installable': True, |
||||
|
@ -0,0 +1,8 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
|
||||
|
<function model="ir.exports.line" name="_install_base_export_manager"/> |
||||
|
|
||||
|
</data> |
||||
|
</openerp> |
@ -1,50 +0,0 @@ |
|||||
# Translation of Odoo Server. |
|
||||
# This file contains the translation of the following modules: |
|
||||
# * base_exports_manager |
|
||||
# |
|
||||
msgid "" |
|
||||
msgstr "" |
|
||||
"Project-Id-Version: Odoo Server 8.0\n" |
|
||||
"Report-Msgid-Bugs-To: \n" |
|
||||
"POT-Creation-Date: 2015-10-27 12:38+0000\n" |
|
||||
"PO-Revision-Date: 2015-10-27 12:38+0000\n" |
|
||||
"Last-Translator: <>\n" |
|
||||
"Language-Team: \n" |
|
||||
"MIME-Version: 1.0\n" |
|
||||
"Content-Type: text/plain; charset=UTF-8\n" |
|
||||
"Content-Transfer-Encoding: \n" |
|
||||
"Plural-Forms: \n" |
|
||||
|
|
||||
#. module: base_exports_manager |
|
||||
#: view:ir.exports:base_exports_manager.ir_exports_form_view |
|
||||
msgid "Export Profile" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: base_exports_manager |
|
||||
#: model:ir.actions.act_window,name:base_exports_manager.ir_exports_action |
|
||||
#: view:ir.exports:base_exports_manager.ir_exports_tree_view |
|
||||
#: model:ir.ui.menu,name:base_exports_manager.ir_exports_menu |
|
||||
msgid "Export Profiles" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: base_exports_manager |
|
||||
#: code:addons/base_exports_manager/models/ir_exports_line.py:62 |
|
||||
#, python-format |
|
||||
msgid "Field '%s' already exists" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: base_exports_manager |
|
||||
#: code:addons/base_exports_manager/models/ir_exports_line.py:57 |
|
||||
#, python-format |
|
||||
msgid "Field '%s' does not exist" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: base_exports_manager |
|
||||
#: field:ir.exports.line,sequence:0 |
|
||||
msgid "Sequence" |
|
||||
msgstr "" |
|
||||
|
|
||||
#. module: base_exports_manager |
|
||||
#: field:ir.exports.line,label:0 |
|
||||
msgid "Label" |
|
||||
msgstr "" |
|
@ -1,25 +1,5 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# Python source code encoding : https://www.python.org/dev/peps/pep-0263/ |
|
||||
############################################################################## |
|
||||
# |
|
||||
# OpenERP, Open Source Management Solution |
|
||||
# This module copyright : |
|
||||
# (c) 2015 Antiun Ingenieria, SL (Madrid, Spain, http://www.antiun.com) |
|
||||
# Antonio Espinosa <antonioea@antiun.com> |
|
||||
# |
|
||||
# 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/>. |
|
||||
# |
|
||||
############################################################################## |
|
||||
|
# © 2015 Antiun Ingeniería S.L. - Antonio Espinosa |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from . import ir_exports_line |
|
||||
|
from . import ir_exports, ir_exports_line |
@ -0,0 +1,67 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# Copyright 2015-2016 Jairo Llopis <jairo.llopis@tecnativa.com> |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from openerp import _, api, fields, models |
||||
|
from openerp.exceptions import ValidationError |
||||
|
|
||||
|
|
||||
|
class IrExports(models.Model): |
||||
|
_inherit = 'ir.exports' |
||||
|
|
||||
|
name = fields.Char(required=True) |
||||
|
resource = fields.Char( |
||||
|
required=False, |
||||
|
readonly=True, |
||||
|
help="Model's technical name.") |
||||
|
model_id = fields.Many2one( |
||||
|
"ir.model", |
||||
|
"Model", |
||||
|
store=True, |
||||
|
domain=[("osv_memory", "=", False)], |
||||
|
compute="_compute_model_id", |
||||
|
inverse="_inverse_model_id", |
||||
|
help="Database model to export.") |
||||
|
|
||||
|
@api.multi |
||||
|
@api.depends("resource") |
||||
|
def _compute_model_id(self): |
||||
|
"""Get the model from the resource.""" |
||||
|
for s in self: |
||||
|
s.model_id = self._get_model_id(s.resource) |
||||
|
|
||||
|
@api.multi |
||||
|
@api.onchange("model_id") |
||||
|
def _inverse_model_id(self): |
||||
|
"""Get the resource from the model.""" |
||||
|
for s in self: |
||||
|
s.resource = s.model_id.model |
||||
|
|
||||
|
@api.multi |
||||
|
@api.onchange("resource") |
||||
|
def _onchange_resource(self): |
||||
|
"""Void fields if model is changed in a view.""" |
||||
|
for s in self: |
||||
|
s.export_fields = False |
||||
|
|
||||
|
@api.model |
||||
|
def _get_model_id(self, resource): |
||||
|
"""Return a model object from its technical name. |
||||
|
|
||||
|
:param str resource: |
||||
|
Technical name of the model, like ``ir.model``. |
||||
|
""" |
||||
|
return self.env["ir.model"].search([("model", "=", resource)]) |
||||
|
|
||||
|
@api.model |
||||
|
def create(self, vals): |
||||
|
"""Check required values when creating the record. |
||||
|
|
||||
|
Odoo's export dialog populates ``resource``, while this module's new |
||||
|
form populates ``model_id``. At least one of them is required to |
||||
|
trigger the methods that fill up the other, so this should fail if |
||||
|
one is missing. |
||||
|
""" |
||||
|
if not any(f in vals for f in {"model_id", "resource"}): |
||||
|
raise ValidationError(_("You must supply a model or resource.")) |
||||
|
return super(IrExports, self).create(vals) |
@ -1,5 +1,6 @@ |
|||||
# -*- coding: utf-8 -*- |
# -*- coding: utf-8 -*- |
||||
# License AGPL-3: Antiun Ingenieria S.L. - Javier Iniesta |
|
||||
# See README.rst file on addon root folder for more details |
|
||||
|
# © 2015 Antiun Ingeniería S.L. - Javier Iniesta |
||||
|
# © 2015 Antiun Ingeniería S.L. - Jairo Llopis |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
from . import test_ir_exports_line |
|
||||
|
from . import test_ir_exports, test_ir_exports_line |
@ -0,0 +1,54 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © 2015 Antiun Ingeniería S.L. - Jairo Llopis |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl.html). |
||||
|
|
||||
|
from openerp.exceptions import ValidationError |
||||
|
from openerp.tests.common import TransactionCase |
||||
|
|
||||
|
|
||||
|
class TestIrExportsCase(TransactionCase): |
||||
|
def test_create_with_basic_data(self): |
||||
|
"""Emulate creation from original form. |
||||
|
|
||||
|
This form is handled entirely client-side, and lacks some required |
||||
|
field values. |
||||
|
""" |
||||
|
# Emulate creation from JsonRpc, without model_id and field#_id |
||||
|
data = { |
||||
|
"name": u"Test éxport", |
||||
|
"resource": "ir.exports", |
||||
|
"export_fields": [ |
||||
|
[0, 0, {"name": "export_fields"}], |
||||
|
[0, 0, {"name": "export_fields/create_uid"}], |
||||
|
[0, 0, {"name": "export_fields/create_date"}], |
||||
|
[0, 0, {"name": "export_fields/field1_id"}], |
||||
|
], |
||||
|
} |
||||
|
record = self.env["ir.exports"].create(data) |
||||
|
|
||||
|
self.assertEqual(record.model_id.model, data["resource"]) |
||||
|
|
||||
|
def test_create_without_model(self): |
||||
|
"""Creating a record without ``model_id`` and ``resource`` fails.""" |
||||
|
IrExports = self.env["ir.exports"] |
||||
|
model = IrExports._get_model_id("res.partner") |
||||
|
|
||||
|
# Creating with resource |
||||
|
record = IrExports.create({ |
||||
|
"name": "some", |
||||
|
"resource": model.model, |
||||
|
}) |
||||
|
self.assertEqual(record.model_id, model) |
||||
|
|
||||
|
# Creating with model_id |
||||
|
record = IrExports.create({ |
||||
|
"name": "some", |
||||
|
"model_id": model.id, |
||||
|
}) |
||||
|
self.assertEqual(record.resource, model.model) |
||||
|
|
||||
|
# Creating without anyone |
||||
|
with self.assertRaises(ValidationError): |
||||
|
IrExports.create({ |
||||
|
"name": "some", |
||||
|
}) |
Write
Preview
Loading…
Cancel
Save
Reference in new issue