From a3b876065796450d2f730309369b287df4f9db2c Mon Sep 17 00:00:00 2001 From: Xavier Codinas Date: Wed, 20 Sep 2017 17:54:28 +0200 Subject: [PATCH] Allow to set default category and product accounts on configuration wizard issue6497 review34951004 --- CHANGELOG | 1 + __init__.py | 5 +++ account.py | 61 +++++++++++++++++++++++++++ account.xml | 13 ++++++ tryton.cfg | 1 + view/create_chart_properties_form.xml | 17 ++++++++ 6 files changed, 98 insertions(+) create mode 100644 account.py create mode 100644 account.xml create mode 100644 view/create_chart_properties_form.xml diff --git a/CHANGELOG b/CHANGELOG index 4ea0144b0e..a111b46fa7 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,4 @@ +* Allow to set default category and product accounts on configuration wizard * Replace MissingFunction with properties Version 4.4.0 - 2017-05-01 diff --git a/__init__.py b/__init__.py index f74314ef54..82a5baa134 100644 --- a/__init__.py +++ b/__init__.py @@ -4,6 +4,7 @@ from trytond.pool import Pool from .product import * from .configuration import * +from . import account def register(): @@ -13,6 +14,7 @@ def register(): CategoryAccount, CategoryCustomerTax, CategorySupplierTax, + account.CreateChartProperties, Template, TemplateAccount, TemplateCustomerTax, @@ -21,3 +23,6 @@ def register(): Configuration, ConfigurationDefaultAccount, module='account_product', type_='model') + Pool.register( + account.CreateChart, + module='account_product', type_='wizard') diff --git a/account.py b/account.py new file mode 100644 index 0000000000..eb695db4bc --- /dev/null +++ b/account.py @@ -0,0 +1,61 @@ +# 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.pyson import Eval +from trytond.model import fields +from trytond.transaction import Transaction + +__all__ = ['CreateChart', 'CreateChartProperties'] + + +class CreateChartProperties: + __metaclass__ = PoolMeta + __name__ = 'account.create_chart.properties' + + product_account_expense = fields.Many2One( + 'account.account', 'Default Expense Account', + domain=[ + ('kind', '=', 'expense'), + ('company', '=', Eval('company')), + ], + depends=['company']) + product_account_revenue = fields.Many2One( + 'account.account', 'Default Revenue Account', + domain=[ + ('kind', '=', 'revenue'), + ('company', '=', Eval('company')), + ], + depends=['company']) + category_account_expense = fields.Many2One( + 'account.account', 'Default Expense Account', + domain=[ + ('kind', '=', 'expense'), + ('company', '=', Eval('company')), + ], + depends=['company']) + category_account_revenue = fields.Many2One( + 'account.account', 'Default Revenue Account', + domain=[ + ('kind', '=', 'revenue'), + ('company', '=', Eval('company')), + ], + depends=['company']) + + +class CreateChart: + __metaclass__ = PoolMeta + __name__ = 'account.create_chart' + + def transition_create_properties(self): + pool = Pool() + Configuration = pool.get('account.configuration') + state = super(CreateChart, self).transition_create_properties() + + with Transaction().set_context(company=self.properties.company.id): + config = Configuration(1) + for name in ['product_account_expense', 'product_account_revenue', + 'category_account_expense', 'category_account_revenue']: + setattr(config, 'default_%s' % name, + getattr(self.properties, name)) + config.save() + return state diff --git a/account.xml b/account.xml new file mode 100644 index 0000000000..35e8678287 --- /dev/null +++ b/account.xml @@ -0,0 +1,13 @@ + + + + + + account.create_chart.properties + + create_chart_properties_form + + + diff --git a/tryton.cfg b/tryton.cfg index 59763e7365..56bfe472ba 100644 --- a/tryton.cfg +++ b/tryton.cfg @@ -8,3 +8,4 @@ depends: xml: product.xml configuration.xml + account.xml diff --git a/view/create_chart_properties_form.xml b/view/create_chart_properties_form.xml new file mode 100644 index 0000000000..b2932bc3a2 --- /dev/null +++ b/view/create_chart_properties_form.xml @@ -0,0 +1,17 @@ + + + + + + +