diff --git a/INSTALL b/INSTALL index 62edd4b..a2d2cf9 100644 --- a/INSTALL +++ b/INSTALL @@ -4,18 +4,15 @@ Installing trytond_account_code_digits Prerequisites ------------- - * Python 2.5 or later (http://www.python.org/) + * Python 2.7 or later (http://www.python.org/) * python-dateutil (http://labix.org/python-dateutil) * trytond (http://www.tryton.org/) - * trytond_company (http://www.tryton.org/) - * trytond_party (http://www.tryton.org/) - * trytond_currency (http://www.tryton.org/) * trytond_account (http://www.tryton.org/) Installation ------------ -Once you've downloaded and unpacked the trytond_account_code_digits source +Once you've downloaded and unpacked the trytond_account_code_digits source release, enter the directory where the archive was unpacked, and run: python setup.py install diff --git a/__init__.py b/__init__.py index 5759645..f2a5143 100644 --- a/__init__.py +++ b/__init__.py @@ -1,20 +1,21 @@ -#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. +# 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. from trytond.pool import Pool -from .account import * -from .configuration import * +from . import account + def register(): Pool.register( - Configuration, - AccountTemplate, - Account, - CreateChartAccount, - UpdateChartStart, + account.Configuration, + account.ConfigurationDefaultAccount, + account.AccountTemplate, + account.Account, + account.CreateChartAccount, + account.UpdateChartStart, module='account_code_digits', type_='model') Pool.register( - CreateChart, - UpdateChart, + account.CreateChart, + account.UpdateChart, module='account_code_digits', type_='wizard') diff --git a/account.py b/account.py index f4a2058..b0e5d18 100644 --- a/account.py +++ b/account.py @@ -1,11 +1,44 @@ -#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. +# 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. from trytond.model import fields from trytond.pool import Pool, PoolMeta -__all__ = ['AccountTemplate', 'Account', 'CreateChartAccount', 'CreateChart', - 'UpdateChartStart', 'UpdateChart'] +__all__ = ['Configuration', 'AccountTemplate', 'Account', + 'CreateChartAccount', 'CreateChart', 'UpdateChartStart', 'UpdateChart'] + + +class Configuration: + __metaclass__ = PoolMeta + __name__ = 'account.configuration' + + default_account_code_digits = fields.MultiValue( + fields.Integer( + "Account Code Digits", + help='Number of digits to be used for all non-view accounts.')) + force_digits = fields.Boolean('Force Digits', + help='If marked it won\'t be allowed to create a non-view account' + ' with a diferent number of digits than the number used on the ' + 'selected on the chart creation.') + + @classmethod + def multivalue_model(cls, field): + pool = Pool() + if field == 'default_account_code_digits': + return pool.get('account.configuration.default_account') + return super(Configuration, cls).multivalue_model(field) + + +class ConfigurationDefaultAccount: + __metaclass__ = PoolMeta + __name__ = 'account.configuration.default_account' + default_account_code_digits = fields.Integer( + "Account Code Digits", + domain=[ + 'OR', + ('default_account_code_digits', '>=', 0), + ('default_account_code_digits', '=', None), + ]) class AccountTemplate: @@ -13,10 +46,16 @@ class AccountTemplate: __name__ = 'account.account.template' def _get_account_value(self, account=None): + pool = Pool() + Config = pool.get('account.configuration') + config = Config(1) + res = super(AccountTemplate, self)._get_account_value(account) - Config = Pool().get('account.configuration') - digits = Config.browse([1])[0].default_account_code_digits - if res.get('code') and res.get('kind') != 'view' and digits != None: + + digits = config.default_account_code_digits + if (res.get('code') + and res.get('kind') != 'view' + and digits is not None): digits = int(digits - len(res['code'])) if '%' in res['code']: res['code'] = res['code'].replace('%', '0' * (digits + 1)) @@ -43,15 +82,16 @@ class Account: @classmethod def validate(cls, accounts): - config = Pool().get('account.configuration').get_singleton() + pool = Pool() + Config = pool.get('account.configuration') + config = Config(1) super(Account, cls).validate(accounts) - if (config and config.default_account_code_digits and - config.force_digits): + if config.default_account_code_digits and config.force_digits: for account in accounts: account.check_digits(config.default_account_code_digits) def check_digits(self, digits): - #Only the first item of code is checked: "570000 (1)" -> "570000" + # Only the first item of code is checked: "570000 (1)" -> "570000" code = self.code.split(' ')[0] if self.kind != 'view' and len(code) != digits: self.raise_user_error('invalid_code_digits', error_args={ @@ -68,10 +108,12 @@ class CreateChartAccount: account_code_digits = fields.Integer('Account Code Digits', help='Number of digits to be used for all non-view accounts.') - @staticmethod - def default_account_code_digits(): - config = Pool().get('account.configuration').get_singleton() - return config.default_account_code_digits if config else None + @classmethod + def default_account_code_digits(cls): + pool = Pool() + Config = pool.get('account.configuration') + config = Config(1) + return config.default_account_code_digits class CreateChart: @@ -79,11 +121,12 @@ class CreateChart: __name__ = 'account.create_chart' def transition_create_account(self): + pool = Pool() + Config = pool.get('account.configuration') if hasattr(self.account, 'account_code_digits'): - digits = self.account.account_code_digits - Config = Pool().get('account.configuration') - config = Config.get_singleton() or Config() - config.default_account_code_digits = digits + config = Config(1) + config.default_account_code_digits = ( + self.account.account_code_digits) config.save() return super(CreateChart, self).transition_create_account() @@ -95,10 +138,12 @@ class UpdateChartStart: account_code_digits = fields.Integer('Account Code Digits', help='Number of digits to be used for all non-view accounts.') - @staticmethod - def default_account_code_digits(): - config = Pool().get('account.configuration').get_singleton() - return config.default_account_code_digits if config else None + @classmethod + def default_account_code_digits(cls): + pool = Pool() + Config = pool.get('account.configuration') + config = Config(1) + return config.default_account_code_digits class UpdateChart: @@ -106,9 +151,9 @@ class UpdateChart: __name__ = 'account.update_chart' def transition_update(self): - digits = self.start.account_code_digits - Config = Pool().get('account.configuration') - config = Config.get_singleton() or Config() - config.default_account_code_digits = digits + pool = Pool() + Config = pool.get('account.configuration') + config = Config(1) + config.default_account_code_digits = self.start.account_code_digits config.save() return super(UpdateChart, self).transition_update() diff --git a/account.xml b/account.xml index 6b13342..0771a50 100644 --- a/account.xml +++ b/account.xml @@ -1,13 +1,21 @@ +The COPYRIGHT file at the top level of this repository contains the full +copyright notices and license terms. --> + + account.configuration + + configuration_form + + account.create_chart.account create_chart_account_form + account.update_chart.start diff --git a/configuration.py b/configuration.py deleted file mode 100644 index 9b21beb..0000000 --- a/configuration.py +++ /dev/null @@ -1,26 +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. -from trytond.model import fields -from trytond.pool import PoolMeta -from trytond.pyson import Eval - - -__all__ = ['Configuration'] - - -class Configuration: - __metaclass__ = PoolMeta - __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.')) - force_digits = fields.Boolean('Force Digits', - help='If marked it won\'t be allowed to create a non-view account' - ' with a diferent number of digits than the number used on the ' - 'selected on the chart creation.', - states={ - 'invisible': Eval('default_account_code_digits', 0) == 0, - }, - depends=['default_account_code_digits']) diff --git a/configuration.xml b/configuration.xml deleted file mode 100644 index 388733d..0000000 --- a/configuration.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - account.configuration - - configuration_form - - - diff --git a/setup.py b/setup.py index 2528435..ba8d84b 100644 --- a/setup.py +++ b/setup.py @@ -20,6 +20,7 @@ def read(fname): os.path.join(os.path.dirname(__file__), fname), 'r', encoding='utf-8').read() + def get_require_version(name): if minor_version % 2: require = '%s >= %s.%s.dev0, < %s.%s' @@ -49,7 +50,7 @@ for dep in info.get('depends', []): requires.append(get_require_version('%s_%s' % (prefix, dep))) requires.append(get_require_version('trytond')) -tests_require = [] +tests_require = [get_require_version('trytond_company')] dependency_links = [] if minor_version % 2: # Add development index for testing with proteus diff --git a/tests/test_account_code_digits.py b/tests/test_account_code_digits.py index b4e65b4..683dd48 100755 --- a/tests/test_account_code_digits.py +++ b/tests/test_account_code_digits.py @@ -16,7 +16,7 @@ class AccountCodeDigitsTestCase(ModuleTestCase): module = 'account_code_digits' @with_transaction() - def test0010_force_digits(self): + def test_force_digits(self): 'Test force digits' pool = Pool() Account = pool.get('account.account') @@ -51,5 +51,5 @@ class AccountCodeDigitsTestCase(ModuleTestCase): def suite(): suite = trytond.tests.test_tryton.suite() suite.addTests(unittest.TestLoader().loadTestsFromTestCase( - AccountCodeDigitsTestCase)) + AccountCodeDigitsTestCase)) return suite diff --git a/tox.ini b/tox.ini index 08e43cf..527d859 100644 --- a/tox.ini +++ b/tox.ini @@ -1,10 +1,10 @@ [tox] -envlist = {py27,py33,py34,py35}-{sqlite,postgresql,mysql},pypy-{sqlite,postgresql} +envlist = {py27,py34,py35,py36}-{sqlite,postgresql,mysql},pypy-{sqlite,postgresql} [testenv] commands = {envpython} setup.py test deps = - {py27,py33,py34,py35}-postgresql: psycopg2 >= 2.5 + {py27,py34,py35,py36}-postgresql: psycopg2 >= 2.5 pypy-postgresql: psycopg2cffi >= 2.5 mysql: MySQL-python sqlite: sqlitebck diff --git a/tryton.cfg b/tryton.cfg index 722e4a2..47a1604 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -1,12 +1,8 @@ [tryton] -version=4.3.0 +version=4.7.0 depends: ir res - company - party - currency account xml: account.xml - configuration.xml