trytond-patches/issue14841002_1.diff

83 lines
3.0 KiB
Diff

# HG changeset patch
# User Sergi Almacellas Abellana <sergi@koolpi.com>
Speedup fiscalyear closing process
issue4443
review14841002
Index: trytond/trytond/modules/account/fiscalyear.py
===================================================================
--- a/trytond/trytond/modules/account/fiscalyear.py
+++ b/trytond/trytond/modules/account/fiscalyear.py
@@ -4,7 +4,7 @@
from trytond.model import ModelView, ModelSQL, fields
from trytond.wizard import Wizard, StateView, StateTransition, StateAction, \
Button
-from trytond.tools import datetime_strftime
+from trytond.tools import datetime_strftime, grouped_slice
from trytond.pyson import Eval, If, PYSONEncoder
from trytond.transaction import Transaction
from trytond.pool import Pool
@@ -231,26 +231,33 @@
return None
return fiscalyears[0].id
- def _process_account(self, account):
+ def _process_accounts(self, accounts):
'''
Process account for a fiscal year closed
'''
- Currency = Pool().get('currency.currency')
- Deferral = Pool().get('account.account.deferral')
+ pool = Pool()
+ Currency = pool.get('currency.currency')
+ Deferral = pool.get('account.account.deferral')
- if account.kind == 'view':
- return
- if not account.deferral:
- if not Currency.is_zero(self.company.currency, account.balance):
- self.raise_user_error('account_balance_not_zero',
- error_args=(account.rec_name,))
- else:
- Deferral.create([{
- 'account': account.id,
- 'fiscalyear': self.id,
- 'debit': account.debit,
- 'credit': account.credit,
- }])
+ for sub_accounts in grouped_slice(accounts):
+ to_create = []
+ for account in sub_accounts:
+ if account.kind == 'view':
+ continue
+ if not account.deferral:
+ if not Currency.is_zero(self.company.currency,
+ account.balance):
+ self.raise_user_error('account_balance_not_zero',
+ error_args=(account.rec_name,))
+ else:
+ to_create.append({
+ 'account': account.id,
+ 'fiscalyear': self.id,
+ 'debit': account.debit,
+ 'credit': account.credit,
+ })
+ if to_create:
+ Deferral.create(to_create)
@classmethod
@ModelView.button
@@ -285,8 +292,7 @@
accounts = Account.search([
('company', '=', fiscalyear.company.id),
])
- for account in accounts:
- fiscalyear._process_account(account)
+ fiscalyear._process_accounts(accounts)
@classmethod
@ModelView.button