2008-10-22 20:07:32 +02:00
|
|
|
#This file is part of Tryton. The COPYRIGHT file at the top level of
|
|
|
|
|
#this repository contains the full copyright notices and license terms.
|
2008-04-08 11:26:36 +02:00
|
|
|
'Address'
|
2008-07-17 19:37:09 +02:00
|
|
|
from trytond.osv import fields, OSV
|
2008-04-08 11:26:36 +02:00
|
|
|
|
2008-02-26 12:41:13 +01:00
|
|
|
STATES = {
|
|
|
|
|
'readonly': "active == False",
|
|
|
|
|
}
|
2008-02-15 17:42:25 +01:00
|
|
|
|
2008-04-08 11:26:36 +02:00
|
|
|
|
2008-02-15 17:42:25 +01:00
|
|
|
class Address(OSV):
|
2008-05-21 18:12:20 +02:00
|
|
|
"Address"
|
2008-10-22 20:07:32 +02:00
|
|
|
_name = 'party.address'
|
2008-02-15 17:42:25 +01:00
|
|
|
_description = __doc__
|
2008-10-22 20:07:32 +02:00
|
|
|
party = fields.Many2One('party.party', 'Party', required=True,
|
2008-07-17 17:37:50 +02:00
|
|
|
ondelete='cascade', select=1, states=STATES)
|
2008-10-23 14:04:22 +02:00
|
|
|
name = fields.Char('Name', states=STATES)
|
|
|
|
|
street = fields.Char('Street', states=STATES)
|
|
|
|
|
streetbis = fields.Char('Street (bis)', states=STATES)
|
|
|
|
|
zip = fields.Char('Zip', change_default=True,
|
2008-02-26 12:41:13 +01:00
|
|
|
states=STATES)
|
2008-10-23 14:04:22 +02:00
|
|
|
city = fields.Char('City', states=STATES)
|
2008-10-22 20:07:32 +02:00
|
|
|
country = fields.Many2One('country.country', 'Country',
|
2008-02-26 12:41:13 +01:00
|
|
|
states=STATES)
|
2008-10-22 20:07:32 +02:00
|
|
|
subdivision = fields.Many2One("country.subdivision",
|
2008-10-15 19:05:05 +02:00
|
|
|
'Subdivision', domain="[('country', '=', country)]", states=STATES)
|
2008-02-26 12:41:13 +01:00
|
|
|
active = fields.Boolean('Active')
|
2008-03-05 20:40:29 +01:00
|
|
|
sequence = fields.Integer("Sequence")
|
2008-10-22 20:07:32 +02:00
|
|
|
full_address = fields.Function('get_full_address', type='text')
|
2008-03-05 20:40:29 +01:00
|
|
|
|
2008-04-22 17:48:57 +02:00
|
|
|
def __init__(self):
|
|
|
|
|
super(Address, self).__init__()
|
2008-05-21 18:12:20 +02:00
|
|
|
self._order.insert(0, ('party', 'ASC'))
|
2008-04-22 17:48:57 +02:00
|
|
|
self._order.insert(1, ('sequence', 'ASC'))
|
2008-07-17 19:37:09 +02:00
|
|
|
self._error_messages.update({
|
|
|
|
|
'write_party': 'You can not modify the party of an address!',
|
|
|
|
|
})
|
2008-04-22 17:48:57 +02:00
|
|
|
|
2008-02-26 16:23:30 +01:00
|
|
|
def default_active(self, cursor, user, context=None):
|
2008-10-23 13:38:29 +02:00
|
|
|
return True
|
2008-02-26 16:23:30 +01:00
|
|
|
|
2008-10-22 20:07:32 +02:00
|
|
|
def get_full_address(self, cursor, user, ids, name, arg, context=None):
|
|
|
|
|
if not ids:
|
2008-12-12 16:55:04 +01:00
|
|
|
return {}
|
2008-10-22 20:07:32 +02:00
|
|
|
res = {}
|
|
|
|
|
for address in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
res[address.id] = ''
|
|
|
|
|
if address.name:
|
|
|
|
|
res[address.id] += address.name
|
|
|
|
|
if address.street:
|
|
|
|
|
if res[address.id]:
|
|
|
|
|
res[address.id] += '\n'
|
|
|
|
|
res[address.id] += address.street
|
|
|
|
|
if address.streetbis:
|
|
|
|
|
if res[address.id]:
|
|
|
|
|
res[address.id] += '\n'
|
|
|
|
|
res[address.id] += address.streetbis
|
|
|
|
|
if address.zip or address.city:
|
|
|
|
|
if res[address.id]:
|
|
|
|
|
res[address.id] += '\n'
|
2008-11-12 22:24:15 +01:00
|
|
|
if address.zip:
|
|
|
|
|
res[address.id] += address.zip
|
|
|
|
|
if address.city:
|
|
|
|
|
if res[address.id][-1:] != '\n':
|
|
|
|
|
res[address.id] += ' '
|
|
|
|
|
res[address.id] += address.city
|
2008-10-22 20:07:32 +02:00
|
|
|
if address.country or address.subdivision:
|
|
|
|
|
if res[address.id]:
|
|
|
|
|
res[address.id] += '\n'
|
|
|
|
|
if address.subdivision:
|
2008-11-12 22:24:15 +01:00
|
|
|
res[address.id] += address.subdivision.name
|
2008-10-22 20:07:32 +02:00
|
|
|
if address.country:
|
2008-11-12 22:24:15 +01:00
|
|
|
if res[address.id][-1:] != '\n':
|
|
|
|
|
res[address.id] += ' '
|
2008-10-22 20:07:32 +02:00
|
|
|
res[address.id] += address.country.name
|
|
|
|
|
return res
|
|
|
|
|
|
2008-03-05 03:12:45 +01:00
|
|
|
def name_get(self, cursor, user, ids, context=None):
|
2008-04-08 11:26:36 +02:00
|
|
|
if not ids:
|
2008-03-05 03:12:45 +01:00
|
|
|
return []
|
2008-04-08 11:26:36 +02:00
|
|
|
if isinstance(ids, (int, long)):
|
|
|
|
|
ids = [ids]
|
2008-03-05 03:12:45 +01:00
|
|
|
res = []
|
2008-10-22 20:07:32 +02:00
|
|
|
for address in self.browse(cursor, user, ids, context=context):
|
2008-03-06 14:07:17 +01:00
|
|
|
res.append((address.id, ", ".join(x for x in [address.name,
|
2008-05-21 18:12:20 +02:00
|
|
|
address.party.name, address.zip, address.city] if x)))
|
2008-03-05 03:12:45 +01:00
|
|
|
return res
|
|
|
|
|
|
2008-03-06 14:07:17 +01:00
|
|
|
def name_search(self, cursor, user, name, args=None, operator='ilike',
|
2008-04-23 16:59:20 +02:00
|
|
|
context=None, limit=None):
|
2008-03-05 20:40:29 +01:00
|
|
|
if not args:
|
|
|
|
|
args=[]
|
|
|
|
|
|
2008-05-21 18:12:20 +02:00
|
|
|
ids = self.search(cursor, user, [('zip', '=', name)] + args,
|
2008-03-06 14:07:17 +01:00
|
|
|
limit=limit, context=context)
|
2008-03-05 20:40:29 +01:00
|
|
|
if not ids:
|
2008-05-21 18:12:20 +02:00
|
|
|
ids = self.search(cursor, user, [('city', operator, name)] + args,
|
2008-03-06 14:07:17 +01:00
|
|
|
limit=limit, context=context)
|
2008-03-05 20:40:29 +01:00
|
|
|
if name:
|
2008-05-21 18:12:20 +02:00
|
|
|
ids += self.search(cursor, user, [('name', operator, name)] + args,
|
2008-03-06 14:07:17 +01:00
|
|
|
limit=limit, context=context)
|
2008-05-21 18:12:20 +02:00
|
|
|
ids += self.search(cursor, user, [('party', operator, name)] + args,
|
2008-03-06 14:07:17 +01:00
|
|
|
limit=limit, context=context)
|
2008-03-05 20:40:29 +01:00
|
|
|
return self.name_get(cursor, user, ids, context=context)
|
|
|
|
|
|
2008-06-28 20:46:14 +02:00
|
|
|
def write(self, cursor, user, ids, vals, context=None):
|
|
|
|
|
if 'party' in vals:
|
2008-07-24 22:23:03 +02:00
|
|
|
if isinstance(ids, (int, long)):
|
|
|
|
|
ids = [ids]
|
2008-06-28 20:46:14 +02:00
|
|
|
for address in self.browse(cursor, user, ids, context=context):
|
|
|
|
|
if address.party.id != vals['party']:
|
2008-07-17 19:37:09 +02:00
|
|
|
self.raise_user_error(cursor, 'write_party',
|
|
|
|
|
context=context)
|
2008-06-28 20:46:14 +02:00
|
|
|
return super(Address, self).write(cursor, user, ids, vals,
|
|
|
|
|
context=context)
|
|
|
|
|
|
2008-02-15 17:42:25 +01:00
|
|
|
Address()
|