Browse Source

Merge pull request #387 from acsone/9.0-mig-base_optional_quick_create-jne

[WIP] from 8.0 to 9.0 base_optional_quick_create
pull/485/head
Stefan Rijnhart (Opener) 8 years ago
committed by GitHub
parent
commit
67ae4f420b
  1. 1
      base_optional_quick_create/AUTHORS.txt
  2. 70
      base_optional_quick_create/README.rst
  3. 22
      base_optional_quick_create/__init__.py
  4. 35
      base_optional_quick_create/__openerp__.py
  5. 63
      base_optional_quick_create/model.py
  6. 5
      base_optional_quick_create/models/__init__.py
  7. 46
      base_optional_quick_create/models/ir_model.py
  8. 2
      base_optional_quick_create/views/model_view.xml
  9. 1
      setup/base_optional_quick_create/odoo_addons/__init__.py
  10. 1
      setup/base_optional_quick_create/odoo_addons/base_optional_quick_create
  11. 6
      setup/base_optional_quick_create/setup.py

1
base_optional_quick_create/AUTHORS.txt

@ -1 +0,0 @@
Lorenzo Battistini <lorenzo.battistini@agilebg.com>

70
base_optional_quick_create/README.rst

@ -0,0 +1,70 @@
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
:alt: License: AGPL-3
==========================
Base Optional Quick Create
==========================
This module allows to avoid to *quick create* new records, through many2one
fields, for a specific model.
You can configure which models should allow *quick create*.
When specified, the *quick create* option will always open the standard create
form.
Got the idea from https://twitter.com/nbessi/status/337869826028605441
Installation
============
To install this module, you need to click on install
Usage
=====
To use this module, you need to:
* go into the menu of ir_model
* select the model you want to disable the quick create option
* check the Avoid quick create
.. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot
:target: https://runbot.odoo-community.org/runbot/149/9.0
For further information, please visit:
* https://www.odoo.com/forum/help-1
Known issues / Roadmap
======================
Bug Tracker
===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_.
In case of trouble, please check there if your issue has already been reported.
If you spotted it first, help us smashing it by providing a detailed and welcomed feedback
`here <https://github.com/OCA/server-tools/issues/new?body=module:%20base_optional_quick_create%0Aversion:%209.0%0A%0A**Steps%20to%20reproduce**%0A-%20...%0A%0A**Current%20behavior**%0A%0A**Expected%20behavior**>`_.
Credits
=======
Contributors
------------
* Jonathan Nemry <jonathan.nemry@acsone.eu>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
Maintainer
----------
.. image:: https://odoo-community.org/logo.png
:alt: Odoo Community Association
:target: https://odoo-community.org
This module is maintained by the OCA.
OCA, or the Odoo Community Association, is a nonprofit organization whose mission is to support the collaborative development of Odoo features and promote its widespread use.
To contribute to this module, please visit https://odoo-community.org.

22
base_optional_quick_create/__init__.py

@ -1,21 +1,5 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.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/>.
#
##############################################################################
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# © 2016 ACSONE SA/NA (<http://acsone.eu>)
from . import model
from . import models

35
base_optional_quick_create/__openerp__.py

@ -1,45 +1,20 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.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/>.
#
##############################################################################
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# © 2016 ACSONE SA/NA (<http://acsone.eu>)
{
'name': "Optional quick create",
'version': '8.0.0.1.0',
'version': '9.0.1.0.0',
'category': 'Tools',
'summary': "Avoid 'quick create' on m2o fields, on a 'by model' basis",
'description': """
This module allows to avoid to *quick create* new records, through many2one
fields, for a specific model.
You can configure which models should allow *quick create*.
When specified, the *quick create* option will always open the standard create
form.
Got the idea from https://twitter.com/nbessi/status/337869826028605441
""",
'author': "Agile Business Group,Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com',
'license': 'AGPL-3',
"depends": ['base'],
"data": [
'model_view.xml',
'views/model_view.xml',
],
"demo": [],
'test': [],
'installable': False
'installable': True
}

63
base_optional_quick_create/model.py

