Active Records

This commit is contained in:
resteve 2012-10-09 13:03:58 +02:00
parent 7001f82181
commit 9b82e689e9
6 changed files with 70 additions and 71 deletions

View file

@ -1,3 +1,4 @@
* Active Records
* setup.py trytond prefix. Change 2.4.0 version
* Add ca_ES locale
* Add es_ES locale

View file

@ -2,5 +2,18 @@
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from account import *
from configuration import *
from trytond.pool import Pool
from .account import *
from .configuration import *
def register():
Pool.register(
Configuration,
AccountTemplate,
CreateChartAccount,
UpdateChartStart,
module='account_code_digits', type_='model')
Pool.register(
CreateChart,
UpdateChart,
module='account_code_digits', type_='wizard')

View file

@ -1,28 +0,0 @@
#This file is part account_code_digits module for Tryton.
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
{
'name': 'Account Code Digits',
'version': '2.4.0',
'author': 'NaN·tic',
'email': 'info@nan-tic.com',
'website': 'http://www.nan-tic.com/',
'description': '''Adds the possibility to set the number of digits to be
used for account codes.''',
'depends': [
'ir',
'res',
'company',
'party',
'currency',
'account',
],
'xml': [
'account.xml',
'configuration.xml',
],
'translation': [
'locale/ca_ES.po',
'locale/es_ES.po',
],
}

View file

@ -3,18 +3,26 @@
#the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard
from trytond.pool import Pool
from trytond.pool import Pool, PoolMeta
class AccountTemplate(ModelSQL, ModelView):
_name = 'account.account.template'
__all__ = ['AccountTemplate', 'CreateChartAccount', 'CreateChart',
'UpdateChartStart', 'UpdateChart']
__metaclass__ = PoolMeta
def _get_account_value(self, template, account=None):
res = super(AccountTemplate, self)._get_account_value(template, account)
config_obj = Pool().get('account.configuration')
digits = config_obj.browse(1).default_account_code_digits
class AccountTemplate:
__name__ = 'account.account.template'
def _get_account_value(self, account=None):
res = super(AccountTemplate, self)._get_account_value(account)
Config = Pool().get('account.configuration')
digits = Config.browse([1])[0].default_account_code_digits
print res
print res.get('code')
print type(res.get('code'))
if res.get('code') and res.get('kind') != 'view' and digits != None:
digits = digits - len(res['code'])
digits = int(digits - len(res['code']))
print type(digits)
if digits > 0:
if '%' in res['code']:
res['code'] = res['code'].replace('%', '0'*digits)
@ -22,61 +30,54 @@ class AccountTemplate(ModelSQL, ModelView):
res['code'] = res['code'] + '0'*digits
return res
AccountTemplate()
class CreateChartAccount(ModelView):
_name = 'account.create_chart.account'
class CreateChartAccount:
__name__ = 'account.create_chart.account'
account_code_digits = fields.Integer('Account Code Digits', readonly=True,
help='Number of digits to be used for all non-view accounts. ' \
'(Defined at Account/Account Configuration/Account Code Digits)')
def default_account_code_digits(self):
config_obj = Pool().get('account.configuration')
config = config_obj.browse(1)
@staticmethod
def default_account_code_digits():
Config = Pool().get('account.configuration')
config = Config.browse([1])[0]
return config.default_account_code_digits
CreateChartAccount()
class CreateChart(Wizard):
_name = 'account.create_chart'
class CreateChart:
__name__ = 'account.create_chart'
def _action_create_account(self, datas):
digits = datas['form']['account_code_digits']
config_obj = Pool().get('account.configuration')
config_obj.write(1, {
Config = Pool().get('account.configuration')
Config.write(1, {
'default_account_code_digits': digits
})
return super(CreateChartAccount, self)._action_create_account(datas)
CreateChart()
class UpdateChartStart(ModelView):
_name = 'account.update_chart.start'
class UpdateChartStart:
__name__ = 'account.update_chart.start'
account_code_digits = fields.Integer('Account Code Digits', readonly=True,
help='Number of digits to be used for all non-view accounts. ' \
'(Defined at Account/Account Configuration/Account Code Digits)')
def default_account_code_digits(self):
config_obj = Pool().get('account.configuration')
config = config_obj.browse(1)
@staticmethod
def default_account_code_digits():
Config = Pool().get('account.configuration')
config = Config.browse([1])[0]
return config.default_account_code_digits
UpdateChartStart()
class UpdateChart(Wizard):
_name = 'account.update_chart'
class UpdateChart:
__name__ = 'account.update_chart'
def _action_update_account(self, datas):
digits = datas['form']['account_code_digits']
config_obj = Pool().get('account.configuration')
config_obj.write(1, {
Config = Pool().get('account.configuration')
Config.write(1, {
'default_account_code_digits': digits
})
return super(CreateChartAccount, self)._action_update_account(datas)
UpdateChart()

View file

@ -2,16 +2,16 @@
#The COPYRIGHT file at the top level of this repository contains
#the full copyright notices and license terms.
from trytond.model import ModelView, ModelSQL, ModelSingleton, fields
from trytond.pool import Pool
from trytond.transaction import Transaction
from trytond.pyson import Eval, Bool
from trytond.pool import Pool, PoolMeta
class Configuration(ModelSingleton, ModelSQL, ModelView):
_name = 'account.configuration'
__all__ = ['Configuration']
__metaclass__ = PoolMeta
class Configuration:
__name__ = 'account.configuration'
default_account_code_digits = fields.Property(
fields.Numeric('Account Code Digits', digits=(16, 0),
help='Number of digits to be used for all non-view accounts.'))
Configuration()

12
tryton.cfg Normal file
View file

@ -0,0 +1,12 @@
[tryton]
version=2.6.0
depends:
ir
res
company
party
currency
account
xml:
account.xml
configuration.xml