forked from Techsystech/web
[ADD] `web_widget_x2many_2d_matrix_example`
parent
507888d4df
commit
366b3015b6
|
@ -0,0 +1,41 @@
|
|||
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
|
||||
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
|
||||
:alt: License: AGPL-3
|
||||
|
||||
===================================
|
||||
2D matrix for x2many fields example
|
||||
===================================
|
||||
|
||||
Install it and click on the menu item `Demo x2m matrix widget`.
|
||||
|
||||
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. If you spotted it first,
|
||||
help us smash it by providing a detailed and welcomed feedback.
|
||||
|
||||
Credits
|
||||
=======
|
||||
|
||||
Contributors
|
||||
------------
|
||||
|
||||
* Simone Orsi <simone.orsi@camptocamp.com>
|
||||
|
||||
|
||||
Maintainer
|
||||
----------
|
||||
|
||||
.. image:: https://odoo-community.org/logo.png
|
||||
:alt: Odoo Community Association
|
||||
:target: https://odoo-community.org
|
||||
|
||||
This module is maintained by the OCA.
|
||||
|
||||
OCA, or the Odoo Community Association, is a nonprofit organization whose
|
||||
mission is to support the collaborative development of Odoo features and
|
||||
promote its widespread use.
|
||||
|
||||
To contribute to this module, please visit https://odoo-community.org.
|
|
@ -0,0 +1,2 @@
|
|||
from . import models
|
||||
from . import wizard
|
|
@ -0,0 +1,20 @@
|
|||
{
|
||||
'name': 'web_widget_x2many_2d_matrix example',
|
||||
'summary': "A small example on how to use `web_widget_x2many_2d_matrix`.",
|
||||
"version": "11.0.1.0.0",
|
||||
"author": "Camptocamp, "
|
||||
"Odoo Community Association (OCA)",
|
||||
"website": "https://github.com/OCA/web",
|
||||
"license": "AGPL-3",
|
||||
"category": "Hidden/Dependency",
|
||||
"depends": [
|
||||
'web_widget_x2many_2d_matrix',
|
||||
],
|
||||
"data": [
|
||||
'security/ir.model.access.csv',
|
||||
'demo/x2m.demo.csv',
|
||||
'views/x2m_demo.xml',
|
||||
'wizard/x2m_matrix.xml',
|
||||
],
|
||||
"installable": True,
|
||||
}
|
|
@ -0,0 +1,20 @@
|
|||
id,name,line_ids/user_id/id,line_ids/name,line_ids/value
|
||||
web_widget_x2many_2d_matrix_example.x2m_demo_5,One,,,
|
||||
,,base.user_demo,A,1
|
||||
,,base.user_demo,B,2
|
||||
,,base.user_demo,C,3
|
||||
web_widget_x2many_2d_matrix_example.x2m_demo_3,Two,,,
|
||||
,,base.user_demo,E,5
|
||||
,,base.user_demo,F,6
|
||||
web_widget_x2many_2d_matrix_example.x2m_demo_2,Three,,,
|
||||
,,base.user_root,G,8
|
||||
,,base.user_demo,H,9
|
||||
,,base.user_root,I,10
|
||||
web_widget_x2many_2d_matrix_example.x2m_demo_1,Four,,,
|
||||
,,base.user_root,L,12
|
||||
,,base.user_demo,M,13
|
||||
,,base.user_demo,N,14
|
||||
,,base.user_demo,O,15
|
||||
,,base.user_root,P,16
|
||||
web_widget_x2many_2d_matrix_example.x2m_demo_4,Five,,,
|
||||
,,base.user_demo,Q,18
|
|
|
@ -0,0 +1 @@
|
|||
from . import x2m_demo
|
|
@ -0,0 +1,31 @@
|
|||
from odoo import models, api, fields
|
||||
|
||||
|
||||
class X2MDemo(models.Model):
|
||||
_name = 'x2m.demo'
|
||||
|
||||
name = fields.Char()
|
||||
line_ids = fields.One2many('x2m.demo.line', 'demo_id')
|
||||
|
||||
@api.multi
|
||||
def open_x2m_matrix(self):
|
||||
wiz = self.env['x2m.matrix.demo.wiz'].create({})
|
||||
return {
|
||||
'name': 'Try x2many 2D matrix widget',
|
||||
'type': 'ir.actions.act_window',
|
||||
'view_type': 'form',
|
||||
'view_mode': 'form',
|
||||
'res_model': 'x2m.matrix.demo.wiz',
|
||||
'target': 'new',
|
||||
'res_id': wiz.id,
|
||||
'context': self.env.context,
|
||||
}
|
||||
|
||||
|
||||
class X2MDemoLine(models.Model):
|
||||
_name = 'x2m.demo.line'
|
||||
|
||||
name = fields.Char()
|
||||
demo_id = fields.Many2one('x2m.demo')
|
||||
user_id = fields.Many2one('res.users')
|
||||
value = fields.Integer()
|
|
@ -0,0 +1,5 @@
|
|||
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
|
||||
access_x2m_demo_line,access_x2m_demo_line,model_x2m_demo_line,base.group_user,1,0,0,0
|
||||
access_x2m_demo_line_admin,access_x2m_demo_line_admin,model_x2m_demo_line,base.group_system,1,1,1,1
|
||||
access_x2m_demo,access_x2m_demo,model_x2m_demo,base.group_user,1,0,0,0
|
||||
access_x2m_demo_admin,access_x2m_demo_admin,model_x2m_demo,base.group_system,1,1,1,1
|
|
|
@ -0,0 +1,54 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="view_x2m_demo_form" model="ir.ui.view">
|
||||
<field name="name">x2m.demo.form</field>
|
||||
<field name="model">x2m.demo</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<sheet>
|
||||
<group>
|
||||
<field name="name" />
|
||||
<field name="line_ids">
|
||||
<tree>
|
||||
<field name="name" />
|
||||
<field name="value" />
|
||||
<field name="user_id" />
|
||||
</tree>
|
||||
</field>
|
||||
</group>
|
||||
<footer>
|
||||
<button name="open_x2m_matrix" type="object"
|
||||
string="Try x2m 2d matrix"
|
||||
class="oe_stat_button" icon="fa-edit" />
|
||||
</footer>
|
||||
</sheet>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record model="ir.ui.view" id="view_x2m_demo_tree">
|
||||
<field name="name">Demo - Tree</field>
|
||||
<field name="model">x2m.demo</field>
|
||||
<field name="arch" type="xml">
|
||||
<tree>
|
||||
<field name="name" />
|
||||
</tree>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
<record id="action_x2m_demo" model="ir.actions.act_window">
|
||||
<field name="name">Demo</field>
|
||||
<field name="res_model">x2m.demo</field>
|
||||
<field name="view_type">form</field>
|
||||
<field name="view_mode">tree,form</field>
|
||||
<field name="view_id" ref="view_x2m_demo_tree"/>
|
||||
</record>
|
||||
|
||||
<menuitem
|
||||
id="base_matrix_widget_menu"
|
||||
name="Demo x2m matrix widget"
|
||||
action="action_x2m_demo"
|
||||
/>
|
||||
|
||||
</odoo>
|
|
@ -0,0 +1 @@
|
|||
from . import demo_wizard
|
|
@ -0,0 +1,27 @@
|
|||
from odoo import fields, models
|
||||
|
||||
|
||||
class DemoWizard(models.TransientModel):
|
||||
_name = 'x2m.matrix.demo.wiz'
|
||||
|
||||
line_ids = fields.Many2many(
|
||||
'x2m.demo.line', default=lambda self: self._default_line_ids())
|
||||
|
||||
def _default_line_ids(self):
|
||||
recs = self.env['x2m.demo'].search([])
|
||||
# same with users
|
||||
users = self.env['x2m.demo.line'].search([]).mapped('user_id')
|
||||
return [
|
||||
(0, 0, {
|
||||
'name': "{}'s task on {}".format(usr.name, rec.name),
|
||||
'demo_id': rec.id,
|
||||
'user_id': usr.id,
|
||||
'value': 0,
|
||||
})
|
||||
# if the project doesn't have a task for the user, create a new one
|
||||
if not rec.line_ids.filtered(lambda x: x.user_id == usr) else
|
||||
# otherwise, return the task
|
||||
(4, rec.line_ids.filtered(lambda x: x.user_id == usr)[0].id)
|
||||
for rec in recs
|
||||
for usr in users
|
||||
]
|
|
@ -0,0 +1,21 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<odoo>
|
||||
|
||||
<record id="x2many_2d_matrix_demo" model="ir.ui.view">
|
||||
<field name="name">x2m.matrix.demo.wiz</field>
|
||||
<field name="model">x2m.matrix.demo.wiz</field>
|
||||
<field name="type">form</field>
|
||||
<field name="arch" type="xml">
|
||||
<form>
|
||||
<field name="line_ids" widget="x2many_2d_matrix" field_x_axis="demo_id" field_y_axis="user_id" field_value="value">
|
||||
<tree>
|
||||
<field name="demo_id"/>
|
||||
<field name="user_id"/>
|
||||
<field name="value"/>
|
||||
</tree>
|
||||
</field>
|
||||
</form>
|
||||
</field>
|
||||
</record>
|
||||
|
||||
</odoo>
|
Loading…
Reference in New Issue