Browse Source

[ADD] base_kanban_stage: Stage model and abstract logic

* Add Kanban-compatible stage model base.kanban.stage
* Add views, menu items, actions, and access controls needed to manage base.kanban.stage records
* Add abstract model base.kanban.abstract that other models can inherit from to gain Kanban stage functionality
* Add base Kanban view base_kanban_abstract_view_kanban, which can be customized as needed for use with models that inherit from base.kanban.abstract
* Add model base.kanban.abstract.tester, which is needed for base.kanban.abstract unit tests
pull/679/head
Ted Salmon 8 years ago
committed by Dave Lasley
parent
commit
b7bb5c734b
  1. 16
      base_kanban_stage/README.rst
  2. 0
      base_kanban_stage/__init__.py
  3. 6
      base_kanban_stage/__openerp__.py
  4. 4
      base_kanban_stage/models/__init__.py
  5. 8
      base_kanban_stage/models/base_kanban_abstract.py
  6. 4
      base_kanban_stage/models/base_kanban_stage.py
  7. 3
      base_kanban_stage/security/ir.model.access.csv
  8. 0
      base_kanban_stage/static/description/icon.png
  9. 4
      base_kanban_stage/tests/__init__.py
  10. 24
      base_kanban_stage/tests/test_base_kanban_abstract.py
  11. 16
      base_kanban_stage/tests/test_base_kanban_stage.py
  12. 4
      base_kanban_stage/views/base_kanban_abstract.xml
  13. 23
      base_kanban_stage/views/base_kanban_stage.xml
  14. 3
      web_kanban_stage/security/ir.model.access.csv

16
web_kanban_stage/README.rst → base_kanban_stage/README.rst

@ -8,7 +8,7 @@ Kanban - Stage Support
This module provides a stage model compatible with Kanban views and the This module provides a stage model compatible with Kanban views and the
standard views needed to manage these stages. It also provides the standard views needed to manage these stages. It also provides the
``web.kanban.abstract`` model, which can be inherited to add support for
``base.kanban.abstract`` model, which can be inherited to add support for
Kanban views with stages to any other model. Lastly, it includes a base Kanban Kanban views with stages to any other model. Lastly, it includes a base Kanban
view that can be extended as needed. view that can be extended as needed.
@ -25,16 +25,16 @@ No configuration is needed or possible.
Usage Usage
===== =====
* Inherit from ``web.kanban.abstract`` to add Kanban stage functionality to
* Inherit from ``base.kanban.abstract`` to add Kanban stage functionality to
the child model: the child model:
.. code-block:: python .. code-block:: python
class MyModel(models.Model): class MyModel(models.Model):
_name = 'my.model' _name = 'my.model'
_inherit = 'web.kanban.abstract'
_inherit = 'base.kanban.abstract'
* Extend the provided base Kanban view (``web_kanban_abstract_view_kanban``)
* Extend the provided base Kanban view (``base_kanban_abstract_view_kanban``)
as needed by the child model. The base view has four ``name`` attributes as needed by the child model. The base view has four ``name`` attributes
intended to provide convenient XPath access to different parts of the Kanban intended to provide convenient XPath access to different parts of the Kanban
card. They are ``card_dropdown_menu``, ``card_header``, ``card_body``, and card. They are ``card_dropdown_menu``, ``card_header``, ``card_body``, and
@ -45,7 +45,7 @@ Usage
<record id="my_model_view_kanban" model="ir.ui.view"> <record id="my_model_view_kanban" model="ir.ui.view">
<field name="name">My Model - Kanban View</field> <field name="name">My Model - Kanban View</field>
<field name="model">my.model</field> <field name="model">my.model</field>
<field name="inherit_id" ref="web_kanban_stage.web_kanban_abstract_view_kanban"/>
<field name="inherit_id" ref="base_kanban_stage.base_kanban_abstract_view_kanban"/>
<field name="arch" type="xml"> <field name="arch" type="xml">
<xpath expr="//div[@name='card_header']"> <xpath expr="//div[@name='card_header']">
<!-- Add header content here --> <!-- Add header content here -->
@ -65,14 +65,14 @@ Usage
Known Issues / Roadmap Known Issues / Roadmap
====================== ======================
* The grouping logic used by ``web.kanban.abstract`` currently does not
* The grouping logic used by ``base.kanban.abstract`` currently does not
support additional domains and alternate sort orders support additional domains and alternate sort orders
Bug Tracker Bug Tracker
=========== ===========
Bugs are tracked on `GitHub Issues <https://github.com/OCA/web/issues>`_. In
case of trouble, please check there if your issue has already been reported.
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 smash it by providing detailed and welcomed If you spotted it first, help us smash it by providing detailed and welcomed
feedback. feedback.

0
web_kanban_stage/__init__.py → base_kanban_stage/__init__.py

