trytond-country_zip/country.py

27 lines
899 B
Python
Raw Permalink Normal View History

2012-07-18 11:01:45 +02:00
#This file is part country_zip module for Tryton.
2013-04-16 23:25:30 +02:00
#The COPYRIGHT file at the top level of this repository contains
2012-07-18 11:01:45 +02:00
#the full copyright notices and license terms.
2012-06-12 10:49:05 +02:00
from trytond.model import ModelView, ModelSQL, fields
2012-10-09 08:52:39 +02:00
__all__ = ['CountryZip']
2013-04-30 13:45:14 +02:00
2012-06-12 10:49:05 +02:00
class CountryZip(ModelSQL, ModelView):
2014-02-11 20:32:09 +01:00
'Country Zip'
__name__ = 'country.zip'
_rec_name = 'zip'
2012-06-12 10:49:05 +02:00
zip = fields.Char('Zip', required=True, select=1)
city = fields.Char('City', select=1)
subdivision = fields.Many2One('country.subdivision', 'Subdivision',
ondelete='CASCADE', select=1)
country = fields.Function(fields.Many2One('country.country', 'Country'),
'get_country', searcher='search_country'
)
def get_country(self, name):
return self.subdivision.country.id
@classmethod
def search_country(cls, name, clause):
return [('subdivision.%s' % name,) + tuple(clause[1:])]