From e73038b836f36cfd5120b71e32b044b70cae24df Mon Sep 17 00:00:00 2001 From: Nikolina Todorova Date: Tue, 25 Oct 2016 21:41:38 +0200 Subject: [PATCH] [7.0] [ADD] web_note and web_note_test (#216) --- web_note/README.rst | 58 ++++++++++++ web_note/__init__.py | 4 + web_note/__openerp__.py | 27 ++++++ web_note/security/ir.model.access.csv | 3 + web_note/security/web_note_security.xml | 32 +++++++ web_note/web_note.py | 98 +++++++++++++++++++++ web_note/web_note_test/__init__.py | 5 ++ web_note/web_note_test/__openerp__.py | 26 ++++++ web_note/web_note_test/res_partner.py | 12 +++ web_note/web_note_test/res_partner_view.xml | 16 ++++ web_note/web_note_test/web_note.py | 12 +++ web_note/web_note_view.xml | 32 +++++++ 12 files changed, 325 insertions(+) create mode 100644 web_note/README.rst create mode 100644 web_note/__init__.py create mode 100644 web_note/__openerp__.py create mode 100644 web_note/security/ir.model.access.csv create mode 100644 web_note/security/web_note_security.xml create mode 100644 web_note/web_note.py create mode 100644 web_note/web_note_test/__init__.py create mode 100644 web_note/web_note_test/__openerp__.py create mode 100644 web_note/web_note_test/res_partner.py create mode 100644 web_note/web_note_test/res_partner_view.xml create mode 100644 web_note/web_note_test/web_note.py create mode 100644 web_note/web_note_view.xml diff --git a/web_note/README.rst b/web_note/README.rst new file mode 100644 index 00000000..8b91363e --- /dev/null +++ b/web_note/README.rst @@ -0,0 +1,58 @@ +.. 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 + +============== +Web Note +============== + +This module can be used for adding a notes field in any module that need them. +There are three type of notes - private, internal, external. +Only the user that create a private note can see it. The other two types can be used for creating different views. + +Usage +===== + +To use this module, you need to: + + * Add dependencie to 'web_note' in the __openerp__.py file of the module in which you need the webnotes(your module). + * inherit the web.note class and add many2one field connected with your model + * in your model create one2many field to web.note model + * add the field in the view you want + +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 smashing it by providing a detailed and welcomed feedback. + +Credits +======= + +Images +------ + +* Odoo Community Association: `Icon `_. + +Contributors +------------ + +* Nikolina Todorova + +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_note/__init__.py b/web_note/__init__.py new file mode 100644 index 00000000..4eac210b --- /dev/null +++ b/web_note/__init__.py @@ -0,0 +1,4 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2014 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import web_note diff --git a/web_note/__openerp__.py b/web_note/__openerp__.py new file mode 100644 index 00000000..525af2b4 --- /dev/null +++ b/web_note/__openerp__.py @@ -0,0 +1,27 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2014 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + 'name': 'Web Note', + 'version': '7.0.1.0.0', + 'author': 'initOS GmbH', + 'category': '', + 'description': + """ +This module can be used for adding a notes field in any module that need them. +There are three type of notes - private, internal, external. +Only the user that create a private note can see it. +The other two types can be used for creating different views. + """, + 'website': 'http://www.initos.com', + 'license': 'AGPL-3', + 'images': [], + 'depends': [], + 'data': [ + "web_note_view.xml", + "security/web_note_security.xml", + "security/ir.model.access.csv", + ], + 'active': False, + 'installable': True +} diff --git a/web_note/security/ir.model.access.csv b/web_note/security/ir.model.access.csv new file mode 100644 index 00000000..270eb81d --- /dev/null +++ b/web_note/security/ir.model.access.csv @@ -0,0 +1,3 @@ +id,name,model_id:id,group_id:id,perm_read,perm_write,perm_create,perm_unlink +access_web_note,access.web.note,model_web_note,group_web_note_user,1,1,1,1 +access_web_note_container,access.web.note.container,model_web_note_container,group_web_note_user,1,1,1,1 \ No newline at end of file diff --git a/web_note/security/web_note_security.xml b/web_note/security/web_note_security.xml new file mode 100644 index 00000000..ef21aae6 --- /dev/null +++ b/web_note/security/web_note_security.xml @@ -0,0 +1,32 @@ + + + + + + Web Note / User + + + + + Note Private + + + ['|',('type', '!=', 'private'),'&' ,('type', '=', 'private'), ('create_uid', '=', user.id)] + + + + + + + + Note Container Private + + + ['|',('type', '!=', 'private'),'&', ('type', '=', 'private'), ('create_uid', '=', user.id)] + + + + + + + \ No newline at end of file diff --git a/web_note/web_note.py b/web_note/web_note.py new file mode 100644 index 00000000..e1b10e73 --- /dev/null +++ b/web_note/web_note.py @@ -0,0 +1,98 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2014 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp.osv import orm, fields +import re + + +def remove_html_tags(data): + p = re.compile(r'<.*?>') + return p.sub('', data) + + +def remove_extra_spaces(data): + p = re.compile(r'\s+') + return p.sub(' ', data) + + +def _type_selection(self, *args, **kwargs): + """Redirect for easier overwriting.""" + return self.pool.get('web.note').type_selection(*args, **kwargs) + + +class WebNote(orm.Model): + _name = 'web.note' + + def name_get(self, cr, uid, ids, context=None): + if context is None: + context = {} + if isinstance(ids, (int, long)): + ids = [ids] + res = [] + for record in self.browse(cr, uid, ids, context=context): + name = remove_extra_spaces(remove_html_tags(record.message or '')) + + res.append((record.id, name)) + return res + + def _name_get_fnc(self, cr, uid, ids, prop, unknow_none, context=None): + res = self.name_get(cr, uid, ids, context=context) + return dict(res) + + def type_selection(self, cr, uid, context=None): + return (('private', 'private'), + ('internal', 'internal'), + ('external', 'external')) + + def onchange_container_id(self, cr, uid, ids, + container_id=False, message=None, context=None): + result = {} + if container_id: + container = self.pool.get('web.note.container').\ + browse(cr, uid, container_id, context=context) + result['value'] = { + 'sequence': + container.sequence or self._defaults.get('sequence', 0), + } + if container.pattern: + result['value']['message'] = container.pattern + return result + + _order = 'sequence,create_date' + + _columns = { + 'type': fields.selection(_type_selection, 'Note type', required=True), + 'message': fields.html('Message'), + 'display_name': + fields.function(_name_get_fnc, + type="char", string='Note', store=False), + 'container_id': fields.many2one('web.note.container', 'Note-Container', + help='Containers include ' + 'templates for order and heading.'), + 'sequence': fields.integer('Order in report'), + 'create_uid': fields.many2one('res.users', 'User', readonly=True), + } + + _defaults = { + 'sequence': 10, + } + + +class WebNoteContainer(orm.Model): + _name = 'web.note.container' + _description = 'Note Container' + + _order = 'type, sequence' + + _columns = { + 'name': fields.char('Name', required=True,), + 'sequence': fields.integer('Order in report'), + 'type': fields.selection(_type_selection, 'Report', required=True), + 'pattern': fields.html('Template', + help='If you select the container the ' + 'template is added to the note.') + } + + _defaults = { + 'sequence': 10, + } diff --git a/web_note/web_note_test/__init__.py b/web_note/web_note_test/__init__.py new file mode 100644 index 00000000..3e2cf538 --- /dev/null +++ b/web_note/web_note_test/__init__.py @@ -0,0 +1,5 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2014 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from . import web_note +from . import res_partner diff --git a/web_note/web_note_test/__openerp__.py b/web_note/web_note_test/__openerp__.py new file mode 100644 index 00000000..4dfe4a50 --- /dev/null +++ b/web_note/web_note_test/__openerp__.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2014 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +{ + 'name': 'Web Note Test', + 'version': '7.0.1.0.0', + 'author': 'initOS GmbH', + 'category': '', + 'description': + """ +This module is example of the use of the web_note module. + """, + 'website': 'http://www.initos.com', + 'license': 'AGPL-3', + 'images': [], + 'depends': [ + "base", + "sale", + "web_note", + ], + 'data': [ + "res_partner_view.xml", + ], + 'active': False, + 'installable': True +} diff --git a/web_note/web_note_test/res_partner.py b/web_note/web_note_test/res_partner.py new file mode 100644 index 00000000..0e8c371c --- /dev/null +++ b/web_note/web_note_test/res_partner.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2014 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp.osv import orm, fields + + +class res_partner(orm.Model): + _inherit = 'res.partner' + + _columns = { + 'notes': fields.one2many('web.note', 'partner_id', 'Notes') + } diff --git a/web_note/web_note_test/res_partner_view.xml b/web_note/web_note_test/res_partner_view.xml new file mode 100644 index 00000000..32ba8404 --- /dev/null +++ b/web_note/web_note_test/res_partner_view.xml @@ -0,0 +1,16 @@ + + + + + res.partner.view.buttons + res.partner + + + + + + + + + + \ No newline at end of file diff --git a/web_note/web_note_test/web_note.py b/web_note/web_note_test/web_note.py new file mode 100644 index 00000000..9f43cb6b --- /dev/null +++ b/web_note/web_note_test/web_note.py @@ -0,0 +1,12 @@ +# -*- coding: utf-8 -*- +# © initOS GmbH 2014 +# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). +from openerp.osv import orm, fields + + +class WebNote(orm.Model): + _inherit = 'web.note' + _columns = { + 'partner_id': + fields.many2one('res.partner', 'Partner Id', invisible=True), + } diff --git a/web_note/web_note_view.xml b/web_note/web_note_view.xml new file mode 100644 index 00000000..2e3454b6 --- /dev/null +++ b/web_note/web_note_view.xml @@ -0,0 +1,32 @@ + + + + + web.note.form + web.note + +
+ + + + + +
+ + web.note.tree + web.note + + + + + + + + + +
+