From 366b3015b62b136db31e26a0163ead9ba29ca491 Mon Sep 17 00:00:00 2001 From: Simone Orsi Date: Tue, 20 Feb 2018 12:46:16 +0100 Subject: [PATCH] [ADD] `web_widget_x2many_2d_matrix_example` --- .../README.rst | 41 ++++++++++++++ .../__init__.py | 2 + .../__manifest__.py | 20 +++++++ .../demo/x2m.demo.csv | 20 +++++++ .../models/__init__.py | 1 + .../models/x2m_demo.py | 31 +++++++++++ .../security/ir.model.access.csv | 5 ++ .../views/x2m_demo.xml | 54 +++++++++++++++++++ .../wizard/__init__.py | 1 + .../wizard/demo_wizard.py | 27 ++++++++++ .../wizard/x2m_matrix.xml | 21 ++++++++ 11 files changed, 223 insertions(+) create mode 100644 web_widget_x2many_2d_matrix_example/README.rst create mode 100644 web_widget_x2many_2d_matrix_example/__init__.py create mode 100644 web_widget_x2many_2d_matrix_example/__manifest__.py create mode 100644 web_widget_x2many_2d_matrix_example/demo/x2m.demo.csv create mode 100644 web_widget_x2many_2d_matrix_example/models/__init__.py create mode 100644 web_widget_x2many_2d_matrix_example/models/x2m_demo.py create mode 100644 web_widget_x2many_2d_matrix_example/security/ir.model.access.csv create mode 100644 web_widget_x2many_2d_matrix_example/views/x2m_demo.xml create mode 100644 web_widget_x2many_2d_matrix_example/wizard/__init__.py create mode 100644 web_widget_x2many_2d_matrix_example/wizard/demo_wizard.py create mode 100644 web_widget_x2many_2d_matrix_example/wizard/x2m_matrix.xml diff --git a/web_widget_x2many_2d_matrix_example/README.rst b/web_widget_x2many_2d_matrix_example/README.rst new file mode 100644 index 00000000..4f8000d9 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/README.rst @@ -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 +`_. 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 + + +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. diff --git a/web_widget_x2many_2d_matrix_example/__init__.py b/web_widget_x2many_2d_matrix_example/__init__.py new file mode 100644 index 00000000..9b429614 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/__init__.py @@ -0,0 +1,2 @@ +from . import models +from . import wizard diff --git a/web_widget_x2many_2d_matrix_example/__manifest__.py b/web_widget_x2many_2d_matrix_example/__manifest__.py new file mode 100644 index 00000000..75567396 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/__manifest__.py @@ -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, +} diff --git a/web_widget_x2many_2d_matrix_example/demo/x2m.demo.csv b/web_widget_x2many_2d_matrix_example/demo/x2m.demo.csv new file mode 100644 index 00000000..9a8b5aa1 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/demo/x2m.demo.csv @@ -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 diff --git a/web_widget_x2many_2d_matrix_example/models/__init__.py b/web_widget_x2many_2d_matrix_example/models/__init__.py new file mode 100644 index 00000000..a23d8c46 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/models/__init__.py @@ -0,0 +1 @@ +from . import x2m_demo diff --git a/web_widget_x2many_2d_matrix_example/models/x2m_demo.py b/web_widget_x2many_2d_matrix_example/models/x2m_demo.py new file mode 100644 index 00000000..039f5a75 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/models/x2m_demo.py @@ -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() diff --git a/web_widget_x2many_2d_matrix_example/security/ir.model.access.csv b/web_widget_x2many_2d_matrix_example/security/ir.model.access.csv new file mode 100644 index 00000000..ff2b0388 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/security/ir.model.access.csv @@ -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 diff --git a/web_widget_x2many_2d_matrix_example/views/x2m_demo.xml b/web_widget_x2many_2d_matrix_example/views/x2m_demo.xml new file mode 100644 index 00000000..8f6805b6 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/views/x2m_demo.xml @@ -0,0 +1,54 @@ + + + + + x2m.demo.form + x2m.demo + +
+ + + + + + + + + + + +
+
+
+
+
+
+ + + Demo - Tree + x2m.demo + + + + + + + + + Demo + x2m.demo + form + tree,form + + + + + +
diff --git a/web_widget_x2many_2d_matrix_example/wizard/__init__.py b/web_widget_x2many_2d_matrix_example/wizard/__init__.py new file mode 100644 index 00000000..68ebaf69 --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/wizard/__init__.py @@ -0,0 +1 @@ +from . import demo_wizard diff --git a/web_widget_x2many_2d_matrix_example/wizard/demo_wizard.py b/web_widget_x2many_2d_matrix_example/wizard/demo_wizard.py new file mode 100644 index 00000000..267bcd6e --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/wizard/demo_wizard.py @@ -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 + ] diff --git a/web_widget_x2many_2d_matrix_example/wizard/x2m_matrix.xml b/web_widget_x2many_2d_matrix_example/wizard/x2m_matrix.xml new file mode 100644 index 00000000..db0c02ee --- /dev/null +++ b/web_widget_x2many_2d_matrix_example/wizard/x2m_matrix.xml @@ -0,0 +1,21 @@ + + + + + x2m.matrix.demo.wiz + x2m.matrix.demo.wiz + form + +
+ + + + + + + +
+
+
+ +