Skip to content

Commit 0628b00

Browse files
committed
[ADD] web_widget_x2many_2d_matrix_example
1 parent 69cc921 commit 0628b00

File tree

11 files changed

+223
-0
lines changed

11 files changed

+223
-0
lines changed
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
.. image:: https://img.shields.io/badge/licence-AGPL--3-blue.svg
2+
:target: http://www.gnu.org/licenses/agpl-3.0-standalone.html
3+
:alt: License: AGPL-3
4+
5+
===================================
6+
2D matrix for x2many fields example
7+
===================================
8+
9+
Install it and click on the menu item `Demo x2m matrix widget`.
10+
11+
Bug Tracker
12+
===========
13+
14+
Bugs are tracked on `GitHub Issues
15+
<https://github.com/OCA/web/issues>`_. In case of trouble, please
16+
check there if your issue has already been reported. If you spotted it first,
17+
help us smash it by providing a detailed and welcomed feedback.
18+
19+
Credits
20+
=======
21+
22+
Contributors
23+
------------
24+
25+
* Simone Orsi <simone.orsi@camptocamp.com>
26+
27+
28+
Maintainer
29+
----------
30+
31+
.. image:: https://odoo-community.org/logo.png
32+
:alt: Odoo Community Association
33+
:target: https://odoo-community.org
34+
35+
This module is maintained by the OCA.
36+
37+
OCA, or the Odoo Community Association, is a nonprofit organization whose
38+
mission is to support the collaborative development of Odoo features and
39+
promote its widespread use.
40+
41+
To contribute to this module, please visit https://odoo-community.org.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from . import models
2+
from . import wizard
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{
2+
'name': 'web_widget_x2many_2d_matrix example',
3+
'summary': "A small example on how to use `web_widget_x2many_2d_matrix`.",
4+
"version": "11.0.1.0.0",
5+
"author": "Camptocamp, "
6+
"Odoo Community Association (OCA)",
7+
"website": "https://github.com/OCA/web",
8+
"license": "AGPL-3",
9+
"category": "Hidden/Dependency",
10+
"depends": [
11+
'web_widget_x2many_2d_matrix',
12+
],
13+
"data": [
14+
'security/ir.model.access.csv',
15+
'demo/x2m.demo.csv',
16+
'views/x2m_demo.xml',
17+
'wizard/x2m_matrix.xml',
18+
],
19+
"installable": True,
20+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
id,name,line_ids/user_id/id,line_ids/name,line_ids/value
2+
web_widget_x2many_2d_matrix_example.x2m_demo_5,One,,,
3+
,,base.user_demo,A,1
4+
,,base.user_demo,B,2
5+
,,base.user_demo,C,3
6+
web_widget_x2many_2d_matrix_example.x2m_demo_3,Two,,,
7+
,,base.user_demo,E,5
8+
,,base.user_demo,F,6
9+
web_widget_x2many_2d_matrix_example.x2m_demo_2,Three,,,
10+
,,base.user_root,G,8
11+
,,base.user_demo,H,9
12+
,,base.user_root,I,10
13+
web_widget_x2many_2d_matrix_example.x2m_demo_1,Four,,,
14+
,,base.user_root,L,12
15+
,,base.user_demo,M,13
16+
,,base.user_demo,N,14
17+
,,base.user_demo,O,15
18+
,,base.user_root,P,16
19+
web_widget_x2many_2d_matrix_example.x2m_demo_4,Five,,,
20+
,,base.user_demo,Q,18
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import x2m_demo
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from odoo import models, api, fields
2+
3+
4+
class X2MDemo(models.Model):
5+
_name = 'x2m.demo'
6+
7+
name = fields.Char()
8+
line_ids = fields.One2many('x2m.demo.line', 'demo_id')
9+
10+
@api.multi
11+
def open_x2m_matrix(self):
12+
wiz = self.env['x2m.matrix.demo.wiz'].create({})
13+
return {
14+
'name': 'Try x2many 2D matrix widget',
15+
'type': 'ir.actions.act_window',
16+
'view_type': 'form',
17+
'view_mode': 'form',
18+
'res_model': 'x2m.matrix.demo.wiz',
19+
'target': 'new',
20+
'res_id': wiz.id,
21+
'context': self.env.context,
22+
}
23+
24+
25+
class X2MDemoLine(models.Model):
26+
_name = 'x2m.demo.line'
27+
28+
name = fields.Char()
29+
demo_id = fields.Many2one('x2m.demo')
30+
user_id = fields.Many2one('res.users')
31+
value = fields.Integer()
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink
2+
access_x2m_demo_line,access_x2m_demo_line,model_x2m_demo_line,base.group_user,1,0,0,0
3+
access_x2m_demo_line_admin,access_x2m_demo_line_admin,model_x2m_demo_line,base.group_system,1,1,1,1
4+
access_x2m_demo,access_x2m_demo,model_x2m_demo,base.group_user,1,0,0,0
5+
access_x2m_demo_admin,access_x2m_demo_admin,model_x2m_demo,base.group_system,1,1,1,1
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<odoo>
3+
4+
<record id="view_x2m_demo_form" model="ir.ui.view">
5+
<field name="name">x2m.demo.form</field>
6+
<field name="model">x2m.demo</field>
7+
<field name="arch" type="xml">
8+
<form>
9+
<sheet>
10+
<group>
11+
<field name="name" />
12+
<field name="line_ids">
13+
<tree>
14+
<field name="name" />
15+
<field name="value" />
16+
<field name="user_id" />
17+
</tree>
18+
</field>
19+
</group>
20+
<footer>
21+
<button name="open_x2m_matrix" type="object"
22+
string="Try x2m 2d matrix"
23+
class="oe_stat_button" icon="fa-edit" />
24+
</footer>
25+
</sheet>
26+
</form>
27+
</field>
28+
</record>
29+
30+
<record model="ir.ui.view" id="view_x2m_demo_tree">
31+
<field name="name">Demo - Tree</field>
32+
<field name="model">x2m.demo</field>
33+
<field name="arch" type="xml">
34+
<tree>
35+
<field name="name" />
36+
</tree>
37+
</field>
38+
</record>
39+
40+
<record id="action_x2m_demo" model="ir.actions.act_window">
41+
<field name="name">Demo</field>
42+
<field name="res_model">x2m.demo</field>
43+
<field name="view_type">form</field>
44+
<field name="view_mode">tree,form</field>
45+
<field name="view_id" ref="view_x2m_demo_tree"/>
46+
</record>
47+
48+
<menuitem
49+
id="base_matrix_widget_menu"
50+
name="Demo x2m matrix widget"
51+
action="action_x2m_demo"
52+
/>
53+
54+
</odoo>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import demo_wizard
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
from odoo import fields, models
2+
3+
4+
class DemoWizard(models.TransientModel):
5+
_name = 'x2m.matrix.demo.wiz'
6+
7+
line_ids = fields.Many2many(
8+
'x2m.demo.line', default=lambda self: self._default_line_ids())
9+
10+
def _default_line_ids(self):
11+
recs = self.env['x2m.demo'].search([])
12+
# same with users
13+
users = self.env['x2m.demo.line'].search([]).mapped('user_id')
14+
return [
15+
(0, 0, {
16+
'name': "{}'s task on {}".format(usr.name, rec.name),
17+
'demo_id': rec.id,
18+
'user_id': usr.id,
19+
'value': 0,
20+
})
21+
# if the project doesn't have a task for the user, create a new one
22+
if not rec.line_ids.filtered(lambda x: x.user_id == usr) else
23+
# otherwise, return the task
24+
(4, rec.line_ids.filtered(lambda x: x.user_id == usr)[0].id)
25+
for rec in recs
26+
for usr in users
27+
]

0 commit comments

Comments
 (0)