diff --git a/__init__.py b/__init__.py
index cb1b0dbeaf..d6dd4a7923 100644
--- a/__init__.py
+++ b/__init__.py
@@ -18,10 +18,13 @@ def register():
UpdateAssetShowDepreciation,
PrintDepreciationTableStart,
Category,
+ CategoryAccount,
Template,
+ TemplateAccount,
Product,
InvoiceLine,
Configuration,
+ ConfigurationAssetSequence,
Move,
PurchaseLine,
module='account_asset', type_='model')
diff --git a/account.py b/account.py
index 8b58bb86db..9db6d32758 100644
--- a/account.py
+++ b/account.py
@@ -1,21 +1,66 @@
# This file is part of 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 import backend
+from trytond.model import ModelSQL, fields
from trytond.pyson import Eval
-from trytond.pool import PoolMeta
+from trytond.pool import PoolMeta, Pool
+from trytond.tools.multivalue import migrate_property
+from trytond.modules.company.model import CompanyValueMixin
-__all__ = ['Configuration', 'Move']
+__all__ = ['Configuration', 'ConfigurationAssetSequence', 'Move']
class Configuration:
__metaclass__ = PoolMeta
__name__ = 'account.configuration'
- asset_sequence = fields.Property(fields.Many2One('ir.sequence',
- 'Asset Reference Sequence', domain=[
- ('company', 'in', [Eval('context', {}).get('company', -1),
- None]),
+ asset_sequence = fields.MultiValue(fields.Many2One(
+ 'ir.sequence', "Asset Reference Sequence", required=True,
+ domain=[
+ ('company', 'in', [
+ Eval('context', {}).get('company', -1), None]),
('code', '=', 'account.asset'),
- ], required=True))
+ ]))
+
+ @classmethod
+ def default_asset_sequence(cls, **pattern):
+ return cls.multivalue_model('asset_sequence').default_asset_sequence()
+
+
+class ConfigurationAssetSequence(ModelSQL, CompanyValueMixin):
+ "Account Configuration Asset Sequence"
+ __name__ = 'account.configuration.asset_sequence'
+ asset_sequence = fields.Many2One(
+ 'ir.sequence', "Asset Reference Sequence", required=True,
+ domain=[
+ ('company', 'in', [Eval('company', -1), None]),
+ ('code', '=', 'account.asset'),
+ ],
+ depends=['company'])
+
+ @classmethod
+ def __register__(cls, module_name):
+ TableHandler = backend.get('TableHandler')
+ exist = TableHandler.table_exist(cls._table)
+
+ super(ConfigurationAssetSequence, cls).__register__(module_name)
+
+ if not exist:
+ cls._migrate_property([], [], [])
+
+ @classmethod
+ def _migrate_property(cls, field_names, value_names, fields):
+ field_names.append('asset_sequence')
+ value_names.append('asset_sequence')
+ fields.append('company')
+ migrate_property(
+ 'account.configuration', field_names, cls, value_names,
+ fields=fields)
+
+ @classmethod
+ def default_asset_sequence(cls):
+ pool = Pool()
+ ModelData = pool.get('ir.model.data')
+ return ModelData.get_id('account_asset', 'sequence_asset')
class Move:
diff --git a/account.xml b/account.xml
index 2347bec8f7..0eb9b87d36 100644
--- a/account.xml
+++ b/account.xml
@@ -9,11 +9,4 @@ this repository contains the full copyright notices and license terms. -->
configuration_form
-
-
-
-
-
-
diff --git a/product.py b/product.py
index 6c3baa2520..f6b538fc74 100644
--- a/product.py
+++ b/product.py
@@ -1,17 +1,19 @@
# This file is part of Tryton. The COPYRIGHT file at the top level of this
# repository contains the full copyright notices and license terms.
+from trytond import backend
from trytond.model import fields
from trytond.pyson import Eval
-from trytond.pool import PoolMeta
+from trytond.pool import PoolMeta, Pool
from trytond.modules.account_product import MissingFunction
-__all__ = ['Category', 'Template', 'Product']
+__all__ = ['Category', 'CategoryAccount', 'Template', 'TemplateAccount',
+ 'Product']
class Category:
__metaclass__ = PoolMeta
__name__ = 'product.category'
- account_depreciation = fields.Property(fields.Many2One('account.account',
+ account_depreciation = fields.MultiValue(fields.Many2One('account.account',
'Account Depreciation', domain=[
('kind', '=', 'other'),
('company', '=', Eval('context', {}).get('company', -1)),
@@ -25,7 +27,7 @@ class Category:
account_depreciation_used = MissingFunction(
fields.Many2One('account.account', 'Account Depreciation Used'),
'missing_account', 'get_account')
- account_asset = fields.Property(fields.Many2One('account.account',
+ account_asset = fields.MultiValue(fields.Many2One('account.account',
'Account Asset',
domain=[
('kind', '=', 'expense'),
@@ -41,6 +43,54 @@ class Category:
fields.Many2One('account.account', 'Account Asset Used'),
'missing_account', 'get_account')
+ @classmethod
+ def multivalue_model(cls, field):
+ pool = Pool()
+ if field in {'account_depreciation', 'account_asset'}:
+ return pool.get('product.category.account')
+ return super(Category, cls).multivalue_model(field)
+
+
+class CategoryAccount:
+ __metaclass__ = PoolMeta
+ __name__ = 'product.category.account'
+ account_depreciation = fields.Many2One(
+ 'account.account', "Account Depreciation",
+ domain=[
+ ('kind', '=', 'other'),
+ ('company', '=', Eval('company', -1)),
+ ],
+ depends=['company'])
+ account_asset = fields.Many2One(
+ 'account.account', "Account Asset",
+ domain=[
+ ('kind', '=', 'expense'),
+ ('company', '=', Eval('company', -1)),
+ ],
+ depends=['company'])
+
+ @classmethod
+ def __register__(cls, module_name):
+ TableHandler = backend.get('TableHandler')
+ exist = TableHandler.table_exist(cls._table)
+ if exist:
+ table = TableHandler(cls, module_name)
+ exist &= (table.column_exist('account_depreciation')
+ and table.column_exist('account_asset'))
+
+ super(CategoryAccount, cls).__register__(module_name)
+
+ if not exist:
+ # Re-migration
+ cls._migrate_property([], [], [])
+
+ @classmethod
+ def _migrate_property(cls, field_names, value_names, fields):
+ field_names.extend(['account_depreciation', 'account_asset'])
+ value_names.extend(['account_depreciation', 'account_asset'])
+ super(CategoryAccount, cls)._migrate_property(
+ field_names, value_names, fields)
+
class Template:
__metaclass__ = PoolMeta
@@ -49,7 +99,7 @@ class Template:
'readonly': ~Eval('active', True),
'invisible': Eval('type', '') != 'assets',
}, depends=['active', 'type'])
- account_depreciation = fields.Property(fields.Many2One('account.account',
+ account_depreciation = fields.MultiValue(fields.Many2One('account.account',
'Account Depreciation', domain=[
('kind', '=', 'other'),
('company', '=', Eval('context', {}).get('company', -1)),
@@ -66,7 +116,7 @@ class Template:
account_depreciation_used = MissingFunction(
fields.Many2One('account.account', 'Account Depreciation Used'),
'missing_account', 'get_account')
- account_asset = fields.Property(fields.Many2One('account.account',
+ account_asset = fields.MultiValue(fields.Many2One('account.account',
'Account Asset',
domain=[
('kind', '=', 'expense'),
@@ -94,6 +144,54 @@ class Template:
depends=['active', 'depreciable', 'type'],
help='In months')
+ @classmethod
+ def multivalue_model(cls, field):
+ pool = Pool()
+ if field in {'account_depreciation', 'account_asset'}:
+ return pool.get('product.template.account')
+ return super(Template, cls).multivalue_model(field)
+
+
+class TemplateAccount:
+ __metaclass__ = PoolMeta
+ __name__ = 'product.template.account'
+ account_depreciation = fields.Many2One(
+ 'account.account', "Account Depreciation",
+ domain=[
+ ('kind', '=', 'other'),
+ ('company', '=', Eval('company', -1)),
+ ],
+ depends=['company'])
+ account_asset = fields.Many2One(
+ 'account.account', "Account Asset",
+ domain=[
+ ('kind', '=', 'expense'),
+ ('company', '=', Eval('company', -1)),
+ ],
+ depends=['company'])
+
+ @classmethod
+ def __register__(cls, module_name):
+ TableHandler = backend.get('TableHandler')
+ exist = TableHandler.table_exist(cls._table)
+ if exist:
+ table = TableHandler(cls, module_name)
+ exist &= (table.column_exist('account_depreciation')
+ and table.column_exist('account_asset'))
+
+ super(TemplateAccount, cls).__register__(module_name)
+
+ if not exist:
+ # Re-migration
+ cls._migrate_property([], [], [])
+
+ @classmethod
+ def _migrate_property(cls, field_names, value_names, fields):
+ field_names.extend(['account_depreciation', 'account_asset'])
+ value_names.extend(['account_depreciation', 'account_asset'])
+ super(TemplateAccount, cls)._migrate_property(
+ field_names, value_names, fields)
+
class Product:
__metaclass__ = PoolMeta