summaryrefslogtreecommitdiff
path: root/addons/note/note.py
diff options
context:
space:
mode:
authorFabien Pinckaers <fp@openerp.com>2012-09-16 19:10:15 +0200
committerFabien Pinckaers <fp@openerp.com>2012-09-16 19:10:15 +0200
commit5000fffb1e9462b01de17a7d5f07d19bc7bad3f7 (patch)
tree710681d4aa681f84376255fe9e2c8fcb5e9ae524 /addons/note/note.py
parent8985e6aea9fc4d10609bc93270ebf97d26a89062 (diff)
parent378b77a5e4e79ac761e6c072591fd84a295eb1bf (diff)
[MERGE] merging notes + small cleaning
bzr revid: fp@openerp.com-20120916171015-e0n1lq2a5c10a0nb
Diffstat (limited to 'addons/note/note.py')
-rw-r--r--addons/note/note.py158
1 files changed, 125 insertions, 33 deletions
diff --git a/addons/note/note.py b/addons/note/note.py
index abc7dca297e..65848ed7828 100644
--- a/addons/note/note.py
+++ b/addons/note/note.py
@@ -21,16 +21,17 @@
from openerp.osv import osv, fields
from tools.translate import _
+import re
class note_stage(osv.osv):
""" Category of Note """
_name = "note.stage"
_description = "Note Stage"
_columns = {
- 'name': fields.char('Category Name', size=64, required=True),
+ 'name': fields.char('Stage Name', required=True),
'sequence': fields.integer('Sequence', help="Used to order the note stages"),
- 'user_id': fields.many2one('res.users', 'Owner', help="Owner of the note stage.", required=True, readonly=True),
- 'fold': fields.boolean('Folded'),
+ 'user_id': fields.many2one('res.users', 'Owner', help="Owner of the note stage.", required=True),
+ 'fold': fields.boolean('Folded by Default'),
}
_order = 'sequence asc'
_defaults = {
@@ -39,59 +40,150 @@ class note_stage(osv.osv):
'sequence' : 1,
}
+class note_tag(osv.osv):
+ _name = "note.tag"
+ _description = "Note Tag"
+ _columns = {
+ 'name' : fields.char('Tag Name', required=True),
+ }
+
class note_note(osv.osv):
""" Note """
_name = 'note.note'
- _inherit = ['mail.thread','pad.common']
- _pad_fields = ['note_pad']
+ _inherit = ['mail.thread']
_description = "Note"
- def _set_note_first_line(self, cr, uid, id, name, value, args, context=None):
- return self.write(cr, uid, [id], {'note': value}, context=context)
+ #writing method (no modification of values)
+ def name_create(self, cr, uid, name, context=None):
+ rec_id = self.create(cr, uid, {'memo': name}, context=context)
+ return self.name_get(cr, uid, [rec_id], context)[0]
- def _get_note_first_line(self, cr, uid, ids, name, args, context=None):
+ #read the first line (convert hml into text)
+ def _get_note_first_line(self, cr, uid, ids, name="", args={}, context=None):
res = {}
for note in self.browse(cr, uid, ids, context=context):
- res[note.id] = (note.note or '').strip().split('\n')[0]
+ text_note = (note.memo or '').strip().split('\n')[0]
+ text_note = re.sub(r'(\S?)(<br[ /]*>|<[/]?p>|<[/]?div>|<table>)[\s\S]*',r'\1',text_note)
+ text_note = re.sub(r'<[^>]+>','',text_note)
+ res[note.id] = text_note
return res
+ #unactivate a sticky note and record the date
+ def onclick_note_is_done(self, cr, uid, ids, context=None):
+ self.write(cr, uid, ids, { 'active' : False, 'date_done' : fields.date.today() })
+ self.message_post(cr, uid, ids[0], body='Note is done.', subject=False,
+ type='notification', parent_id=False, attachments=None, context=context)
+ return False
+
+ #activate a note
+ def onclick_note_not_done(self, cr, uid, ids, context=None):
+ self.write(cr, uid, ids, {'active' : True})
+ self.message_post(cr, uid, ids[0], body='Note has been activated.', subject=False,
+ type='notification', parent_id=False, attachments=None, context=context)
+ return False
+
+ #used for undisplay the follower if it's the current user
+ def _get_my_current_partner(self, cr, uid, ids, name, args, context=None):
+ user = self.pool.get('res.users').browse(cr, uid, uid, context=context)
+ pid = user.partner_id and user.partner_id.id or False
+ return dict.fromkeys(ids, pid)
+
+ #return the default stage for the uid user
def _get_default_stage_id(self,cr,uid,context=None):
- ids = self.pool.get('note.stage').search(cr,uid,[('user_id','=',uid)])
+ ids = self.pool.get('note.stage').search(cr,uid,[('user_id','=',uid)], context=context)
return ids and ids[0] or False
- def _read_group_stage_ids(self, cr, uid, ids, domain, read_group_order=None, access_rights_uid=None, context=None):
- access_rights_uid = access_rights_uid or uid
- stage_obj = self.pool.get('note.stage')
+ def _set_stage_per_user(self, cr, uid, id, name, value, args=None, context=None):
+ note = self.browse(cr, uid, id, context=context)
+ if not value: return False
+ return self.write(cr, uid, [id], {'stage_ids': [(4, value)]}, context=context)
- # only show stage groups not folded and owned by user
- search_domain = [('user_id', '=', uid)]
+ def _get_stage_per_user(self, cr, uid, ids, name, args, context=None):
+ result = dict.fromkeys(ids, False)
+ for record in self.browse(cr, uid, ids, context=context):
+ for stage in record.stage_ids:
+ if stage.user_id.id == uid:
+ result[record.id] = stage.id
+ return result
- stage_ids = stage_obj._search(cr, uid, search_domain, order=self._order, access_rights_uid=access_rights_uid, context=context)
- result = stage_obj.name_get(cr, access_rights_uid, stage_ids, context=context)
-
- fold = {}
- for stage in stage_obj.browse(cr, access_rights_uid, stage_ids, context=context):
- fold[stage.id] = stage.fold or False
- return result, fold
_columns = {
- 'name': fields.function(_get_note_first_line, fnct_inv=_set_note_first_line, string='Note Summary', type="text"),
- 'note': fields.text('Pad Content'),
- 'note_pad_url': fields.char('Pad Url', size=250),
+ 'name': fields.function(_get_note_first_line,
+ string='Note Summary',
+ type='text', store=True),
+ 'memo': fields.html('Note Content'),
'sequence': fields.integer('Sequence'),
- 'stage_id': fields.many2one('note.stage', 'Stage'),
+ 'stage_id': fields.function(_get_stage_per_user,
+ fnct_inv=_set_stage_per_user,
+ string='Stage',
+ type='many2one',
+ relation='note.stage'),
+ 'stage_ids': fields.many2many('note.stage','note_stage_rel','note_id','stage_id','Stages of Users'),
'active': fields.boolean('Active'),
+ 'date_done': fields.date('Date done'),
'color': fields.integer('Color Index'),
- # to be replaced by message_follower_ids
- 'follower_ids': fields.many2many('res.users', 'mail_subscription', 'res_id', 'user_id', 'Followers')
+ 'tag_ids' : fields.many2many('note.tag','note_tags_rel','note_id','tag_id','Tags'),
+ 'current_partner_id' : fields.function(_get_my_current_partner),
}
-
_defaults = {
'active' : 1,
'stage_id' : _get_default_stage_id,
- 'note_pad_url': lambda self, cr, uid, context: self.pad_generate_url(cr, uid, context),
}
- _order = 'sequence asc'
- _group_by_full = {
- 'stage_id' : _read_group_stage_ids,
+ _order = 'sequence'
+
+ def read_group(self, cr, uid, domain, fields, groupby, offset=0, limit=None, context=None, orderby=False):
+ if groupby and groupby[0]=="stage_id":
+
+ #search all stages
+ current_stage_ids = self.pool.get('note.stage').search(cr,uid,[('user_id','=',uid)], context=context)
+
+ if current_stage_ids: #if the user have some stages
+
+ #dict of stages: map les ids sur les noms
+ stage_name = dict(self.pool.get('note.stage').name_get(cr, uid, current_stage_ids, context=context))
+
+ result = [{ #notes by stage for stages user
+ '__context': {'group_by': groupby[1:]},
+ '__domain': domain + [('stage_ids.id', '=', current_stage_id)],
+ 'stage_id': (current_stage_id, stage_name[current_stage_id]),
+ 'stage_id_count': self.search(cr,uid, domain+[('stage_ids', '=', current_stage_id)], context=context, count=True)
+ } for current_stage_id in current_stage_ids]
+
+ #note without user's stage
+ nb_notes_ws = self.search(cr,uid, domain+[('stage_ids', 'not in', current_stage_ids)], context=context, count=True)
+ if nb_notes_ws:
+ result += [{ #notes for unknown stage and if stage_ids is not empty
+ '__context': {'group_by': groupby[1:]},
+ '__domain': domain + [('stage_ids', 'not in', current_stage_ids)],
+ 'stage_id': (0, 'Unknown'),
+ 'stage_id_count':nb_notes_ws
+ }]
+
+ else: # if stage_ids is empty
+
+ #note without user's stage
+ nb_notes_ws = self.search(cr,uid, domain, context=context, count=True)
+ if nb_notes_ws:
+ result = [{ #notes for unknown stage
+ '__context': {'group_by': groupby[1:]},
+ '__domain': domain,
+ 'stage_id': (0, 'Unknown'),
+ 'stage_id_count':nb_notes_ws
+ }]
+ else:
+ result = []
+ return result
+
+ else:
+ return super(note_note, self).read_group(self, cr, uid, domain, fields, groupby,
+ offset=offset, limit=limit, context=context, orderby=orderby)
+
+
+#upgrade config setting page to configure pad, fancy and tags mode
+class note_base_config_settings(osv.osv_memory):
+ _inherit = 'base.config.settings'
+ _columns = {
+ 'module_note_pad': fields.boolean('Use collaborative pads (etherpad)'),
+ 'group_note_fancy': fields.boolean('Use fancy layouts for notes', implied_group='note.group_note_fancy'),
+ 'group_note_tags': fields.boolean('Allow setting tags on notes', implied_group='note.group_note_tags'),
}