mreficent
5 years ago
committed by
ahenriquez
7 changed files with 89 additions and 6 deletions
-
1base_kanban_stage/README.rst
-
1base_kanban_stage/__manifest__.py
-
1base_kanban_stage/models/__init__.py
-
5base_kanban_stage/models/base_kanban_stage.py
-
49base_kanban_stage/models/ir_model.py
-
8base_kanban_stage/tests/test_base_kanban_stage.py
-
30base_kanban_stage/views/ir_model_views.xml
@ -0,0 +1,49 @@ |
|||
# Copyright 2019 Eficent Business and IT Consulting Services S.L. |
|||
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
|||
|
|||
from odoo import _, api, fields, models |
|||
from odoo.exceptions import UserError |
|||
|
|||
|
|||
class IrModel(models.Model): |
|||
_inherit = 'ir.model' |
|||
|
|||
is_kanban = fields.Boolean( |
|||
string="Kanban", default=False, |
|||
help="Whether this model support kanban stages.", |
|||
) |
|||
|
|||
@api.multi |
|||
def write(self, vals): |
|||
if self and 'is_kanban' in vals: |
|||
if not all(rec.state == 'manual' for rec in self): |
|||
raise UserError(_('Only custom models can be modified.')) |
|||
if not all(rec.is_kanban <= vals['is_kanban'] for rec in self): |
|||
raise UserError( |
|||
_('Field "Kanban" cannot be changed to "False".')) |
|||
res = super(IrModel, self).write(vals) |
|||
# setup models; this reloads custom models in registry |
|||
self.pool.setup_models(self._cr) |
|||
# update database schema of models |
|||
models = self.pool.descendants(self.mapped('model'), '_inherits') |
|||
self.pool.init_models(self._cr, models, dict( |
|||
self._context, update_custom_fields=True)) |
|||
else: |
|||
res = super(IrModel, self).write(vals) |
|||
return res |
|||
|
|||
def _reflect_model_params(self, model): |
|||
vals = super(IrModel, self)._reflect_model_params(model) |
|||
vals['is_kanban'] = issubclass( |
|||
type(model), self.pool['base.kanban.abstract']) |
|||
return vals |
|||
|
|||
@api.model |
|||
def _instanciate(self, model_data): |
|||
model_class = super(IrModel, self)._instanciate(model_data) |
|||
if model_data.get('is_kanban') and \ |
|||
model_class._name != 'base.kanban.abstract': |
|||
parents = model_class._inherit or [] |
|||
parents = [parents] if isinstance(parents, (str,)) else parents |
|||
model_class._inherit = parents + ['base.kanban.abstract'] |
|||
return model_class |
@ -0,0 +1,30 @@ |
|||
<?xml version="1.0" encoding="utf-8"?> |
|||
|
|||
<!-- |
|||
Copyright 2019 Eficent Business and IT Consulting Services S.L. |
|||
License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). |
|||
--> |
|||
|
|||
<odoo> |
|||
|
|||
<record id="model_form_view" model="ir.ui.view"> |
|||
<field name="model">ir.model</field> |
|||
<field name="inherit_id" ref="base.view_model_form"/> |
|||
<field name="arch" type="xml"> |
|||
<field name="transient" position="after"> |
|||
<field name="is_kanban" attrs="{'readonly': [('state','!=', 'manual')]}" groups="base.group_no_one"/> |
|||
</field> |
|||
</field> |
|||
</record> |
|||
|
|||
<record id="model_search_view" model="ir.ui.view"> |
|||
<field name="model">ir.model</field> |
|||
<field name="inherit_id" ref="base.view_model_search"/> |
|||
<field name="arch" type="xml"> |
|||
<filter name="base" position="after"> |
|||
<filter string="Kanban" name="is_kanban" domain="[('is_kanban', '=', True)]"/> |
|||
</filter> |
|||
</field> |
|||
</record> |
|||
|
|||
</odoo> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue