How to do it...

Follow the steps below to create an attractive kanban card.

  1. Add a new model to manage the tags for the library.book.rent model, as follows:
class LibraryRentTags(models.Model):
_name = 'library.rent.tag'

    name = fields.Char()
color = fields.Integer()
  1. Add basic access rights for the library.rent.tag model, as follows:
acl_book_rent_tags,library.book_rent_tags_default,model_library_rent_tag,,1,0,0,0
acl_book_rent_librarian_tags,library.book_rent_tags_librarian,model_library_rent_tag,group_librarian,1,1,1,1
  1. Add new fields in the library.book.rent model, as follows:
    color = fields.Integer()
popularity = fields.Selection([
('no', 'No Demand'),
('low', 'Low Demand'),
('medium', 'Average Demand'),
('high', 'High Demand')], default="no")
tag_ids = fields.Many2many('library.rent.tag')
  1. Add fields in the form view, as follows:
<field name="popularity" widget="priority"/>
<field name="tag_ids" widget="many2many_tags"
options="{'color_field': 'color', 'no_create_edit': True}"/>
  1. Update the kanban view to display colors, tags, and priorities, as shown in the following example:
<kanban default_group_by="stage_id" on_create="quick_create"   
quick_create_view="my_library.library_book_rent_view_form_minimal">
<field name="stage_id" />
<field name="color" />
<templates>
<t t-name="kanban-box">
<div t-attf-class="#{kanban_color(record.color.raw_value)} oe_kanban_global_click">
<div class="o_dropdown_kanban dropdown">
<a class="dropdown-toggle o-no-caret btn" role="button" data-toggle="dropdown">
<span class="fa fa-ellipsis-v"/>
</a>
<div class="dropdown-menu" role="menu">
<t t-if="widget.editable">
<a role="menuitem" type="edit" class="dropdown-item">Edit</a>
</t>
<t t-if="widget.deletable">
<a role="menuitem" type="delete" class="dropdown-item">Delete</a>
</t>
<ul class="oe_kanban_colorpicker" data-field="color"/>
</div>
</div>
<div class="oe_kanban_content">
<div class="oe_kanban_card oe_kanban_global_click">
<div>
<i class="fa fa-user"/>
<b>
<field name="borrower_id" />
</b>
</div>
<div class="text-muted">
<i class="fa fa-book"/>
<field name="book_id" />
</div>
<span class="oe_kanban_list_many2many">
<field name="tag_ids" widget="many2many_tags" options="{'color_field': 'color'}"/>
</span>
<div>
<field name="popularity" widget="priority"/>
</div>
</div>
</div>
</div>
</t>
</templates>
</kanban>
The code in bold should be added to the existing kanban view.

Restart the server and update the module to apply the changes. Then, click on the plus icon on the column. It will display kanban, as shown in the following figure:

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset