Browse Source

Migrate base_optional_quick_create to Odoo 10

pull/14/head
Alexis de Lattre 8 years ago
committed by Pedro M. Baeza
parent
commit
210d8e2d41
  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. 29
      base_optional_quick_create/models/ir_model.py
  6. 22
      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 Got the idea from https://twitter.com/nbessi/status/337869826028605441
Installation
============
To install this module, you need to click on install
Usage Usage
===== =====
To use this module, you need to: 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 .. image:: https://odoo-community.org/website/image/ir.attachment/5784_f2813bd/datas
:alt: Try me on Runbot :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 Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/server-tools/issues>`_. 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. 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 Credits
======= =======
@ -55,6 +43,7 @@ Contributors
* Jonathan Nemry <jonathan.nemry@acsone.eu> * Jonathan Nemry <jonathan.nemry@acsone.eu>
* Lorenzo Battistini <lorenzo.battistini@agilebg.com> * Lorenzo Battistini <lorenzo.battistini@agilebg.com>
* Alexis de Lattre <alexis.delattre@akretion.com>
Maintainer Maintainer
---------- ----------

2
base_optional_quick_create/__init__.py

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

6
base_optional_quick_create/__openerp__.py → base_optional_quick_create/__manifest__.py

@ -4,7 +4,7 @@
{ {
'name': "Optional quick create", 'name': "Optional quick create",
'version': '9.0.1.0.0',
'version': '10.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",
'author': "Agile Business Group,Odoo Community Association (OCA)", 'author': "Agile Business Group,Odoo Community Association (OCA)",
@ -14,7 +14,5 @@
"data": [ "data": [
'views/model_view.xml', 'views/model_view.xml',
], ],
"demo": [],
'test': [],
'installable': True
'installable': True,
} }

2
base_optional_quick_create/models/__init__.py

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

29
base_optional_quick_create/models/ir_model.py

@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# © 2013 Agile Business Group sagl (<http://www.agilebg.com>) # © 2013 Agile Business Group sagl (<http://www.agilebg.com>)
# © 2016 ACSONE SA/NA (<http://acsone.eu>) # © 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): class IrModel(models.Model):
@ -12,35 +12,38 @@ class IrModel(models.Model):
avoid_quick_create = fields.Boolean() 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 _wrap_name_create():
def wrapper(self, cr, uid, name, context=None):
def wrapper(self):
raise UserError(_("Can't create quickly. Opening create form")) raise UserError(_("Can't create quickly. Opening create form"))
return wrapper return wrapper
for model in self.browse(cr, SUPERUSER_ID, ids):
for model in self:
if model.avoid_quick_create: if model.avoid_quick_create:
model_name = model.model 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 model_name and not hasattr(model_obj, 'check_quick_create'):
model_obj._patch_method('name_create', _wrap_name_create()) model_obj._patch_method('name_create', _wrap_name_create())
model_obj.check_quick_create = True model_obj.check_quick_create = True
return 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.model
@api.returns('self', lambda value: value.id) @api.returns('self', lambda value: value.id)
def create(self, vals): def create(self, vals):
ir_model = super(IrModel, self).create(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 return ir_model
@api.multi @api.multi
def write(self, vals): def write(self, vals):
res = super(IrModel, self).write(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 return res

22
base_optional_quick_create/views/model_view.xml

@ -1,14 +1,12 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<openerp>
<data>
<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>
<field name="arch" type="xml">
<field name="transient" position="after">
<field name="avoid_quick_create"/>
</field>
<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>
<field name="arch" type="xml">
<field name="transient" position="after">
<field name="avoid_quick_create"/>
</field> </field>
</record>
</data>
</openerp>
</field>
</record>
</odoo>
Loading…
Cancel
Save