1 ##############################################################################
3 # Copyright (c) 2007 TINY SPRL. (http://tiny.be) All Rights Reserved.
6 # WARNING: This program as such is intended to be used by professional
7 # programmers who take the whole responsability of assessing all potential
8 # consequences resulting from its eventual inadequacies and bugs
9 # End users who are looking for a ready-to-use solution with commercial
10 # garantees and support are strongly adviced to contract a Free Software
13 # This program is Free Software; you can redistribute it and/or
14 # modify it under the terms of the GNU General Public License
15 # as published by the Free Software Foundation; either version 2
16 # of the License, or (at your option) any later version.
18 # This program is distributed in the hope that it will be useful,
19 # but WITHOUT ANY WARRANTY; without even the implied warranty of
20 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 # GNU General Public License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with this program; if not, write to the Free Software
25 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
27 ##############################################################################
29 from osv import fields, osv
32 class Country(osv.osv):
34 _description = 'Country'
36 'name': fields.char('Country Name', size=64,
37 help='The full name of the country.', required=True),
38 'code': fields.char('Country Code', size=2,
39 help='The ISO country code in two chars.\n'
40 'You can use this field for quick search.', required=True),
43 ('name_uniq', 'unique (name)',
44 'The name of the country must be unique !'),
45 ('code_uniq', 'unique (code)',
46 'The code of the country must be unique !')
49 def name_search(self, cr, user, name='', args=None, operator='ilike',
50 context=None, limit=80):
57 ids = self.search(cr, user, [('code', '=', name.upper())] + args,
58 limit=limit, context=context)
60 ids = self.search(cr, user, [('name', operator, name)] + args,
61 limit=limit, context=context)
62 return self.name_get(cr, user, ids, context)
65 def create(self, cursor, user, vals, context=None):
67 vals['code'] = vals['code'].upper()
68 return super(Country, self).create(cursor, user, vals,
71 def write(self, cursor, user, ids, vals, context=None):
73 vals['code'] = vals['code'].upper()
74 return super(Country, self).write(cursor, user, ids, vals,
80 class CountryState(osv.osv):
81 _description="Country state"
82 _name = 'res.country.state'
84 'country_id': fields.many2one('res.country', 'Country',
86 'name': fields.char('State Name', size=64, required=True),
87 'code': fields.char('State Code', size=3, required=True),
89 def name_search(self, cr, user, name='', args=None, operator='ilike',
90 context=None, limit=80):
95 ids = self.search(cr, user, [('code', '=', name)] + args, limit=limit,
98 ids = self.search(cr, user, [('name', operator, name)] + args,
99 limit=limit, context=context)
100 return self.name_get(cr, user, ids, context)