Update to 4.7

This commit is contained in:
C?dric Krier 2017-12-12 10:42:56 +01:00
parent 153c8de5d5
commit ba2e2c05eb
10 changed files with 104 additions and 94 deletions

View File

@ -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

View File

@ -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')

View File

@ -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()

View File

@ -1,13 +1,21 @@
<?xml version="1.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. -->
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="configuration_view_form">
<field name="model">account.configuration</field>
<field name="inherit" ref="account.configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
<record model="ir.ui.view" id="create_chart_account_view_form">
<field name="model">account.create_chart.account</field>
<field name="inherit" ref="account.create_chart_account_view_form"/>
<field name="name">create_chart_account_form</field>
</record>
<record model="ir.ui.view" id="update_chart_start_view_form">
<field name="model">account.update_chart.start</field>
<field name="inherit" ref="account.update_chart_start_view_form"/>

View File

@ -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'])

View File

@ -1,12 +0,0 @@
<?xml version="1.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. -->
<tryton>
<data>
<record model="ir.ui.view" id="configuration_view_form">
<field name="model">account.configuration</field>
<field name="inherit" ref="account.configuration_view_form"/>
<field name="name">configuration_form</field>
</record>
</data>
</tryton>

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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