Remove Property fields

issue2349
review31251002
This commit is contained in:
Cédric Krier
2017-04-01 00:26:01 +02:00
parent 8c3fafc82e
commit 67facdfa20
4 changed files with 160 additions and 21 deletions
+3
View File
@@ -18,10 +18,13 @@ def register():
UpdateAssetShowDepreciation,
PrintDepreciationTableStart,
Category,
CategoryAccount,
Template,
TemplateAccount,
Product,
InvoiceLine,
Configuration,
ConfigurationAssetSequence,
Move,
PurchaseLine,
module='account_asset', type_='model')
+53 -8
View File
@@ -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:
-7
View File
@@ -9,11 +9,4 @@ this repository contains the full copyright notices and license terms. -->
<field name="name">configuration_form</field>
</record>
</data>
<data noupdate="1">
<record model="ir.property" id="property_asset_sequence">
<field name="field"
search="[('model.model', '=', 'account.configuration'), ('name', '=', 'asset_sequence')]"/>
<field name="value" eval="'ir.sequence,' + str(ref('sequence_asset'))"/>
</record>
</data>
</tryton>
+104 -6
View File
@@ -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