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 openerp.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',
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.'),
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'),
59 'image': fields.binary("Image"),
60 'country_group_ids': fields.many2many('res.country.group', 'res_country_res_country_group_rel', 'res_country_id', 'res_country_group_id', string='Country Groups'),
63 ('name_uniq', 'unique (name)',
64 'The name of the country must be unique !'),
65 ('code_uniq', 'unique (code)',
66 'The code of the country must be unique !')
69 'address_format': "%(street)s\n%(street2)s\n%(city)s %(state_code)s %(zip)s\n%(country_name)s",
73 name_search = location_name_search
75 def create(self, cursor, user, vals, context=None):
77 vals['code'] = vals['code'].upper()
78 return super(Country, self).create(cursor, user, vals,
81 def write(self, cursor, user, ids, vals, context=None):
83 vals['code'] = vals['code'].upper()
84 return super(Country, self).write(cursor, user, ids, vals,
88 class CountryGroup(osv.osv):
89 _description="Country Group"
90 _name = 'res.country.group'
92 'name': fields.char('Name', required=True),
93 'country_ids': fields.many2many('res.country', 'res_country_res_country_group_rel', 'res_country_group_id', 'res_country_id', string='Countries'),
96 class CountryState(osv.osv):
97 _description="Country state"
98 _name = 'res.country.state'
100 'country_id': fields.many2one('res.country', 'Country',
102 'name': fields.char('State Name', required=True,
103 help='Administrative divisions of a country. E.g. Fed. State, Departement, Canton'),
104 'code': fields.char('State Code', size=3,
105 help='The state code in max. three chars.', required=True),
109 name_search = location_name_search
111 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: