e221350ebd765abfc7f8fc9ee6396ff48736c843
[burette/cyclofficine_pantin.git] / res_partner.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 # cyclofficine_pantin module for OpenERP, Custom module for La Cyclofficine
5 # de Pantin
6
7 # Copyright (C) 2015-2016 cyclofficine_pantin
8 # (<http://cyclocoop.org/index.php/les-ateliers/pantin/>)
9 #
10 # This file is a part of cyclofficine_pantin
11 #
12 # cyclofficine_pantin is free software: you can redistribute it and/or
13 # modify it under the terms of the GNU General Public License as published
14 # by the Free Software Foundation, either version 3 of the License, or (at
15 # your option) any later version.
16 #
17 # cyclofficine_pantin is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU General Public License for more details.
21 #
22 # You should have received a copy of the GNU General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #
25 ##############################################################################
26 from openerp.osv import osv
27 from openerp.osv import orm
28 from openerp.osv import fields
29
30
31 class Partner(orm.Model):
32 _inherit = 'res.partner'
33
34 _order = 'member_ident,name asc'
35
36 def _check_member_ident_length(self, cr, uid, ids, context=None):
37 # Check if member ident length is equal to sequence padding.
38 sequences = self.pool.get('ir.sequence')
39 id_mb_seq = sequences.search(cr, uid,
40 [('name', '=', 'Member identifier')],
41 limit=1, context=context)
42 mb_sequences = sequences.browse(cr, uid, id_mb_seq, context=context)
43
44 partners = self.browse(cr, uid, ids, context=context)
45 for mb_seq in mb_sequences:
46 padding = mb_seq.padding
47
48 for partner in partners:
49 if partner.member_ident:
50 mb_ident_length = len(partner.member_ident)
51 if not mb_ident_length == padding:
52 return False
53
54 return True
55
56 _constraints = [
57 (_check_member_ident_length,
58 'This member indentifier has not a good length.', ['member_ident']),
59 ]
60
61 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: