Active Records

This commit is contained in:
resteve 2012-10-09 08:52:39 +02:00
parent 4ac8ec495d
commit 62427ae670
8 changed files with 51 additions and 55 deletions

View File

@ -1,2 +1,5 @@
Version 2.6.0 - 2012-10-12
* Active Records
Version 2.4.0 - 2011-11-12
* Initial release

View File

@ -3,5 +3,13 @@
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.pool import Pool
from country import *
from address import *
def register():
Pool.register(
Address,
CountryZip,
module='country_zip', type_='model')

View File

@ -1,33 +0,0 @@
# -*- encoding: utf-8 -*-
#This file is part country_zip module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
{
'name' : 'Country, Subdivision and City from Zip',
'name_es_ES': 'País, subdivisión y ciudad a partir de código postal',
'name_ca_ES': 'País, subdivisió i ciutat a partir de codi postal',
'version' : '2.4.0',
'author' : 'Zikzakmedia SL',
'email': 'zikzak@zikzakmedia.com',
'website': 'http://www.zikzakmedia.com/',
'description': '''This module helps the encoding of addresses.
It computes the Country, Subdivision and City fields from the Zip code. These information must be previously encoded.
''',
'description_es_ES': '''Este módulo ayuda en la codificación de direcciones.
Calcula los campos país, subdivisión y ciudad a partir de código postal. Esta información debe ser previamente introducida.
''',
'description_ca_ES': '''Aquest mòdul ajuda a la codificació d'adreces.
Calcula els camps país, subdivisió i ciutat a partir de codi postal. Aquesta informació ha de ser previament intruïda.
''',
'depends' : [
'party',
'country',
],
'xml' : [
'country.xml',
],
'translation': [
'locale/ca_ES.po',
'locale/es_ES.po',
],
}

View File

@ -7,6 +7,8 @@ from trytond.model import ModelView, ModelSQL, fields
from trytond.pyson import Eval
from trytond.pool import Pool
__all__ = ['Address']
STATES = {
'readonly': ~Eval('active'),
}
@ -14,27 +16,24 @@ DEPENDS = ['active']
class Address(ModelSQL, ModelView):
"Address"
_name = 'party.address'
__name__ = 'party.address'
zip = fields.Char('Zip', states=STATES, depends=DEPENDS,
on_change=['zip', 'city', 'subdivision', 'country'])
def on_change_zip(self, vals):
pool = Pool()
country_zip_obj = pool.get('country.zip')
subdivision_obj = pool.get('country.subdivision')
def on_change_zip(self):
res = {}
if vals.get('zip'):
country_zips = country_zip_obj.search_read([('zip', '=', vals['zip'])])
Zip = Pool().get('country.zip')
Subdivision = Pool().get('country.subdivision')
if self.zip:
country_zips = Zip.search_read([('zip','=',self.zip)])
country_zip = country_zips and country_zips[0] or False
if country_zip:
res['city'] = country_zip['city']
if country_zip['subdivision']:
subdivision = subdivision_obj.read(country_zip['subdivision'])
if country_zip.get('subdivision'):
subdivisions = Subdivision.read([country_zip['subdivision']])
res['subdivision'] = country_zip['subdivision']
res['country'] = subdivision['country']
res['country'] = subdivisions[0]['country']
return res
Address()

View File

@ -5,14 +5,14 @@
from trytond.model import ModelView, ModelSQL, fields
__all__ = ['CountryZip']
class CountryZip(ModelSQL, ModelView):
"Country Zip"
_name = "country.zip"
_description = __doc__
__name__ = "country.zip"
zip = fields.Char('Zip', required=True, select=1)
city = fields.Char('City', select=1)
subdivision = fields.Many2One('country.subdivision', 'Subdivision',
ondelete='CASCADE', select=1)
CountryZip()

View File

@ -7,3 +7,8 @@ Party
*****
On change Zip field search city and subdivision associated in this zip.
Use
***
Add your zip (country code+number, example: ES08720) and press tab key. Country, subdivision and city are add information about zip

View File

@ -5,8 +5,15 @@
from setuptools import setup
import re
import os
import ConfigParser
info = eval(open('__tryton__.py').read())
config = ConfigParser.ConfigParser()
config.readfp(open('tryton.cfg'))
info = dict(config.items('tryton'))
for key in ('depends', 'extras_depend', 'xml'):
if key in info:
info[key] = info[key].strip().splitlines()
major_version, minor_version, _ = info.get('version', '0.0.1').split('.', 2)
major_version = int(major_version)
minor_version = int(minor_version)
@ -22,10 +29,10 @@ requires.append('trytond >= %s.%s, < %s.%s' %
setup(name='trytond_country_zip',
version=info.get('version', '0.0.1'),
description=info.get('description', ''),
author=info.get('author', ''),
author_email=info.get('email', ''),
url=info.get('website', ''),
description='Country, Subdivision and City from Zip',
author='Zikzakmedia SL',
author_email='zikzak@zikzakmedia.com',
url='http://www.zikzakmedia.com/',
download_url="https://bitbucket.org/zikzakmedia/trytond-country_zip",
package_dir={'trytond.modules.country_zip': '.'},
packages=[
@ -34,7 +41,7 @@ setup(name='trytond_country_zip',
],
package_data={
'trytond.modules.country_zip': info.get('xml', []) \
+ info.get('translation', []),
+ ['tryton.cfg', 'locale/*.po'],
},
classifiers=[
'Development Status :: 5 - Production/Stable',

7
tryton.cfg Normal file
View File

@ -0,0 +1,7 @@
[tryton]
version=2.6.0
depends:
party
country
xml:
country.xml