Browse Source

[WIP] from 8.0 to 9.0 base_optional_quick_create

* bump version to 9.0.1.0.0 and make it installable
* apply a views/models directory arch into the module
* fix xpath anchor on ir_model views (osv_memory to transient)
* add README.rst
* apply some new api
pull/387/head
Jonathan Nemry (ACSONE) 9 years ago
committed by Stéphane Bidoul
parent
commit
9cc4b2fe04
  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. 44
      base_optional_quick_create/models/ir_model.py
  8. 2
      base_optional_quick_create/views/model_view.xml

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 -*- # -*- 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 -*- # -*- 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", 'name': "Optional quick create",
'version': '8.0.0.1.0',
'version': '9.0.1.0.0',
'category': 'Tools', 'category': 'Tools',
'summary': "Avoid 'quick create' on m2o fields, on a 'by model' basis", '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)", 'author': "Agile Business Group,Odoo Community Association (OCA)",
'website': 'http://www.agilebg.com', 'website': 'http://www.agilebg.com',
'license': 'AGPL-3', 'license': 'AGPL-3',
"depends": ['base'], "depends": ['base'],
"data": [ "data": [
'model_view.xml',
'views/model_view.xml',
], ],
"demo": [], "demo": [],
'test': [], '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

44
base_optional_quick_create/models/ir_model.py

@ -0,0 +1,44 @@
# -*- 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 Warning
from openerp import SUPERUSER_ID
from openerp.tools.translate import _
class IrModel(models.Model):
_inherit = 'ir.model'
avoid_quick_create = fields.Boolean()
def _wrap_name_create(self, old_create, model):
def wrapper(cr, uid, name, context=None):
raise Warning(_("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
@api.model
@api.returns('self', lambda value: value.id)
def create(self, vals):
ir_model = super(IrModel, self).create(vals)
self._register_hook(self.env.cr, [ir_model.id])
return ir_model
@api.multi
def write(self, vals):
res = super(IrModel, self).write(vals)
self._register_hook(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="model">ir.model</field>
<field name="inherit_id" ref="base.view_model_form"></field> <field name="inherit_id" ref="base.view_model_form"></field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<field name="osv_memory" position="after">
<field name="transient" position="after">
<field name="avoid_quick_create"/> <field name="avoid_quick_create"/>
</field> </field>
</field> </field>
Loading…
Cancel
Save