Browse Source

Merge pull request #597 from akretion/10-mig-quick_create

[10.0] Migrate base_optional_quick_create to v10
pull/819/head
Stéphane Bidoul (ACSONE) 8 years ago
committed by GitHub
parent
commit
0830f849a1
  1. 25
      base_optional_quick_create/README.rst
  2. 2
      base_optional_quick_create/__init__.py
  3. 6
      base_optional_quick_create/__manifest__.py
  4. 2
      base_optional_quick_create/models/__init__.py
  5. 31
      base_optional_quick_create/models/ir_model.py
  6. 6
      base_optional_quick_create/views/model_view.xml

25
base_optional_quick_create/README.rst

@ -14,38 +14,26 @@ 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
* go into the menu of *ir_model*,
* select the model for which you want to disable the quick create option,
* enable the option *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
======================
:target: https://runbot.odoo-community.org/runbot/149/10.0
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**>`_.
If you spotted it first, help us smashing it by providing a detailed and welcomed
feedback.
Credits
=======
@ -55,6 +43,7 @@ Contributors
* Jonathan Nemry <jonathan.nemry@acsone.eu>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Alexis de Lattre <alexis.delattre@akretion.com>
Maintainer
----------

2
base_optional_quick_create/__init__.py

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

6
base_optional_quick_create/__manifest__.py

@ -4,7 +4,7 @@
{
'name': "Optional quick create",
'version': '9.0.1.0.0',
'version': '10.0.1.0.0',
'category': 'Tools',
'summary': "Avoid 'quick create' on m2o fields, on a 'by model' basis",
'author': "Agile Business Group,Odoo Community Association (OCA)",
@ -14,7 +14,5 @@
"data": [
'views/model_view.xml',
],
"demo": [],
'test': [],
'installable': False
'installable': True,
}

2
base_optional_quick_create/models/__init__.py

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

31
base_optional_quick_create/models/ir_model.py

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*-
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# © 2016 ACSONE SA/NA (<http://acsone.eu>)
# © 2016 Akretion (Alexis de Lattre <alexis.delattre@akretion.com>)
from openerp import api, fields, models, _
from openerp.exceptions import UserError
from openerp import SUPERUSER_ID
from odoo import api, fields, models, _
from odoo.exceptions import UserError
class IrModel(models.Model):
@ -12,35 +12,40 @@ class IrModel(models.Model):
avoid_quick_create = fields.Boolean()
def _patch_quick_create(self, cr, ids):
@api.multi
def _patch_quick_create(self):
@api.multi
def _wrap_name_create():
def wrapper(self, cr, uid, name, context=None):
def wrapper(self):
raise UserError(_("Can't create quickly. Opening create form"))
return wrapper
for model in self.browse(cr, SUPERUSER_ID, ids):
for model in self:
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 = self.env.get(model_name)
if (
not isinstance(model_obj, type(None)) 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)
def _register_hook(self):
models = self.search([])
models._patch_quick_create()
return super(IrModel, self)._register_hook()
@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])
ir_model._patch_quick_create()
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)
self._patch_quick_create()
return res

6
base_optional_quick_create/views/model_view.xml

@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<odoo>
<record id="view_model_form" model="ir.ui.view">
<field name="model">ir.model</field>
<field name="inherit_id" ref="base.view_model_form"></field>
@ -10,5 +9,4 @@
</field>
</field>
</record>
</data>
</openerp>
</odoo>
Loading…
Cancel
Save