@ -1,63 +0,0 @@
# -*- coding: utf-8 -*-
##############################################################################
#
# Copyright (C) 2013 Agile Business Group sagl (<http://www.agilebg.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/>.
#
##############################################################################
from openerp.osv import orm, fields
from openerp import SUPERUSER_ID
from openerp.tools.translate import _
class ir_model(orm.Model):
_inherit = 'ir.model'
_columns = {
'avoid_quick_create': fields.boolean('Avoid quick create'),
}
def _wrap_name_create(self, old_create, model):
def wrapper(cr, uid, name, context=None):
raise orm.except_orm(
_('Error'),
_("Can't create quickly. Opening create form"))
return wrapper
def _register_hook(self, cr, ids=None):
if ids is None:
ids = self.search(cr, SUPERUSER_ID, [])
for model in self.browse(cr, SUPERUSER_ID, ids):
if model.avoid_quick_create:
model_name = model.model
model_obj = self.pool.get(model_name)
if model_obj and not hasattr(model_obj, 'check_quick_create'):
model_obj.name_create = self._wrap_name_create(
model_obj.name_create, model_name)
model_obj.check_quick_create = True
return True
def create(self, cr, uid, vals, context=None):
res_id = super(ir_model, self).create(cr, uid, vals, context=context)
self._register_hook(cr, [res_id])
return res_id
def write(self, cr, uid, ids, vals, context=None):
if isinstance(ids, (int, long)):
ids = [ids]
res = super(ir_model, self).write(cr, uid, ids, vals, context=context)
self._register_hook(cr, ids)
return res

5
base_optional_quick_create/models/__init__.py

@ -0,0 +1,5 @@
# -*- coding: utf-8 -*-
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# © 2016 ACSONE SA/NA (<http://acsone.eu>)
from . import ir_model

46
base_optional_quick_create/models/ir_model.py

@ -0,0 +1,46 @@
# -*- coding: utf-8 -*-
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# © 2016 ACSONE SA/NA (<http://acsone.eu>)
from openerp import api, fields, models, _
from openerp.exceptions import UserError
from openerp import SUPERUSER_ID
class IrModel(models.Model):
_inherit = 'ir.model'
avoid_quick_create = fields.Boolean()
def _patch_quick_create(self, cr, ids):
def _wrap_name_create():
def wrapper(self, cr, uid, name, context=None):
raise UserError(_("Can't create quickly. Opening create form"))
return wrapper
for model in self.browse(cr, SUPERUSER_ID, ids):
if model.avoid_quick_create:
model_name = model.model
model_obj = self.pool.get(model_name)
if model_obj and not hasattr(model_obj, 'check_quick_create'):
model_obj._patch_method('name_create', _wrap_name_create())
model_obj.check_quick_create = True
return True
def _register_hook(self, cr):
self._patch_quick_create(cr, self.search(cr, SUPERUSER_ID, []))
return super(IrModel, self)._register_hook(cr)
@api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
ir_model = super(IrModel, self).create(vals)
self.pool[self._name]._patch_quick_create(self.env.cr, [ir_model.id])
return ir_model
@api.multi
def write(self, vals):
res = super(IrModel, self).write(vals)
self.pool[self._name]._patch_quick_create(self.env.cr, self.ids)
return res

2
base_optional_quick_create/model_view.xml → base_optional_quick_create/views/model_view.xml

@ -5,7 +5,7 @@
<field name="model">ir.model</field>
<field name="inherit_id" ref="base.view_model_form"></field>
<field name="arch" type="xml">
<field name="osv_memory" position="after">
<field name="transient" position="after">
<field name="avoid_quick_create"/>
</field>
</field>

1
setup/base_optional_quick_create/odoo_addons/__init__.py

@ -0,0 +1 @@
__import__('pkg_resources').declare_namespace(__name__)

1
setup/base_optional_quick_create/odoo_addons/base_optional_quick_create

@ -0,0 +1 @@
../../../base_optional_quick_create

6
setup/base_optional_quick_create/setup.py

@ -0,0 +1,6 @@
import setuptools
setuptools.setup(
setup_requires=['setuptools-odoo'],
odoo_addon=True,
)
Loading…
Cancel
Save