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
24 def location_name_search(self, cr, user, name='', args=None, operator='ilike',
25 context=None, limit=100):
31 ids = self.search(cr, user, [('code', 'ilike', name)] + args,
32 limit=limit, context=context)
34 search_domain = [('name', operator, name)]
35 if ids: search_domain.append(('id', 'not in', ids))
36 ids.extend(self.search(cr, user, search_domain + args,
37 limit=limit, context=context))
39 locations = self.name_get(cr, user, ids, context)
40 return sorted(locations, key=lambda (id, name): ids.index(id))
42 class Country(osv.osv):
44 _description = 'Country'
46 'name': fields.char('Country Name', size=64,
47 help='The full name of the country.', required=True, translate=True),
48 'code': fields.char('Country Code', size=2,
49 help='The ISO country code in two chars.\n'
50 'You can use this field for quick search.', required=True),
51 'address_format': fields.text('Address Format', help="""You can state here the usual format to use for the \
52 addresses belonging to this country.\n\nYou can use the python-style string patern with all the field of the address \
53 (for example, use '%(street)s' to display the field 'street') plus
54 \n%(state_name)s: the name of the state
55 \n%(state_code)s: the code of the state
56 \n%(country_name)s: the name of the country
57 \n%(country_code)s: the code of the country"""),
58 'currency_id': fields.many2one('res.currency', 'Currency'),
61 ('name_uniq', 'unique (name)',
62 'The name of the country must be unique !'),
63 ('code_uniq', 'unique (code)',
64 'The code of the country must be unique !')
67 'address_format': "%(street)s\n%(street2)s\n%(city)s %(state_code)s %(zip)s\n%(country_name)s",
71 name_search = location_name_search
73 def create(self, cursor, user, vals, context=None):
75 vals['code'] = vals['code'].upper()
76 return super(Country, self).create(cursor, user, vals,
79 def write(self, cursor, user, ids, vals, context=None):
81 vals['code'] = vals['code'].upper()
82 return super(Country, self).write(cursor, user, ids, vals,
86 class CountryState(osv.osv):
87 _description="Country state"
88 _name = 'res.country.state'
90 'country_id': fields.many2one('res.country', 'Country',
92 'name': fields.char('State Name', size=64, required=True),
93 'code': fields.char('State Code', size=3,
94 help='The state code in three chars.\n', required=True),
98 name_search = location_name_search
100 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: