Skip to Content
Menu
v 17.0 Third Party 444
Download for v 17.0 Deploy on Odoo.sh
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 340
Technical Name kw_matrix_widget
LicenseOPL-1
Websitehttps://kitworks.systems/
Versions 14.0 15.0 16.0 17.0 18.0
You bought this module and need support? Click here!
Availability
Odoo Online
Odoo.sh
On Premise
Lines of code 340
Technical Name kw_matrix_widget
LicenseOPL-1
Websitehttps://kitworks.systems/
Versions 14.0 15.0 16.0 17.0 18.0

Matrix widget

Adds very customizable 2d matrix view

Maintainer
KitWorks

Our web site: https://kitworks.systems

This module is maintained by the Kitworks systems company.

We can provide you further Odoo Support, Odoo implementation, Odoo customization, Odoo 3rd Party development and integration software, consulting services. Our main goal is to provide the best quality product for you.

For any questions contact us.

Matrix widget

Matrix widget is mostly used on compute Text fileds. Like this:

hour_summary = fields.Text('Summary', compute='_compute_hour_summary')

on form view just add widget parameter to field:

<field name="hour_summary" widget="kw_matrix_widget"/>

The most difficult stage is calculating correct json.

{
    "class": "table",
    "header": {"trs": [{"tds": [{"value": "Title"}]}]},
    "body": {"trs": [{"tds": [ {"value": "Value"}]}]},
    "footer": {"trs": [{"tds": [ {"value": "Footer"}]}]}
}

You will get something like this

Title
Value
Footer

Any section is not required. "header" and "footer" generation "th" html tags for cells. "body" generate "td" html tags. Does not matter order of this sections in json, they will be placed in order header - body - footer. Default value for "class" is "table table-striped table-hover"

Each section (except "class". "class" is simple string) is a dictionary and has same syntax with next keys:

  1. trs
  2. class

"trs" is required. For "header" section default value for "class" is "thead-light". "trs" is a list of dict with next keys:

  1. tds

"tds" is required. "tds" is a list of dict with next keys:

  1. class
  2. style
  3. data
  4. colspan
  5. rowspan
  6. value

"value" is required. "value" is simple string. "class", "style", "colspan", "rowspan" will be put as param of html tag td/th. "value" will be put inside. "data" will be put in tag param named "data-matrix". This param will be parced for cells that has class "clickable_matrix_cell" and must contains json with action (will be transmitted as param to do_action method)

How to prepare "data"

You should create action dict, convert it to json and base64. Like next:

data = {
    'name': _('Register reservation'),
    'view_mode': 'form',
    'res_model': 'kw.matrix.reserve.wizard',
    'type': 'ir.actions.act_window',
    'views': [(self.env.ref(
        'kw_equipment_rental.'
        'kw_equipment_rental_kw_matrix_reserve_wizard_form'
        '').id, 'form')],
    'context': {
        'default_kw_equipment_id': equipment_id.id,
        'default_kw_location_id': self.location_id.id,
        'default_hour': hour,
        'default_date':
            self.reservation_date.strftime('%Y-%m-%d'),
    }}
data = json.dumps(data)
data = base64.b64encode(data.encode()).decode()

Methods

It maybe complicate to create multi-level json.

Abstract model kw.matrix.compute.mixin has methods for makes this process easier.

@staticmethod
def kw_generate_matrix_json(matrix_value,
                            col_class='align-middle text-center',
                            row_class='font-weight-bold',
                            cell_class='text-right pr-1',
                            table_class='table table-striped table-hover',
                            header_class='thead-light', ):

"matrix_value" is list of list (cells inside rows). Of course you can't use colspan and rowspan function, but you can easy add class value to correct cell.

@staticmethod
    @staticmethod
def kw_generate_matrix_value(value_list, row_names=None, col_names=None):

"value_list" is dict of dicts. "row_names" and "col_names" is a lists. result will be list of lists. Values will be get from value_list by "row_names" and "col_names" values.

Odoo Proprietary License v1.0

This software and associated files (the "Software") may only be used (executed,
modified, executed after modifications) if you have purchased a valid license
from the authors, typically via Odoo Apps, or if you have received a written
agreement from the authors of the Software (see the COPYRIGHT file).

You may develop Odoo modules that use the Software as a library (typically
by depending on it, importing it and using its resources), but without copying
any source code or material from the Software. You may distribute those
modules under the license of your choice, provided that this license is
compatible with the terms of the Odoo Proprietary License (For example:
LGPL, MIT, or proprietary licenses similar to this one).

It is forbidden to publish, distribute, sublicense, or sell copies of the Software
or modified copies of the Software.

The above copyright notice and this permission notice must be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
DEALINGS IN THE SOFTWARE.

Please log in to comment on this module

  • The author can leave a single reply to each comment.
  • This section is meant to ask simple questions or leave a rating. Every report of a problem experienced while using the module should be addressed to the author directly (refer to the following point).
  • If you want to start a discussion with the author, please use the developer contact information. They can usually be found in the description.
Please choose a rating from 1 to 5 for this module.