From 7dd65a0f9ba6ca0c59addc22f2b3fed6e9f56504 Mon Sep 17 00:00:00 2001 From: Christophe Matthieu Date: Fri, 7 Sep 2012 14:25:06 +0200 Subject: [PATCH] note : constraint for note min len bzr revid: chm@openerp.com-20120907122506-fs6d3vvqowr2m6yk --- addons/note/note.py | 19 +++++++++++++++++-- addons/note/note_view.xml | 6 ++++-- 2 files changed, 21 insertions(+), 4 deletions(-) diff --git a/addons/note/note.py b/addons/note/note.py index 985cacd3404..1b5704eb601 100644 --- a/addons/note/note.py +++ b/addons/note/note.py @@ -55,10 +55,10 @@ class note_note(osv.osv): _inherit = ['mail.thread'] _description = "Note" - def _set_note_first_line(self, cr, uid, id, name, value, args, context=None): + def _set_note_first_line(self, cr, uid, id, name, value, args={}, context=None): return self.write(cr, uid, [id], {'note': value}, context=context) - def _get_note_first_line(self, cr, uid, ids, name, args, context=None): + def _get_note_first_line(self, cr, uid, ids, name="", args={}, context=None): res = {} for note in self.browse(cr, uid, ids, context=context): text_note = (note.note or '').strip().split('\n')[0] @@ -99,6 +99,16 @@ class note_note(osv.osv): return False + def _constraints_min_len(self, cr, uid, ids, context=None): + + res = self._get_note_first_line(cr, uid, ids, context=context) + + for note in self.browse(cr, uid, ids, context=context): + if len(res[note.id])<1 : + return False + + return True + _columns = { 'name': fields.function(_get_note_first_line, fnct_inv=_set_note_first_line, string='Note Summary', type='text'), @@ -120,9 +130,14 @@ class note_note(osv.osv): 'tag_ids' : fields.many2many('note.tag','note_tags_rel','note_id','tag_id','Tags'), } + _constraints = [ + (_constraints_min_len,'The title (first line on the note) must have at least one character.',['note']), + ] + _defaults = { 'active' : 1, 'stage_id' : _get_default_stage_id, + 'note': " " } _order = 'sequence asc' _group_by_full = { diff --git a/addons/note/note_view.xml b/addons/note/note_view.xml index b7e76c5fe5e..63dd8afcd1b 100644 --- a/addons/note/note_view.xml +++ b/addons/note/note_view.xml @@ -104,8 +104,10 @@
- - + + + +