diff --git a/CHANGELOG b/CHANGELOG index b9a736911b..f083dccf2e 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,5 @@ +* Add default revenue/expense configuration + Version 3.6.0 - 2015-04-20 * Bug fixes (see mercurial logs for details) * Add support for PyPy diff --git a/__init__.py b/__init__.py index 561f1cfa4d..e337cf158d 100644 --- a/__init__.py +++ b/__init__.py @@ -3,6 +3,7 @@ from trytond.pool import Pool from .product import * +from .configuration import * def register(): @@ -13,4 +14,5 @@ def register(): Template, TemplateCustomerTax, TemplateSupplierTax, + Configuration, module='account_product', type_='model') diff --git a/configuration.py b/configuration.py new file mode 100644 index 0000000000..9d9e8aedca --- /dev/null +++ b/configuration.py @@ -0,0 +1,62 @@ +# 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.pool import PoolMeta, Pool +from trytond.model import fields +from trytond.pyson import Eval + + +__all__ = ['Configuration'] + + +class Configuration: + __metaclass__ = PoolMeta + __name__ = 'account.configuration' + + default_product_account_expense = fields.Function(fields.Many2One( + 'account.account', 'Default Account Expense', + domain=[ + ('kind', '=', 'expense'), + ('company', '=', Eval('context', {}).get('company', -1)), + ]), + 'get_account', setter='set_account') + default_product_account_revenue = fields.Function(fields.Many2One( + 'account.account', 'Default Account Revenue', + domain=[ + ('kind', '=', 'revenue'), + ('company', '=', Eval('context', {}).get('company', -1)), + ]), + 'get_account', setter='set_account') + default_category_account_expense = fields.Function(fields.Many2One( + 'account.account', 'Default Account Expense', + domain=[ + ('kind', '=', 'expense'), + ('company', '=', Eval('context', {}).get('company', -1)), + ]), + 'get_account', setter='set_account') + default_category_account_revenue = fields.Function(fields.Many2One( + 'account.account', 'Default Account Revenue', + domain=[ + ('kind', '=', 'revenue'), + ('company', '=', Eval('context', {}).get('company', -1)), + ]), + 'get_account', setter='set_account') + + @classmethod + def _get_account_field(cls, name): + pool = Pool() + ModelField = pool.get('ir.model.field') + if name in ['default_product_account_expense', + 'default_product_account_revenue']: + field, = ModelField.search([ + ('model.model', '=', 'product.template'), + ('name', '=', name[len('default_product_'):]), + ], limit=1) + return field + elif name in ['default_category_account_expense', + 'default_category_account_revenue']: + field, = ModelField.search([ + ('model.model', '=', 'product.category'), + ('name', '=', name[len('default_category_'):]), + ], limit=1) + return field + return super(Configuration, cls)._get_account_field(name) diff --git a/configuration.xml b/configuration.xml new file mode 100644 index 0000000000..0eb9b87d36 --- /dev/null +++ b/configuration.xml @@ -0,0 +1,12 @@ + + + + + + account.configuration + + configuration_form + + + diff --git a/tryton.cfg b/tryton.cfg index 985be33e43..4bb06dbe4c 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -7,3 +7,4 @@ depends: product xml: product.xml + configuration.xml diff --git a/view/configuration_form.xml b/view/configuration_form.xml new file mode 100644 index 0000000000..e28ee5f6e9 --- /dev/null +++ b/view/configuration_form.xml @@ -0,0 +1,18 @@ + + + + + + +