-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[8.0] Add base_model_metaclass_mixin #273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
305bbf0
0f5a54f
1d9bf4a
3a0e412
d1e6e6e
b7e4708
150cb0b
4f75726
6a25aa0
e4c6cc6
25f1f30
ddd6797
6fef735
3cc887d
52d39ba
0c64590
c32aab4
bc5fc04
4366f7a
64170ba
caaf1e1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| 0.2 | ||
| === | ||
|
|
||
| * Transformed into a OpenERP module. | ||
|
|
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from 0.2 to 0.4 | ||
|
|
||
| * Prepare module for odoo8. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| ### README ### | ||
|
|
||
|
|
||
| ### Oemetaslfor Odoo/OpenERP ### | ||
|
|
||
|
|
||
| This module handles methods and MetaClass to modify OpenERP base methods. | ||
| For Exemple, we override copy method to restrict the copy in Odoo/OpenERP. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. exAmple |
||
| But you can implement the method you need. | ||
|
|
||
|
|
||
|
|
||
| How to | ||
| ====== | ||
| :: | ||
|
|
||
| # In an Openerp Module: | ||
| from base_model_metaclass_mixin import BaseModelMetaclassMixin | ||
|
|
||
|
|
||
| class oetest(osv.Model): | ||
| __metaclass__ = BaseModelMetaclassMixin | ||
|
|
||
| # Functions defined in BaseModelMetaclassMixin will be automatically added if they are not | ||
| # implemented in the osv.Model class | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| from openerp.osv import orm | ||
| from openerp.osv import osv | ||
| from openerp.tools.translate import _ | ||
|
|
||
| __all__ = ['BaseModelMetaclassMixin'] | ||
|
|
||
|
|
||
| def get_overrides(): | ||
| overrides = {} | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this will be global for all databases running on the server. Shouldn't this be per database (as in: Set up the data structure in |
||
|
|
||
| def add_override(func): | ||
| overrides[func.func_name] = func | ||
|
|
||
| @add_override | ||
| def copy(cls, cr, uid, rec_id, default=None, context=None): | ||
| # Raise by default. This method should be implemented to work. | ||
|
|
||
| raise osv.except_osv( | ||
| _(u"Warning"), | ||
| _(u"Copy is not supported for this item.") | ||
| ) | ||
|
|
||
| for func_name, func in overrides.iteritems(): | ||
| yield func_name, func | ||
|
|
||
|
|
||
| class BaseModelMetaclassMixin(orm.MetaModel): | ||
| def __init__(cls, name, bases, nmspc): | ||
| super(BaseModelMetaclassMixin, cls).__init__(name, bases, nmspc) | ||
|
|
||
| for func_name, func in get_overrides(): | ||
| if func_name not in nmspc: | ||
| setattr(cls, func_name, func) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| # -*- coding: utf-8 -*- | ||
| ############################################################################## | ||
| # | ||
| # BaseModelMetaclassMixin, for OpenERP | ||
| # Copyright (C) 2013 XCG Consulting (http://odoo.consulting) | ||
| # | ||
| # 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/>. | ||
| # | ||
| # Author: Anael LORIMIER <anael.lorimier@xcg-consulting.fr> | ||
| # Vincent Lhote-Hatakeyama <vincent.lhote@xcg-consulting.fr> | ||
| # | ||
| ############################################################################## | ||
|
|
||
| { | ||
| 'name': "BaseModelMetaclassMixin", | ||
| 'version': '0.5', | ||
| 'author': "XCG Consulting", | ||
| 'category': "Custom Module", | ||
| 'description': """This module handles methods to modify OpenERP base | ||
| methods. | ||
| """, | ||
| 'website': "http://www.openerp-experts.com/", | ||
| 'depends': [ | ||
| 'base', | ||
| ], | ||
| 'installable': True, | ||
| 'active': False, | ||
| } | ||
| # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| # Translation of OpenERP Server. | ||
| # This file contains the translation of the following modules: | ||
| # * base_model_metaclass_mixin | ||
| # Vincent Lhote-Hatakeyama <vincent.lhote@xcg-consulting.fr>, 2014. | ||
| msgid "" | ||
| msgstr "" | ||
| "Project-Id-Version: OpenERP Server 7.0\n" | ||
| "Report-Msgid-Bugs-To: \n" | ||
| "POT-Creation-Date: 2014-04-28 09:13+0000\n" | ||
| "PO-Revision-Date: 2014-04-28 11:30+0200\n" | ||
| "Last-Translator: Vincent Lhote-Hatakeyama <vincent.lhote@xcg-consulting.fr>\n" | ||
| "Language-Team: XCG Consulting\n" | ||
| "Language: fr\n" | ||
| "MIME-Version: 1.0\n" | ||
| "Content-Type: text/plain; charset=UTF-8\n" | ||
| "Content-Transfer-Encoding: \n" | ||
| "Plural-Forms: nplurals=2; plural=(n > 1);\n" | ||
| "X-Generator: Virtaal 0.7.1\n" | ||
|
|
||
| #. module: base_model_metaclass_mixin | ||
| #: code:addons/base_model_metaclass_mixin/__init__.py:18 | ||
| #, python-format | ||
| msgid "Warning" | ||
| msgstr "Avertissement" | ||
|
|
||
| #. module: base_model_metaclass_mixin | ||
| #: code:addons/base_model_metaclass_mixin/__init__.py:19 | ||
| #, python-format | ||
| msgid "Copy is not supported for this item." | ||
| msgstr "La duplication n’est pas possible pour cet objet." |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use OCA's readme template here