1 # -*- coding: utf-8 -*-
2 ##############################################################################
4 # OpenERP, Open Source Management Solution
5 # Copyright (C) 2004-2009 Tiny SPRL (<http://tiny.be>).
7 # This program is free software: you can redistribute it and/or modify
8 # it under the terms of the GNU Affero General Public License as
9 # published by the Free Software Foundation, either version 3 of the
10 # License, or (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU Affero General Public License for more details.
17 # You should have received a copy of the GNU Affero General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
20 ##############################################################################
22 from osv import fields, osv
25 class Country(osv.osv):
27 _description = 'Country'
29 'name': fields.char('Country Name', size=64,
30 help='The full name of the country.', required=True, translate=True),
31 'code': fields.char('Country Code', size=2,
32 help='The ISO country code in two chars.\n'
33 'You can use this field for quick search.', required=True),
34 'address_format': fields.text('Address Format', help="""You can state here the usual format to use for the \
35 addresses belonging to this country.\n\nYou can use the python-style string patern with all the field of the address \
36 (for example, use '%(street)s' to display the field 'street') plus
37 \n%(state_name)s: the name of the state
38 \n%(state_code)s: the code of the state
39 \n%(country_name)s: the name of the country
40 \n%(country_code)s: the code of the country"""),
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 'address_format': "%(street)s\n%(street2)s\n%(city)s,%(state_code)s %(zip)s\n%(country_name)s",
52 def name_search(self, cr, user, name='', args=None, operator='ilike',
53 context=None, limit=100):
60 ids = self.search(cr, user, [('code', 'ilike', name)] + args,
61 limit=limit, context=context)
63 ids = self.search(cr, user, [('name', operator, name)] + args,
64 limit=limit, context=context)
65 return self.name_get(cr, user, ids, context)
68 def create(self, cursor, user, vals, context=None):
70 vals['code'] = vals['code'].upper()
71 return super(Country, self).create(cursor, user, vals,
74 def write(self, cursor, user, ids, vals, context=None):
76 vals['code'] = vals['code'].upper()
77 return super(Country, self).write(cursor, user, ids, vals,
83 class CountryState(osv.osv):
84 _description="Country state"
85 _name = 'res.country.state'
87 'country_id': fields.many2one('res.country', 'Country',
89 'name': fields.char('State Name', size=64, required=True,
90 help='Administrative divisions of a country. E.g. Fed. State, Departement, Canton'),
91 'code': fields.char('State Code', size=3,
92 help='The state code in max. three chars.', required=True),
94 def name_search(self, cr, user, name='', args=None, operator='ilike',
95 context=None, limit=100):
100 ids = self.search(cr, user, [('code', 'ilike', name)] + args, limit=limit,
103 ids = self.search(cr, user, [('name', operator, name)] + args,
104 limit=limit, context=context)
105 return self.name_get(cr, user, ids, context)
112 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: