1 # -*- encoding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>). All Rights Reserved
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 ##############################################################################
23 from osv import fields, osv
26 class Country(osv.osv):
28 _description = 'Country'
30 'name': fields.char('Country Name', size=64,
31 help='The full name of the country.', required=True, translate=True),
32 'code': fields.char('Country Code', size=2,
33 help='The ISO country code in two chars.\n'
34 'You can use this field for quick search.', required=True),
37 ('name_uniq', 'unique (name)',
38 'The name of the country must be unique !'),
39 ('code_uniq', 'unique (code)',
40 'The code of the country must be unique !')
43 def name_search(self, cr, user, name='', args=None, operator='ilike',
44 context=None, limit=80):
51 ids = self.search(cr, user, [('code', '=', name)] + args,
52 limit=limit, context=context)
54 ids = self.search(cr, user, [('name', operator, name)] + args,
55 limit=limit, context=context)
56 return self.name_get(cr, user, ids, context)
59 def create(self, cursor, user, vals, context=None):
61 vals['code'] = vals['code'].upper()
62 return super(Country, self).create(cursor, user, vals,
65 def write(self, cursor, user, ids, vals, context=None):
67 vals['code'] = vals['code'].upper()
68 return super(Country, self).write(cursor, user, ids, vals,
74 class CountryState(osv.osv):
75 _description="Country state"
76 _name = 'res.country.state'
78 'country_id': fields.many2one('res.country', 'Country',
80 'name': fields.char('State Name', size=64, required=True),
81 'code': fields.char('State Code', size=3,
82 help='The state code in three chars.\n', required=True),
84 def name_search(self, cr, user, name='', args=None, operator='ilike',
85 context=None, limit=80):
90 ids = self.search(cr, user, [('code', '=', name)] + args, limit=limit,
93 ids = self.search(cr, user, [('name', operator, name)] + args,
94 limit=limit, context=context)
95 return self.name_get(cr, user, ids, context)
102 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: