Nikolina Todorova
8 years ago
committed by
Pedro M. Baeza
12 changed files with 325 additions and 0 deletions
-
58web_note/README.rst
-
4web_note/__init__.py
-
27web_note/__openerp__.py
-
3web_note/security/ir.model.access.csv
-
32web_note/security/web_note_security.xml
-
98web_note/web_note.py
-
5web_note/web_note_test/__init__.py
-
26web_note/web_note_test/__openerp__.py
-
12web_note/web_note_test/res_partner.py
-
16web_note/web_note_test/res_partner_view.xml
-
12web_note/web_note_test/web_note.py
-
32web_note/web_note_view.xml
@ -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 |
||||
|
<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 smashing it by providing a detailed and welcomed feedback. |
||||
|
|
||||
|
Credits |
||||
|
======= |
||||
|
|
||||
|
Images |
||||
|
------ |
||||
|
|
||||
|
* Odoo Community Association: `Icon <https://github.com/OCA/maintainer-tools/blob/master/template/module/static/description/icon.svg>`_. |
||||
|
|
||||
|
Contributors |
||||
|
------------ |
||||
|
|
||||
|
* Nikolina Todorova <nikolina.todorova@initos.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,4 @@ |
|||||
|
# -*- coding: utf-8 -*- |
||||
|
# © initOS GmbH 2014 |
||||
|
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl). |
||||
|
from . import web_note |
@ -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 |
||||
|
} |
@ -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 |
@ -0,0 +1,32 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data noupdate="0"> |
||||
|
<!-- Web Note User Group --> |
||||
|
<record model="res.groups" id="group_web_note_user"> |
||||
|
<field name="name">Web Note / User</field> |
||||
|
<field name="users" eval="[(4, ref('base.user_root'))]"/> |
||||
|
</record> |
||||
|
<!-- Record Rules for Notes --> |
||||
|
<record id="rule_web_note_private" model="ir.rule"> |
||||
|
<field name="name">Note Private</field> |
||||
|
<field name="model_id" ref="web_note.model_web_note"/> |
||||
|
<field name="groups" eval="[(4,ref('group_web_note_user'))]"/> |
||||
|
<field name="domain_force">['|',('type', '!=', 'private'),'&' ,('type', '=', 'private'), ('create_uid', '=', user.id)]</field> |
||||
|
<field name="perm_create" eval="True"/> |
||||
|
<field name="perm_read" eval="True"/> |
||||
|
<field name="perm_write" eval="True"/> |
||||
|
<field name="perm_unlink" eval="True"/> |
||||
|
</record> |
||||
|
<!-- Record Rules for Notes Containers --> |
||||
|
<record id="rule_web_note_container_private" model="ir.rule"> |
||||
|
<field name="name">Note Container Private</field> |
||||
|
<field name="model_id" ref="web_note.model_web_note_container"/> |
||||
|
<field name="groups" eval="[(4,ref('group_web_note_user'))]"/> |
||||
|
<field name="domain_force">['|',('type', '!=', 'private'),'&', ('type', '=', 'private'), ('create_uid', '=', user.id)]</field> |
||||
|
<field name="perm_create" eval="True"/> |
||||
|
<field name="perm_read" eval="True"/> |
||||
|
<field name="perm_write" eval="True"/> |
||||
|
<field name="perm_unlink" eval="True"/> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
@ -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, |
||||
|
} |
@ -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 |
@ -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 |
||||
|
} |
@ -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') |
||||
|
} |
@ -0,0 +1,16 @@ |
|||||
|
<?xml version="1.0"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="res_partner_view_buttons" model="ir.ui.view"> |
||||
|
<field name="name">res.partner.view.buttons</field> |
||||
|
<field name="model">res.partner</field> |
||||
|
<field name="inherit_id" ref="base.view_partner_form" /> |
||||
|
<field name="priority" eval="20"/> |
||||
|
<field name="arch" type="xml"> |
||||
|
<xpath expr="//notebook" position="after"> |
||||
|
<field name="notes"/> |
||||
|
</xpath> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
@ -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), |
||||
|
} |
@ -0,0 +1,32 @@ |
|||||
|
<?xml version="1.0" encoding="utf-8"?> |
||||
|
<openerp> |
||||
|
<data> |
||||
|
<record id="web_note_view_form" model="ir.ui.view"> |
||||
|
<field name="name">web.note.form</field> |
||||
|
<field name="model">web.note</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<form string="Note" version="7.0"> |
||||
|
<group> |
||||
|
<field name="type"/> |
||||
|
<field name="container_id" on_change="onchange_container_id(container_id, message)"/> |
||||
|
<field name="sequence" invisible="1"/> |
||||
|
</group> |
||||
|
<label for="message" string="Note"/> |
||||
|
<field name="message"/> |
||||
|
</form> |
||||
|
</field> |
||||
|
</record> |
||||
|
<record id="web_note_view_tree" model="ir.ui.view"> |
||||
|
<field name="name">web.note.tree</field> |
||||
|
<field name="model">web.note</field> |
||||
|
<field name="arch" type="xml"> |
||||
|
<tree string="Notes" version="7.0"> |
||||
|
<field name="sequence" widget="handle"/> |
||||
|
<field name="type"/> |
||||
|
<field name="container_id"/> |
||||
|
<field name="display_name"/> |
||||
|
</tree> |
||||
|
</field> |
||||
|
</record> |
||||
|
</data> |
||||
|
</openerp> |
Write
Preview
Loading…
Cancel
Save
Reference in new issue