From a1d47e946b95d7adbb80b15cd19fc4a741c8ed4f Mon Sep 17 00:00:00 2001 From: Sergi Almacellas Abellana Date: Tue, 25 Aug 2020 18:04:55 +0200 Subject: [PATCH] Set default accounts on create and update chart wizards issue9382 review306261002 --- account.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/account.py b/account.py index 3a94264805..d687dbc554 100644 --- a/account.py +++ b/account.py @@ -45,6 +45,23 @@ class CreateChart(metaclass=PoolMeta): config.save() return state + def default_properties(self, fields): + pool = Pool() + Account = pool.get('account.account') + + defaults = super(CreateChart, self).default_properties(fields) + expense_accounts = Account.search([ + ('type.expense', '=', True), + ], limit=2) + revenue_accounts = Account.search([ + ('type.revenue', '=', True), + ], limit=2) + if len(expense_accounts) == 1: + defaults['category_account_expense'] = expense_accounts[0].id + if len(revenue_accounts) == 1: + defaults['category_account_revenue'] = revenue_accounts[0].id + return defaults + class MoveLine(metaclass=PoolMeta): __name__ = 'account.move.line'