6
web_kanban_stage/__openerp__.py → base_kanban_stage/__openerp__.py

@ -7,7 +7,7 @@
'summary': 'Provides stage model and abstract logic for inheritance', 'summary': 'Provides stage model and abstract logic for inheritance',
'version': '9.0.1.0.0', 'version': '9.0.1.0.0',
'author': "LasLabs, Odoo Community Association (OCA)", 'author': "LasLabs, Odoo Community Association (OCA)",
'category': 'Web',
'category': 'base',
'depends': [ 'depends': [
'web_kanban', 'web_kanban',
], ],
@ -15,8 +15,8 @@
'license': 'LGPL-3', 'license': 'LGPL-3',
'data': [ 'data': [
'security/ir.model.access.csv', 'security/ir.model.access.csv',
'views/web_kanban_abstract.xml',
'views/web_kanban_stage.xml',
'views/base_kanban_abstract.xml',
'views/base_kanban_stage.xml',
], ],
'installable': True, 'installable': True,
'application': False, 'application': False,

4
web_kanban_stage/models/__init__.py → base_kanban_stage/models/__init__.py

@ -2,5 +2,5 @@
# Copyright 2016 LasLabs Inc. # Copyright 2016 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from . import web_kanban_abstract
from . import web_kanban_stage
from . import base_kanban_abstract
from . import base_kanban_stage

8
web_kanban_stage/models/web_kanban_abstract.py → base_kanban_stage/models/base_kanban_abstract.py

