2012-08-13 17:04:29 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
##############################################################################
|
|
|
|
#
|
|
|
|
# OpenERP, Open Source Management Solution
|
|
|
|
# Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
|
|
|
|
#
|
|
|
|
# This program is free software: you can redistribute it and/or modify
|
|
|
|
# it under the terms of the GNU Affero General Public License as
|
|
|
|
# published by the Free Software Foundation, either version 3 of the
|
|
|
|
# License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU Affero General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Affero General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
##############################################################################
|
|
|
|
|
2013-10-09 16:29:20 +00:00
|
|
|
from openerp import SUPERUSER_ID
|
2012-08-13 17:04:29 +00:00
|
|
|
from openerp.osv import osv, fields
|
2012-11-06 12:34:42 +00:00
|
|
|
from openerp.tools import html2plaintext
|
2012-08-13 17:04:29 +00:00
|
|
|
|
2012-08-20 14:51:38 +00:00
|
|
|
class note_stage(osv.osv):
|
2012-08-13 17:04:29 +00:00
|
|
|
""" Category of Note """
|
|
|
|
_name = "note.stage"
|
|
|
|
_description = "Note Stage"
|
|
|
|
_columns = {
|
2012-11-02 11:42:41 +00:00
|
|
|
'name': fields.char('Stage Name', translate=True, required=True),
|
2012-08-13 17:04:29 +00:00
|
|
|
'sequence': fields.integer('Sequence', help="Used to order the note stages"),
|
2013-01-24 10:46:25 +00:00
|
|
|
'user_id': fields.many2one('res.users', 'Owner', help="Owner of the note stage.", required=True, ondelete='cascade'),
|
2012-09-16 17:10:15 +00:00
|
|
|
'fold': fields.boolean('Folded by Default'),
|
2012-08-13 17:04:29 +00:00
|
|
|
}
|
|
|
|
_order = 'sequence asc'
|
|
|
|
_defaults = {
|
|
|
|
'fold': 0,
|
|
|
|
'user_id': lambda self, cr, uid, ctx: uid,
|
|
|
|
'sequence' : 1,
|
|
|
|
}
|
|
|
|
|
2012-09-07 09:17:08 +00:00
|
|
|
class note_tag(osv.osv):
|
|
|
|
_name = "note.tag"
|
2012-09-16 17:10:15 +00:00
|
|
|
_description = "Note Tag"
|
2012-09-07 09:17:08 +00:00
|
|
|
_columns = {
|
2012-09-16 17:10:15 +00:00
|
|
|
'name' : fields.char('Tag Name', required=True),
|
2012-09-07 09:17:08 +00:00
|
|
|
}
|
|
|
|
|
2012-08-20 14:51:38 +00:00
|
|
|
class note_note(osv.osv):
|
2012-08-13 17:04:29 +00:00
|
|
|
""" Note """
|
|
|
|
_name = 'note.note'
|
2012-09-07 11:56:04 +00:00
|
|
|
_inherit = ['mail.thread']
|
2012-08-13 17:04:29 +00:00
|
|
|
_description = "Note"
|
|
|
|
|
2012-09-10 07:24:59 +00:00
|
|
|
#writing method (no modification of values)
|
2012-09-14 15:08:54 +00:00
|
|
|
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]
|
2012-09-05 09:54:35 +00:00
|
|
|
|
2012-09-10 07:24:59 +00:00
|
|
|
#read the first line (convert hml into text)
|
2012-09-07 12:25:06 +00:00
|
|
|
def _get_note_first_line(self, cr, uid, ids, name="", args={}, context=None):
|
2012-08-13 17:04:29 +00:00
|
|
|
res = {}
|
|
|
|
for note in self.browse(cr, uid, ids, context=context):
|
2012-09-19 14:35:53 +00:00
|
|
|
res[note.id] = (note.memo and html2plaintext(note.memo) or "").strip().replace('*','').split("\n")[0]
|
|
|
|
|
2012-08-13 17:04:29 +00:00
|
|
|
return res
|
2012-08-14 15:42:40 +00:00
|
|
|
|
2012-09-07 09:17:08 +00:00
|
|
|
def onclick_note_is_done(self, cr, uid, ids, context=None):
|
2012-12-19 17:02:11 +00:00
|
|
|
return self.write(cr, uid, ids, {'open': False, 'date_done': fields.date.today()}, context=context)
|
2012-09-07 09:17:08 +00:00
|
|
|
|
|
|
|
def onclick_note_not_done(self, cr, uid, ids, context=None):
|
2012-12-19 17:02:11 +00:00
|
|
|
return self.write(cr, uid, ids, {'open': True}, context=context)
|
|
|
|
|
2012-09-11 09:49:48 +00:00
|
|
|
#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
|
2012-09-13 17:19:38 +00:00
|
|
|
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)], context=context)
|
2012-09-03 22:37:41 +00:00
|
|
|
return ids and ids[0] or False
|
2012-09-13 17:19:38 +00:00
|
|
|
|
|
|
|
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
|
2012-09-19 07:45:00 +00:00
|
|
|
stage_ids = [value] + [stage.id for stage in note.stage_ids if stage.user_id.id != uid ]
|
2012-12-14 10:54:34 +00:00
|
|
|
return self.write(cr, uid, [id], {'stage_ids': [(6, 0, set(stage_ids))]}, context=context)
|
2012-09-13 17:19:38 +00:00
|
|
|
|
|
|
|
def _get_stage_per_user(self, cr, uid, ids, name, args, context=None):
|
|
|
|
result = dict.fromkeys(ids, False)
|
2012-09-11 09:49:48 +00:00
|
|
|
for record in self.browse(cr, uid, ids, context=context):
|
2012-09-13 17:19:38 +00:00
|
|
|
for stage in record.stage_ids:
|
|
|
|
if stage.user_id.id == uid:
|
|
|
|
result[record.id] = stage.id
|
2012-09-11 09:49:48 +00:00
|
|
|
return result
|
|
|
|
|
2012-08-13 17:04:29 +00:00
|
|
|
_columns = {
|
2012-09-11 09:49:48 +00:00
|
|
|
'name': fields.function(_get_note_first_line,
|
2012-09-16 17:10:15 +00:00
|
|
|
string='Note Summary',
|
2012-09-14 15:08:54 +00:00
|
|
|
type='text', store=True),
|
2012-09-16 17:10:15 +00:00
|
|
|
'memo': fields.html('Note Content'),
|
2012-08-13 17:04:29 +00:00
|
|
|
'sequence': fields.integer('Sequence'),
|
2012-09-13 17:19:38 +00:00
|
|
|
'stage_id': fields.function(_get_stage_per_user,
|
|
|
|
fnct_inv=_set_stage_per_user,
|
2012-09-16 17:10:15 +00:00
|
|
|
string='Stage',
|
2012-09-13 17:19:38 +00:00
|
|
|
type='many2one',
|
|
|
|
relation='note.stage'),
|
2012-09-16 17:10:15 +00:00
|
|
|
'stage_ids': fields.many2many('note.stage','note_stage_rel','note_id','stage_id','Stages of Users'),
|
2012-12-20 11:47:30 +00:00
|
|
|
'open': fields.boolean('Active', track_visibility='onchange'),
|
2012-09-07 09:17:08 +00:00
|
|
|
'date_done': fields.date('Date done'),
|
2012-08-13 17:04:29 +00:00
|
|
|
'color': fields.integer('Color Index'),
|
2012-09-07 09:17:08 +00:00
|
|
|
'tag_ids' : fields.many2many('note.tag','note_tags_rel','note_id','tag_id','Tags'),
|
2013-01-24 10:46:25 +00:00
|
|
|
'current_partner_id' : fields.function(_get_my_current_partner, type="many2one", relation='res.partner', string="Owner"),
|
2012-08-13 17:04:29 +00:00
|
|
|
}
|
|
|
|
_defaults = {
|
2012-09-17 12:30:54 +00:00
|
|
|
'open' : 1,
|
2012-08-13 17:04:29 +00:00
|
|
|
'stage_id' : _get_default_stage_id,
|
|
|
|
}
|
2012-09-16 17:10:15 +00:00
|
|
|
_order = 'sequence'
|
2012-09-11 09:49:48 +00:00
|
|
|
|
2012-09-13 17:19:38 +00:00
|
|
|
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
|
2012-09-14 10:14:18 +00:00
|
|
|
current_stage_ids = self.pool.get('note.stage').search(cr,uid,[('user_id','=',uid)], context=context)
|
2012-09-13 17:19:38 +00:00
|
|
|
|
2012-09-14 10:14:18 +00:00
|
|
|
if current_stage_ids: #if the user have some stages
|
2014-04-17 11:04:35 +00:00
|
|
|
stages = self.pool['note.stage'].browse(cr, uid, current_stage_ids, context=context)
|
2012-09-14 08:15:15 +00:00
|
|
|
|
|
|
|
result = [{ #notes by stage for stages user
|
|
|
|
'__context': {'group_by': groupby[1:]},
|
2014-04-17 11:04:35 +00:00
|
|
|
'__domain': domain + [('stage_ids.id', '=', stage.id)],
|
|
|
|
'stage_id': (stage.id, stage.name),
|
|
|
|
'stage_id_count': self.search(cr,uid, domain+[('stage_ids', '=', stage.id)], context=context, count=True),
|
|
|
|
'__fold': stage.fold,
|
|
|
|
} for stage in stages]
|
2012-09-14 08:15:15 +00:00
|
|
|
|
|
|
|
#note without user's stage
|
2012-09-14 10:14:18 +00:00
|
|
|
nb_notes_ws = self.search(cr,uid, domain+[('stage_ids', 'not in', current_stage_ids)], context=context, count=True)
|
2012-09-14 08:15:15 +00:00
|
|
|
if nb_notes_ws:
|
2013-04-22 11:24:38 +00:00
|
|
|
# add note to the first column if it's the first stage
|
|
|
|
dom_not_in = ('stage_ids', 'not in', current_stage_ids)
|
|
|
|
if result and result[0]['stage_id'][0] == current_stage_ids[0]:
|
|
|
|
dom_in = result[0]['__domain'].pop()
|
|
|
|
result[0]['__domain'] = domain + ['|', dom_in, dom_not_in]
|
2013-11-27 15:18:15 +00:00
|
|
|
result[0]['stage_id_count'] += nb_notes_ws
|
2013-04-22 11:24:38 +00:00
|
|
|
else:
|
|
|
|
# add the first stage column
|
|
|
|
result = [{
|
|
|
|
'__context': {'group_by': groupby[1:]},
|
|
|
|
'__domain': domain + [dom_not_in],
|
2014-04-17 11:04:35 +00:00
|
|
|
'stage_id': (stages[0].id, stages[0].name),
|
|
|
|
'stage_id_count':nb_notes_ws,
|
|
|
|
'__fold': stages[0].name,
|
2013-04-22 11:24:38 +00:00
|
|
|
}] + result
|
2012-09-14 08:15:15 +00:00
|
|
|
|
|
|
|
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,
|
2013-04-22 11:24:38 +00:00
|
|
|
'stage_id': False,
|
2012-09-14 08:15:15 +00:00
|
|
|
'stage_id_count':nb_notes_ws
|
|
|
|
}]
|
|
|
|
else:
|
|
|
|
result = []
|
2012-09-13 17:19:38 +00:00
|
|
|
return result
|
|
|
|
|
|
|
|
else:
|
|
|
|
return super(note_note, self).read_group(self, cr, uid, domain, fields, groupby,
|
|
|
|
offset=offset, limit=limit, context=context, orderby=orderby)
|
|
|
|
|
|
|
|
|
2012-09-11 09:49:48 +00:00
|
|
|
#upgrade config setting page to configure pad, fancy and tags mode
|
|
|
|
class note_base_config_settings(osv.osv_memory):
|
|
|
|
_inherit = 'base.config.settings'
|
|
|
|
_columns = {
|
2012-09-16 17:10:15 +00:00
|
|
|
'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'),
|
2012-09-11 09:49:48 +00:00
|
|
|
}
|
2012-11-01 12:22:11 +00:00
|
|
|
|
|
|
|
class res_users(osv.Model):
|
|
|
|
_name = 'res.users'
|
|
|
|
_inherit = ['res.users']
|
|
|
|
def create(self, cr, uid, data, context=None):
|
|
|
|
user_id = super(res_users, self).create(cr, uid, data, context=context)
|
2013-10-09 16:29:20 +00:00
|
|
|
note_obj = self.pool['note.stage']
|
|
|
|
data_obj = self.pool['ir.model.data']
|
|
|
|
is_employee = self.has_group(cr, user_id, 'base.group_user')
|
|
|
|
if is_employee:
|
|
|
|
for n in range(5):
|
|
|
|
xmlid = 'note_stage_%02d' % (n,)
|
2013-04-23 17:20:13 +00:00
|
|
|
try:
|
2013-10-09 16:29:20 +00:00
|
|
|
_model, stage_id = data_obj.get_object_reference(cr, SUPERUSER_ID, 'note', xmlid)
|
2013-04-23 17:20:13 +00:00
|
|
|
except ValueError:
|
|
|
|
continue
|
2013-10-09 16:29:20 +00:00
|
|
|
note_obj.copy(cr, SUPERUSER_ID, stage_id, default={'user_id': user_id}, context=context)
|
2013-04-23 17:20:13 +00:00
|
|
|
return user_id
|