diff --git a/CHANGELOG b/CHANGELOG
index 1da3bfea7c..1a9eaf8f4b 100644
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,5 @@
+* Add asset on account type
+
Version 5.0.0 - 2018-10-01
* Bug fixes (see mercurial logs for details)
* Allow to set when the depreciation move should be created
diff --git a/__init__.py b/__init__.py
index 95bfcb76b3..231bf11768 100644
--- a/__init__.py
+++ b/__init__.py
@@ -25,6 +25,8 @@ def register():
account.Configuration,
account.ConfigurationAssetSequence,
account.ConfigurationAssetDate,
+ account.AccountTypeTemplate,
+ account.AccountType,
account.Move,
account.Period,
account.Journal,
diff --git a/account.py b/account.py
index 48ddc89df6..d343bc82b1 100644
--- a/account.py
+++ b/account.py
@@ -4,14 +4,11 @@ from trytond import backend
from trytond.i18n import gettext
from trytond.model import ModelSQL, fields
from trytond.model.exceptions import AccessError
-from trytond.pyson import Eval
+from trytond.pyson import Eval, If, Bool
from trytond.pool import PoolMeta, Pool
from trytond.tools.multivalue import migrate_property
from trytond.modules.company.model import CompanyValueMixin
-__all__ = ['Configuration', 'ConfigurationAssetSequence',
- 'ConfigurationAssetDate', 'Move', 'Period', 'Journal']
-
asset_bymonthday = fields.Selection([
('1', "First"),
('-1', "Last"),
@@ -122,6 +119,44 @@ class ConfigurationAssetDate(ModelSQL, CompanyValueMixin):
return "12"
+def AccountTypeMixin(template=False):
+
+ class Mixin:
+ fixed_asset = fields.Boolean(
+ "Fixed Asset",
+ domain=[
+ If(Eval('statement') != 'balance',
+ ('fixed_asset', '=', False), ()),
+ ],
+ states={
+ 'invisible': ((Eval('statement') != 'balance')
+ | ~Eval('assets', True)),
+ },
+ depends=['statement', 'assets'])
+ if not template:
+ for fname in dir(Mixin):
+ field = getattr(Mixin, fname)
+ if not isinstance(field, fields.Field):
+ continue
+ field.states['readonly'] = (
+ Bool(Eval('template', -1)) & ~Eval('template_override', False))
+ return Mixin
+
+
+class AccountTypeTemplate(AccountTypeMixin(template=True), metaclass=PoolMeta):
+ __name__ = 'account.account.type.template'
+
+ def _get_type_value(self, type=None):
+ values = super()._get_type_value(type=type)
+ if not type or type.fixed_asset != self.fixed_asset:
+ values['fixed_asset'] = self.fixed_asset
+ return values
+
+
+class AccountType(AccountTypeMixin(), metaclass=PoolMeta):
+ __name__ = 'account.account.type'
+
+
class Move(metaclass=PoolMeta):
__name__ = 'account.move'
diff --git a/account.xml b/account.xml
index 0eb9b87d36..9aa86497be 100644
--- a/account.xml
+++ b/account.xml
@@ -8,5 +8,17 @@ this repository contains the full copyright notices and license terms. -->
configuration_form
+
+
+ account.account.type.template
+
+ account_type_form
+
+
+
+ account.account.type
+
+ account_type_form
+
diff --git a/asset.py b/asset.py
index 084d6d008a..af5e5240ca 100644
--- a/asset.py
+++ b/asset.py
@@ -913,7 +913,7 @@ class AssetDepreciationTable(CompanyReport):
@cached_property
def update_lines(self):
- filter_ = lambda l: (l.account.kind == 'other'
+ filter_ = lambda l: (l.account.type.expense
and self.start_date < l.move.date <= self.end_date)
return list(filter(filter_,
(l for m in self.asset.update_moves for l in m.lines)))
diff --git a/invoice.py b/invoice.py
index a494727220..c80c430a39 100644
--- a/invoice.py
+++ b/invoice.py
@@ -33,6 +33,13 @@ class InvoiceLine(metaclass=PoolMeta):
'account_asset.msg_invoice_line_asset_unique'),
]
+ @classmethod
+ def _account_domain(cls, type_):
+ domain = super()._account_domain(type_)
+ if type_ == 'in':
+ domain.append(('type.fixed_asset', '=', True))
+ return domain
+
@fields.depends('product', 'invoice', 'invoice_type',
'_parent_invoice.invoice_date', '_parent_invoice.accounting_date')
def on_change_product(self):
diff --git a/minimal_chart.xml b/minimal_chart.xml
index aa5295a56b..aab4d92cb9 100644
--- a/minimal_chart.xml
+++ b/minimal_chart.xml
@@ -3,6 +3,25 @@
this repository contains the full copyright notices and license terms. -->
+
+ Fixed Assets
+ дълготрайни активи
+ Actius fixos
+ Anlagevermögen
+ Activos fijos
+ Immobilisations
+ Vaste activa
+ Ativo permanente
+ Основные средства
+ Osnovna sredstva
+
+ balance
+
+
+
+
+
Assets
@@ -15,16 +34,12 @@ this repository contains the full copyright notices and license terms. -->
Ativos
Assets
Sredstva
-
+
-
- expense
-
+
Depreciation
Depreciation
Amortització
@@ -35,12 +50,9 @@ this repository contains the full copyright notices and license terms. -->
Depreciação
Depreciation
Amortizacija
-
+
-
-
- other
+
diff --git a/minimal_chart_bg.xml b/minimal_chart_bg.xml
index 59237626f4..0e2bfd0ca2 100644
--- a/minimal_chart_bg.xml
+++ b/minimal_chart_bg.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+ дълготрайни активи
+
+
+
+
+
+
+
+
+
+ balance
+
+
+
+
+
Assets
@@ -13,11 +31,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
- expense
@@ -30,11 +47,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
-
- other
+
diff --git a/minimal_chart_ca.xml b/minimal_chart_ca.xml
index e04dca3698..b5d63ae791 100644
--- a/minimal_chart_ca.xml
+++ b/minimal_chart_ca.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+ Actius fixos
+
+
+
+
+
+
+
+
+ balance
+
+
+
+
+
@@ -13,11 +31,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
- expense
@@ -30,11 +47,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
-
- other
+
diff --git a/minimal_chart_de.xml b/minimal_chart_de.xml
index 0d17d6274f..fe0096b382 100644
--- a/minimal_chart_de.xml
+++ b/minimal_chart_de.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+
+ Anlagevermögen
+
+
+
+
+
+
+
+ balance
+
+
+
+
+
@@ -13,11 +31,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
- expense
@@ -30,11 +47,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
-
- other
+
diff --git a/minimal_chart_en.xml b/minimal_chart_en.xml
index f58b59a9bb..505920601c 100644
--- a/minimal_chart_en.xml
+++ b/minimal_chart_en.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+ Fixed Assets
+
+
+
+
+
+
+
+
+
+
+ balance
+
+
+
+
+
Assets
@@ -13,11 +31,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
- expense
@@ -30,11 +47,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
-
- other
+
diff --git a/minimal_chart_es.xml b/minimal_chart_es.xml
index f8c02a5535..8a73b4c082 100644
--- a/minimal_chart_es.xml
+++ b/minimal_chart_es.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+
+
+ Activos fijos
+
+
+
+
+
+
+ balance
+
+
+
+
+
@@ -13,11 +31,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
- expense
@@ -30,11 +47,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
-
- other
+
diff --git a/minimal_chart_fr.xml b/minimal_chart_fr.xml
index 16700ddd60..dd3600abfa 100644
--- a/minimal_chart_fr.xml
+++ b/minimal_chart_fr.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+
+
+
+ Immobilisations
+
+
+
+
+
+ balance
+
+
+
+
+
@@ -13,11 +31,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
- expense
@@ -30,11 +47,10 @@ this repository contains the full copyright notices and license terms. -->
-
+
+
-
-
- other
+
diff --git a/minimal_chart_nl.xml b/minimal_chart_nl.xml
index 5cf7056684..41fd81b170 100644
--- a/minimal_chart_nl.xml
+++ b/minimal_chart_nl.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+
+
+
+
+ Vaste activa
+
+
+
+
+ balance
+
+
+
+
+
@@ -13,11 +31,10 @@ this repository contains the full copyright notices and license terms. -->
Assets
-
+
+
-
- expense
@@ -30,11 +47,10 @@ this repository contains the full copyright notices and license terms. -->
Depreciation
-
+
+
-
-
- other
+
diff --git a/minimal_chart_pt.xml b/minimal_chart_pt.xml
index 908850905f..02b1c6a22c 100644
--- a/minimal_chart_pt.xml
+++ b/minimal_chart_pt.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+
+
+
+
+
+ Ativo permanente
+
+
+
+ balance
+
+
+
+
+
@@ -14,11 +32,9 @@ this repository contains the full copyright notices and license terms. -->
Ativos
-
+
-
- expense
@@ -32,11 +48,9 @@ this repository contains the full copyright notices and license terms. -->
Depreciação
-
+
-
-
- other
+
diff --git a/minimal_chart_ru.xml b/minimal_chart_ru.xml
index e00068e2db..139a76ede1 100644
--- a/minimal_chart_ru.xml
+++ b/minimal_chart_ru.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+
+
+
+
+
+
+ Основные средства
+
+
+ balance
+
+
+
+
+
@@ -11,13 +29,12 @@ this repository contains the full copyright notices and license terms. -->
+
Assets
-
+
-
- expense
@@ -28,13 +45,12 @@ this repository contains the full copyright notices and license terms. -->
+
Depreciation
-
+
-
-
- other
+
diff --git a/minimal_chart_sl.xml b/minimal_chart_sl.xml
index 221a3720a3..2998b35326 100644
--- a/minimal_chart_sl.xml
+++ b/minimal_chart_sl.xml
@@ -3,6 +3,24 @@
this repository contains the full copyright notices and license terms. -->
+
+
+
+
+
+
+
+
+
+
+ Osnovna sredstva
+
+ balance
+
+
+
+
+
@@ -12,12 +30,11 @@ this repository contains the full copyright notices and license terms. -->
+
Sredstva
-
+
-
- expense
@@ -29,12 +46,11 @@ this repository contains the full copyright notices and license terms. -->
+
Amortizacija
-
+
-
-
- other
+
diff --git a/product.py b/product.py
index 6d6b2b58bc..955b85a9b2 100644
--- a/product.py
+++ b/product.py
@@ -14,7 +14,7 @@ class Category(metaclass=PoolMeta):
__name__ = 'product.category'
account_depreciation = fields.MultiValue(fields.Many2One('account.account',
'Account Depreciation', domain=[
- ('kind', '=', 'other'),
+ ('type.fixed_asset', '=', True),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
@@ -26,7 +26,7 @@ class Category(metaclass=PoolMeta):
account_asset = fields.MultiValue(fields.Many2One('account.account',
'Account Asset',
domain=[
- ('kind', '=', 'expense'),
+ ('type.fixed_asset', '=', True),
('company', '=', Eval('context', {}).get('company', -1)),
],
states={
@@ -59,14 +59,14 @@ class CategoryAccount(metaclass=PoolMeta):
account_depreciation = fields.Many2One(
'account.account', "Account Depreciation",
domain=[
- ('kind', '=', 'other'),
+ ('type.fixed_asset', '=', True),
('company', '=', Eval('company', -1)),
],
depends=['company'])
account_asset = fields.Many2One(
'account.account', "Account Asset",
domain=[
- ('kind', '=', 'expense'),
+ ('type.fixed_asset', '=', True),
('company', '=', Eval('company', -1)),
],
depends=['company'])
diff --git a/tests/tools.py b/tests/tools.py
index cf03206002..035de5ac5a 100644
--- a/tests/tools.py
+++ b/tests/tools.py
@@ -12,18 +12,14 @@ def add_asset_accounts(accounts, company=None, config=None):
if not company:
company = get_company()
- expense_accounts = Account.find([
- ('kind', '=', 'expense'),
+ accounts['asset'], = Account.find([
+ ('type.fixed_asset', '=', True),
+ ('name', '=', "Assets"),
('company', '=', company.id),
- ])
- for account in expense_accounts:
- if account.name == 'Expense':
- accounts['expense'] = account
- elif account.name == 'Assets':
- accounts['asset'] = account
- depreciation, = Account.find([
- ('kind', '=', 'other'),
- ('name', '=', 'Depreciation'),
- ])
- accounts['depreciation'] = depreciation
+ ], limit=1)
+ accounts['depreciation'], = Account.find([
+ ('type.fixed_asset', '=', True),
+ ('name', '=', "Depreciation"),
+ ('company', '=', company.id),
+ ], limit=1)
return accounts
diff --git a/view/account_type_form.xml b/view/account_type_form.xml
new file mode 100644
index 0000000000..62588a09ab
--- /dev/null
+++ b/view/account_type_form.xml
@@ -0,0 +1,9 @@
+
+
+
+
+
+
+
+