note : constraint for note min len

bzr revid: chm@openerp.com-20120907122506-fs6d3vvqowr2m6yk
This commit is contained in:
Christophe Matthieu
2012-09-07 14:25:06 +02:00
parent b49b72f00e
commit 7dd65a0f9b
2 changed files with 21 additions and 4 deletions
+17 -2
View File
@@ -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 = {
+4 -2
View File
@@ -104,8 +104,10 @@
<header>
<field name="stage_id" domain="[('user_id','=',uid)]" widget="statusbar" clickable="1"/>
</header>
<field name="note" widget="html" editor_width="100%%" editor_height="400px" nolabel="1"/>
<field name="tag_ids" widget="many2many_tags" group="group_note_tags" string="Tags"/>
<field colspan="4" name="note" widget="html" editor_width="100%%" editor_height="400px" nolabel="1"/>
<group>
<field name="tag_ids" widget="many2many_tags" group="group_note_tags"/>
</group>
<div class="oe_chatter">
<field name="message_ids" widget="mail_thread"/>
</div>