Active Records

This commit is contained in:
resteve 2012-10-11 12:12:07 +02:00
parent 2ded0833a0
commit 80fd8ca41a
11 changed files with 96 additions and 104 deletions

View File

@ -1,3 +1,6 @@
* Active Record
* Simplify module information with python configuration
Version 2.1.1 - 2012-01-26
* Point release

View File

@ -5,7 +5,5 @@ include COPYRIGHT
include CHANGELOG
include LICENSE
include *.xml
include *.odt
include locale/*.po
include doc/*
include icons/*

1
README
View File

@ -2,7 +2,6 @@ trytond_party_bank
=============================
Module for adding banks to parties for the Tryton application platform.
See __tryton__.py
Installing
----------

View File

@ -1,5 +1,14 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
#This file is part party_bank module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.pool import Pool
from bank import *
from party import *
def register():
Pool.register(
Bank,
BankAccount,
Party,
module='party_bank', type_='model')

View File

@ -1,37 +0,0 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
{
'name': 'Party Bank',
'name_ca_ES': 'Banc de tercers',
'name_de_DE': 'Partei Bankverbindungen',
'name_es_ES': 'Banco de terceros',
'version': '2.1.2',
'author': 'virtual things',
'email': 'info@virtual-things.biz',
'website': 'http://www.virtual-things.biz/',
'description': '''
- Allows the management of bank accounts for parties
''',
'description_ca_ES': '''
- Permet la gestió de comptes bancaris de tercers
''',
'description_de_DE': '''
- Ermöglicht die Verwaltung von Bankverbindungen für Parteien
''',
'description_es_ES': '''Banco de terceros
- Permite la gestión de cuentas bancarias de terceros
''',
'depends': [
'party',
'currency'
],
'xml': [
'bank.xml',
'party.xml'
],
'translation': [
'locale/ca_ES.po',
'locale/de_DE.po',
'locale/es_ES.po',
],
}

85
bank.py
View File

@ -1,16 +1,17 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
#This file is part party_bank module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from trytond.backend import TableHandler
from trytond.pyson import Not, Eval, Bool
from trytond.transaction import Transaction
from trytond.pool import Pool
__all__ = ['Bank', 'BankAccount']
class Bank(ModelSQL, ModelView):
'Bank'
_name = 'bank.bank'
_description = __doc__
__name__ = 'bank.bank'
_inherits = {'party.party': 'party'}
_rec_name = 'bank_code'
@ -25,42 +26,41 @@ class Bank(ModelSQL, ModelView):
'required': Not(Bool(Eval('bank_code')))
}, depends=['bank_code'])
def get_rec_name(self, ids, name):
@classmethod
def get_rec_name(cls, records, name):
res = {}
if not ids:
if not records:
return res
for bank in self.browse(ids):
for bank in records:
res[bank.id] = ", ".join(
x for x in [bank.name, bank.bank_code, bank.bic] if x)
return res
def search_rec_name(self, name, clause):
ids = self.search([
@classmethod
def search_rec_name(cls, name, clause):
ids = cls.search([
('name',) + tuple(clause[1:]),
], limit=1)
if ids:
return [('name',) + tuple(clause[1:])]
else:
ids = self.search([
ids = cls.search([
('bank_code',) + tuple(clause[1:]),
], limit=1)
if ids:
return [('bank_code',) + tuple(clause[1:])]
else:
ids = self.search([
ids = cls.search([
('bic',) + tuple(clause[1:]),
], limit=1)
if ids:
return [('bic',) + tuple(clause[1:])]
return [(self._rec_name,) + tuple(clause[1:])]
Bank()
return [(cls._rec_name,) + tuple(clause[1:])]
class BankAccount(ModelSQL, ModelView):
'Bank Account'
_name = 'bank.account'
_description = __doc__
__name__ = 'bank.account'
_rec_name = 'code'
default = fields.Boolean('Default', help="Default Bank Account")
@ -90,10 +90,11 @@ class BankAccount(ModelSQL, ModelView):
'Subdivision', domain=[('country', '=', Eval('country'))],
depends=['country'])
def init(self, module_name):
super(BankAccount, self).init(module_name)
@classmethod
def __register__(cls, module_name):
super(BankAccount, cls).__register__(module_name)
cursor = Transaction().cursor
table = TableHandler(cursor, self, module_name)
table = TableHandler(cursor, cls, module_name)
# Migration for existing databases
# Set column 'currency' not required
table.not_null_action('currency', action='remove')
@ -101,52 +102,52 @@ class BankAccount(ModelSQL, ModelView):
if table.column_exist('name'):
table.drop_column('name', exception=True)
def default_default(self):
@staticmethod
def default_default():
return True
def get_rec_name(self, ids, name):
@classmethod
def get_rec_name(cls, records, name):
res = {}
if not ids:
if not records:
return res
for account in self.browse(ids):
for account in records:
res[account.id] = ", ".join(x for x in [account.bank.name,
account.code, account.bank_code, account.iban,
account.bic] if x)
return res
def get_bank_code(self, ids, name):
@classmethod
def get_bank_code(cls, records, name):
res = {}
for account in self.browse(ids):
for account in records:
res[account.id] = account.bank.bank_code
return res
def get_bic(self, ids, name):
@classmethod
def get_bic(cls, records, name):
res = {}
for account in self.browse(ids):
for account in records:
res[account.id] = account.bank.bic
return res
def on_change_bank(self, vals):
bank_obj = Pool().get('bank.bank')
def on_change_bank(self):
res = {
'bank_code': False,
'bic': False
}
if vals.get('bank'):
bank = bank_obj.browse(vals['bank'])
print self.bank
if self.bank:
bank = self.bank
if bank:
res['bank_code'] = bank.bank_code
res['bic'] = bank.bic
print "==="
print res
return res
def on_change_country(self, vals):
subdivision_obj = Pool().get('country.subdivision')
result = dict((k, vals.get(k))
for k in ('country', 'subdivision'))
if vals['subdivision']:
subdivision = subdivision_obj.browse(vals['subdivision'])
if subdivision.country.id != vals['country']:
result['subdivision'] = None
return result
BankAccount()
def on_change_country(self):
if (self.subdivision
and self.subdivision.country != self.country):
return {'subdivision': None}
return {}

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of this
repository contains the full copyright notices and license terms. -->
<!-- This file is part party_bank module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="bank_view_tree">

View File

@ -1,10 +1,14 @@
#This file is part of Tryton. The COPYRIGHT file at the top level of
#this repository contains the full copyright notices and license terms.
#This file is part party_bank module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from trytond.pool import PoolMeta
class Party(ModelSQL, ModelView):
_name = 'party.party'
__all__ = ['Party']
__metaclass__ = PoolMeta
class Party:
__name__ = 'party.party'
bank_accounts = fields.One2Many('bank.account', 'party', 'Bank Accounts')
Party()

View File

@ -1,6 +1,6 @@
<?xml version="1.0"?>
<!-- This file is part of Tryton. The COPYRIGHT file at the top level of this
repository contains the full copyright notices and license terms. -->
<!-- This file is part party_bank module for Tryton.
The COPYRIGHT file at the top level of this repository contains the full copyright notices and license terms. -->
<tryton>
<data>
<record model="ir.ui.view" id="party_view_form">

View File

@ -1,11 +1,19 @@
#!/usr/bin/env python
# This file is part of Tryton. The COPYRIGHT file at the top level of
# this repository contains the full copyright notices and license terms.
#This file is part party_bank module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
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)
@ -21,12 +29,11 @@ requires.append('trytond >= %s.%s, < %s.%s' %
setup(name='trytond_party_bank',
version=info.get('version', '0.0.1'),
description=info.get('description', ''),
author=info.get('author', ''),
author_email=info.get('email', ''),
url=info.get('website', ''),
download_url="http://downloads.tryton.org/" + \
info.get('version', '0.0.1').rsplit('.', 1)[0] + '/',
description='Party Bank',
author='Virtual Things',
author_email='info@virtual-things.biz',
url='http://www.virtual-things.biz',
download_url='https://bitbucket.org/ukoma/party_bank',
package_dir={'trytond.modules.party_bank': '.'},
packages=[
'trytond.modules.party_bank',
@ -34,7 +41,7 @@ setup(name='trytond_party_bank',
],
package_data={
'trytond.modules.party_bank': info.get('xml', []) \
+ info.get('translation', []),
+ ['tryton.cfg', 'locale/*.po'],
},
classifiers=[
'Development Status :: 5 - Production/Stable',

8
tryton.cfg Normal file
View File

@ -0,0 +1,8 @@
[tryton]
version=2.6.0
depends:
party
currency
xml:
bank.xml
party.xml