@ -5,13 +5,13 @@
from openerp import api, fields, models from openerp import api, fields, models
class WebKanbanAbstract(models.AbstractModel):
class BaseKanbanAbstract(models.AbstractModel):
'''Inherit from this class to add support for Kanban stages to your model. '''Inherit from this class to add support for Kanban stages to your model.
All public properties are preceded with kanban_ in order to isolate from All public properties are preceded with kanban_ in order to isolate from
child models, with the exception of stage_id, which is a required field in child models, with the exception of stage_id, which is a required field in
the Kanban widget and must be defined as such.''' the Kanban widget and must be defined as such.'''
_name = 'web.kanban.abstract'
_name = 'base.kanban.abstract'
_order = 'kanban_priority desc, kanban_sequence' _order = 'kanban_priority desc, kanban_sequence'
_group_by_full = { _group_by_full = {
'stage_id': lambda s, *a, **k: s._read_group_stage_ids(*a, **k), 'stage_id': lambda s, *a, **k: s._read_group_stage_ids(*a, **k),
@ -31,7 +31,7 @@ class WebKanbanAbstract(models.AbstractModel):
) )
stage_id = fields.Many2one( stage_id = fields.Many2one(
string='Kanban Stage', string='Kanban Stage',
comodel_name='web.kanban.stage',
comodel_name='base.kanban.stage',
track_visibility='onchange', track_visibility='onchange',
index=True, index=True,
copy=False, copy=False,
@ -105,7 +105,7 @@ class WebKanbanAbstract(models.AbstractModel):
def _read_group_stage_ids( def _read_group_stage_ids(
self, domain=None, read_group_order=None, access_rights_uid=None self, domain=None, read_group_order=None, access_rights_uid=None
): ):
stage_model = self.env['web.kanban.stage'].sudo(access_rights_uid)
stage_model = self.env['base.kanban.stage'].sudo(access_rights_uid)
stages = stage_model.search([('res_model.model', '=', self._name)]) stages = stage_model.search([('res_model.model', '=', self._name)])
names = [(r.id, r.display_name) for r in stages] names = [(r.id, r.display_name) for r in stages]
fold = {r.id: r.fold for r in stages} fold = {r.id: r.fold for r in stages}

4
web_kanban_stage/models/web_kanban_stage.py → base_kanban_stage/models/base_kanban_stage.py

@ -5,8 +5,8 @@
from openerp import api, fields, models from openerp import api, fields, models
class WebKanbanStage(models.Model):
_name = 'web.kanban.stage'
class BaseKanbanStage(models.Model):
_name = 'base.kanban.stage'
_description = 'Kanban Stage' _description = 'Kanban Stage'
_order = 'res_model, sequence' _order = 'res_model, sequence'

3
base_kanban_stage/security/ir.model.access.csv

@ -0,0 +1,3 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_user,Kanban Stage - User Access,model_base_kanban_stage,base.group_user,1,0,0,0
access_manager,Kanban Stage - Manager Access,model_base_kanban_stage,base.group_erp_manager,1,1,1,1

0
web_kanban_stage/static/description/icon.png → base_kanban_stage/static/description/icon.png

Before

Width: 128  |  Height: 128  |  Size: 9.2 KiB

After

Width: 128  |  Height: 128  |  Size: 9.2 KiB

4
web_kanban_stage/tests/__init__.py → base_kanban_stage/tests/__init__.py

@ -2,5 +2,5 @@
# Copyright 2016 LasLabs Inc. # Copyright 2016 LasLabs Inc.
# License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html). # License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl.html).
from . import test_web_kanban_abstract
from . import test_web_kanban_stage
from . import test_base_kanban_abstract
from . import test_base_kanban_stage

24
web_kanban_stage/tests/test_web_kanban_abstract.py → base_kanban_stage/tests/test_base_kanban_abstract.py

@ -6,29 +6,29 @@ from openerp import models
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
class WebKanbanAbstractTester(models.Model):
_name = 'web.kanban.abstract.tester'
_inherit = 'web.kanban.abstract'
class BaseKanbanAbstractTester(models.Model):
_name = 'base.kanban.abstract.tester'
_inherit = 'base.kanban.abstract'
class TestWebKanbanAbstract(TransactionCase):
class TestBaseKanbanAbstract(TransactionCase):
def setUp(self): def setUp(self):
super(TestWebKanbanAbstract, self).setUp()
super(TestBaseKanbanAbstract, self).setUp()
WebKanbanAbstractTester._build_model(self.registry, self.cr)
self.test_model = self.env[WebKanbanAbstractTester._name]
BaseKanbanAbstractTester._build_model(self.registry, self.cr)
self.test_model = self.env[BaseKanbanAbstractTester._name]
test_model_type = self.env['ir.model'].create({ test_model_type = self.env['ir.model'].create({
'model': WebKanbanAbstractTester._name,
'model': BaseKanbanAbstractTester._name,
'name': 'Kanban Abstract - Test Model', 'name': 'Kanban Abstract - Test Model',
'state': 'base', 'state': 'base',
}) })
test_stage_1 = self.env['web.kanban.stage'].create({
test_stage_1 = self.env['base.kanban.stage'].create({
'name': 'Test Stage 1', 'name': 'Test Stage 1',
'res_model': test_model_type.id, 'res_model': test_model_type.id,
}) })
test_stage_2 = self.env['web.kanban.stage'].create({
test_stage_2 = self.env['base.kanban.stage'].create({
'name': 'Test Stage 2', 'name': 'Test Stage 2',
'res_model': test_model_type.id, 'res_model': test_model_type.id,
'fold': True, 'fold': True,
@ -50,9 +50,9 @@ class TestWebKanbanAbstract(TransactionCase):
def test_read_group_stage_ids_correct_associated_model(self): def test_read_group_stage_ids_correct_associated_model(self):
'''It should only return info for stages with right associated model''' '''It should only return info for stages with right associated model'''
stage_model = self.env['ir.model'].search([ stage_model = self.env['ir.model'].search([
('model', '=', 'web.kanban.stage'),
('model', '=', 'base.kanban.stage'),
]) ])
self.env['web.kanban.stage'].create({
self.env['base.kanban.stage'].create({
'name': 'Test Stage 3', 'name': 'Test Stage 3',
'res_model': stage_model.id, 'res_model': stage_model.id,
}) })

16
web_kanban_stage/tests/test_web_kanban_stage.py → base_kanban_stage/tests/test_base_kanban_stage.py

@ -5,18 +5,18 @@
from openerp.tests.common import TransactionCase from openerp.tests.common import TransactionCase
class TestWebKanbanStage(TransactionCase):
class TestBaseKanbanStage(TransactionCase):
def test_default_res_model_no_params(self): def test_default_res_model_no_params(self):
'''It should return empty ir.model recordset if no params in context'''
test_stage = self.env['web.kanban.stage'].with_context({})
'''It should return empty ir.model Recordset if no params in context'''
test_stage = self.env['base.kanban.stage'].with_context({})
res_model = test_stage._default_res_model() res_model = test_stage._default_res_model()
self.assertFalse(res_model) self.assertFalse(res_model)
self.assertEqual(res_model._name, 'ir.model') self.assertEqual(res_model._name, 'ir.model')
def test_default_res_model_no_action(self): def test_default_res_model_no_action(self):
'''It should return empty ir.model recordset if no action in params'''
test_stage = self.env['web.kanban.stage'].with_context(params={})
'''It should return empty ir.model Recordset if no action in params'''
test_stage = self.env['base.kanban.stage'].with_context(params={})
res_model = test_stage._default_res_model() res_model = test_stage._default_res_model()
self.assertFalse(res_model) self.assertFalse(res_model)
@ -28,7 +28,7 @@ class TestWebKanbanStage(TransactionCase):
'name': 'Test Action', 'name': 'Test Action',
'res_model': 'res.users', 'res_model': 'res.users',
}) })
test_stage = self.env['web.kanban.stage'].with_context(
test_stage = self.env['base.kanban.stage'].with_context(
params={'action': test_action.id}, params={'action': test_action.id},
) )
@ -41,9 +41,9 @@ class TestWebKanbanStage(TransactionCase):
'''It should not return ir.model record corresponding to stage model''' '''It should not return ir.model record corresponding to stage model'''
test_action = self.env['ir.actions.act_window'].create({ test_action = self.env['ir.actions.act_window'].create({
'name': 'Test Action', 'name': 'Test Action',
'res_model': 'web.kanban.stage',
'res_model': 'base.kanban.stage',
}) })
test_stage = self.env['web.kanban.stage'].with_context(
test_stage = self.env['base.kanban.stage'].with_context(
params={'action': test_action.id}, params={'action': test_action.id},
) )

4
web_kanban_stage/views/web_kanban_abstract.xml → base_kanban_stage/views/base_kanban_abstract.xml

@ -6,9 +6,9 @@
--> -->
<odoo> <odoo>
<record id="web_kanban_abstract_view_kanban" model="ir.ui.view">
<record id="base_kanban_abstract_view_kanban" model="ir.ui.view">
<field name="name">Kanban Abstract - Base Kanban View</field> <field name="name">Kanban Abstract - Base Kanban View</field>
<field name="model">web.kanban.abstract</field>
<field name="model">base.kanban.abstract</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<kanban default_group_by="stage_id" class="o_kanban_small_column"> <kanban default_group_by="stage_id" class="o_kanban_small_column">
<field name="display_name"/> <field name="display_name"/>

23
web_kanban_stage/views/web_kanban_stage.xml → base_kanban_stage/views/base_kanban_stage.xml

@ -6,9 +6,9 @@
--> -->
<odoo> <odoo>
<record id="web_kanban_stage_view_form" model="ir.ui.view">
<record id="base_kanban_stage_view_form" model="ir.ui.view">
<field name="name">Kanban Stage - Form View</field> <field name="name">Kanban Stage - Form View</field>
<field name="model">web.kanban.stage</field>
<field name="model">base.kanban.stage</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<form string="Kanban Stage"> <form string="Kanban Stage">
<header/> <header/>
@ -31,9 +31,9 @@
</field> </field>
</record> </record>
<record id="web_kanban_stage_view_tree" model="ir.ui.view">
<record id="base_kanban_stage_view_tree" model="ir.ui.view">
<field name="name">Kanban Stages - Tree View</field> <field name="name">Kanban Stages - Tree View</field>
<field name="model">web.kanban.stage</field>
<field name="model">base.kanban.stage</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<tree string="Kanban Stages"> <tree string="Kanban Stages">
<field name="name"/> <field name="name"/>
@ -43,9 +43,9 @@
</field> </field>
</record> </record>
<record id="web_kanban_stage_view_search" model="ir.ui.view">
<record id="base_kanban_stage_view_search" model="ir.ui.view">
<field name="name">Kanban Stages - Search View</field> <field name="name">Kanban Stages - Search View</field>
<field name="model">web.kanban.stage</field>
<field name="model">base.kanban.stage</field>
<field name="arch" type="xml"> <field name="arch" type="xml">
<search string="Kanban Stages"> <search string="Kanban Stages">
<field name="name"/> <field name="name"/>
@ -55,17 +55,18 @@
</field> </field>
</record> </record>
<record model="ir.actions.act_window" id="web_kanban_stage_action">
<record model="ir.actions.act_window" id="base_kanban_stage_action">
<field name="name">Kanban Stages</field> <field name="name">Kanban Stages</field>
<field name="res_model">web.kanban.stage</field>
<field name="res_model">base.kanban.stage</field>
<field name="type">ir.actions.act_window</field> <field name="type">ir.actions.act_window</field>
<field name="view_type">form</field> <field name="view_type">form</field>
<field name="view_mode">tree,form</field> <field name="view_mode">tree,form</field>
</record> </record>
<menuitem id="web_kanban_stage_root_menu" name="Kanban"
<menuitem id="base_kanban_stage_root_menu" name="Kanban"
parent="base.menu_custom" sequence="50"/> parent="base.menu_custom" sequence="50"/>
<menuitem id="web_kanban_stage_menu" name="Stages"
parent="web_kanban_stage_root_menu" action="web_kanban_stage_action"/>
<menuitem id="base_kanban_stage_menu" name="Stages"
parent="base_kanban_stage_root_menu"
action="base_kanban_stage_action" />
</odoo> </odoo>

3
web_kanban_stage/security/ir.model.access.csv

@ -1,3 +0,0 @@
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
access_user,Kanban Stage - User Access,model_web_kanban_stage,base.group_user,1,0,0,0
access_manager,Kanban Stage - Manager Access,model_web_kanban_stage,base.group_erp_manager,1,1,1,1
Loading…
Cancel
Save