Merge lp:~openerp-dev/openobject-addons/7.0-speedup-accounting-mat into lp:openobject-addons/7.0

Proposed by Martin Trigaux (OpenERP)
Status: Needs review
Proposed branch: lp:~openerp-dev/openobject-addons/7.0-speedup-accounting-mat
Merge into: lp:openobject-addons/7.0
Diff against target: 175 lines (+48/-46)
4 files modified
account/account.py (+0/-5)
account/account_bank_statement.py (+8/-13)
account/account_move_line.py (+38/-22)
stock/stock.py (+2/-6)
To merge this branch: bzr merge lp:~openerp-dev/openobject-addons/7.0-speedup-accounting-mat
Reviewer Review Type Date Requested Status
Martin Trigaux (OpenERP) Pending
Review via email: mp+186555@code.launchpad.net

Description of the change

Improve performances on the creation of account moves

To post a comment you must log in.
9463. By Martin Trigaux (OpenERP)

[IMP] account: group constraints into a single browse

9464. By Martin Trigaux (OpenERP)

[IMP] stock: replace browse by a single search

9465. By Martin Trigaux (OpenERP)

[MERGE] sync with 7.0

9466. By Martin Trigaux (OpenERP)

[IMP] account: don't create new analytic lines at creation, will do it once the move is balanced

9467. By Martin Trigaux (OpenERP)

[IMP] account: remove analytic lines only when create new one

Unmerged revisions

9467. By Martin Trigaux (OpenERP)

[IMP] account: remove analytic lines only when create new one

9466. By Martin Trigaux (OpenERP)

[IMP] account: don't create new analytic lines at creation, will do it once the move is balanced

9465. By Martin Trigaux (OpenERP)

[MERGE] sync with 7.0

9464. By Martin Trigaux (OpenERP)

[IMP] stock: replace browse by a single search

9463. By Martin Trigaux (OpenERP)

[IMP] account: group constraints into a single browse

9462. By Martin Trigaux (OpenERP)

[IMP] account: group the creation of move lines in one call (benefit from the novalidate context)

9461. By Martin Trigaux (OpenERP)

[IMP] account: replaced nested browse by a search

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account/account.py'
--- account/account.py 2013-09-18 14:31:46 +0000
+++ account/account.py 2013-09-27 15:33:32 +0000
@@ -1580,11 +1580,6 @@
1580 obj_analytic_line = self.pool.get('account.analytic.line')1580 obj_analytic_line = self.pool.get('account.analytic.line')
1581 obj_move_line = self.pool.get('account.move.line')1581 obj_move_line = self.pool.get('account.move.line')
1582 for move in self.browse(cr, uid, ids, context):1582 for move in self.browse(cr, uid, ids, context):
1583 # Unlink old analytic lines on move_lines
1584 for obj_line in move.line_id:
1585 for obj in obj_line.analytic_lines:
1586 obj_analytic_line.unlink(cr,uid,obj.id)
1587
1588 journal = move.journal_id1583 journal = move.journal_id
1589 amount = 01584 amount = 0
1590 line_ids = []1585 line_ids = []
15911586
=== modified file 'account/account_bank_statement.py'
--- account/account_bank_statement.py 2013-06-07 11:38:29 +0000
+++ account/account_bank_statement.py 2013-09-27 15:33:32 +0000
@@ -220,9 +220,8 @@
220 res_currency_obj = self.pool.get('res.currency')220 res_currency_obj = self.pool.get('res.currency')
221 amt_cur = -res_currency_obj.compute(cr, uid, company_currency_id, cur_id, amount, context=context)221 amt_cur = -res_currency_obj.compute(cr, uid, company_currency_id, cur_id, amount, context=context)
222222
223 res = self._prepare_move_line_vals(cr, uid, st_line, move_id, debit, credit,223 return self._prepare_move_line_vals(cr, uid, st_line, move_id, debit, credit,
224 amount_currency=amt_cur, currency_id=cur_id, analytic_id=anl_id, context=context)224 amount_currency=amt_cur, currency_id=cur_id, analytic_id=anl_id, context=context)
225 return res
226225
227 def _get_counter_part_account(sefl, cr, uid, st_line, context=None):226 def _get_counter_part_account(sefl, cr, uid, st_line, context=None):
228 """Retrieve the account to use in the counterpart move.227 """Retrieve the account to use in the counterpart move.
@@ -342,7 +341,7 @@
342 account_bank_statement_line_obj.write(cr, uid, [st_line.id], {341 account_bank_statement_line_obj.write(cr, uid, [st_line.id], {
343 'move_ids': [(4, move_id, False)]342 'move_ids': [(4, move_id, False)]
344 })343 })
345 torec = []344
346 acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id345 acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id
347346
348 context.update({347 context.update({
@@ -353,18 +352,14 @@
353352
354 bank_move_vals = self._prepare_bank_move_line(cr, uid, st_line, move_id, amount,353 bank_move_vals = self._prepare_bank_move_line(cr, uid, st_line, move_id, amount,
355 company_currency_id, context=context)354 company_currency_id, context=context)
356 move_line_id = account_move_line_obj.create(cr, uid, bank_move_vals, context=context)
357 torec.append(move_line_id)
358
359 counterpart_move_vals = self._prepare_counterpart_move_line(cr, uid, st_line, move_id,355 counterpart_move_vals = self._prepare_counterpart_move_line(cr, uid, st_line, move_id,
360 amount, company_currency_id, context=context)356 amount, company_currency_id, context=context)
361 account_move_line_obj.create(cr, uid, counterpart_move_vals, context=context)357
362358 account_move_obj.write(cr, uid, [move_id], {'line_id': [(0, 0, bank_move_vals), (0, 0, counterpart_move_vals)]}, context)
363 for line in account_move_line_obj.browse(cr, uid, [x.id for x in359
364 account_move_obj.browse(cr, uid, move_id,360 invalid_line_ids = account_move_line_obj.search(cr, uid, [('move_id', '=', move_id), ('state', '<>', 'valid')], context=context)
365 context=context).line_id],361 if invalid_line_ids:
366 context=context):362 for line in account_move_line_obj.browse(cr, uid, invalid_line_ids, context=context):
367 if line.state <> 'valid':
368 raise osv.except_osv(_('Error!'),363 raise osv.except_osv(_('Error!'),
369 _('Journal item "%s" is not valid.') % line.name)364 _('Journal item "%s" is not valid.') % line.name)
370365
371366
=== modified file 'account/account_move_line.py'
--- account/account_move_line.py 2013-09-18 14:31:46 +0000
+++ account/account_move_line.py 2013-09-27 15:33:32 +0000
@@ -193,6 +193,8 @@
193 if obj_line.analytic_account_id:193 if obj_line.analytic_account_id:
194 if not obj_line.journal_id.analytic_journal_id:194 if not obj_line.journal_id.analytic_journal_id:
195 raise osv.except_osv(_('No Analytic Journal!'),_("You have to define an analytic journal on the '%s' journal!") % (obj_line.journal_id.name, ))195 raise osv.except_osv(_('No Analytic Journal!'),_("You have to define an analytic journal on the '%s' journal!") % (obj_line.journal_id.name, ))
196 if obj_line.analytic_lines:
197 acc_ana_line_obj.unlink(cr,uid,[obj.id for obj in obj_line.analytic_lines])
196 vals_line = self._prepare_analytic_line(cr, uid, obj_line, context=context)198 vals_line = self._prepare_analytic_line(cr, uid, obj_line, context=context)
197 acc_ana_line_obj.create(cr, uid, vals_line)199 acc_ana_line_obj.create(cr, uid, vals_line)
198 return True200 return True
@@ -565,6 +567,33 @@
565 if not cr.fetchone():567 if not cr.fetchone():
566 cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index ON account_move_line (journal_id, period_id)')568 cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index ON account_move_line (journal_id, period_id)')
567569
570 def _check_all(self, cr, uid, ids, context=None):
571 for l in self.browse(cr, uid, ids, context=context):
572 if l.account_id.type == 'view':
573 raise osv.except_osv(_('Error!'), _('You cannot create journal items on an account of type view %s %s.') % (l.account_id.code, l.account_id.name))
574 elif l.account_id.type == 'closed':
575 raise osv.except_osv(_('Error!'), _('You cannot create journal items on a closed account %s %s.') % (l.account_id.code, l.account_id.name))
576
577 if l.company_id != l.account_id.company_id or l.company_id != l.period_id.company_id:
578 raise osv.except_osv(_('Error!'), _('Account and Period must belong to the company %s.') % (l.company_id.name))
579
580 if l.journal_id.allow_date:
581 if not time.strptime(l.date[:10],'%Y-%m-%d') >= time.strptime(l.period_id.date_start, '%Y-%m-%d') or not time.strptime(l.date[:10], '%Y-%m-%d') <= time.strptime(l.period_id.date_stop, '%Y-%m-%d'):
582 raise osv.except_osv(_('Error!'), _('The date of your Journal Entry is not in the defined period! You should change the date or remove this constraint from the journal.'))
583
584 if l.account_id.currency_id:
585 if not l.currency_id or not l.currency_id.id == l.account_id.currency_id.id:
586 raise osv.except_osv(_('Error!'), _('The selected account %s of your Journal Entry forces to provide a secondary currency. ' \
587 'You should remove the secondary currency on the account or select a multi-currency view on the journal.' % l.account_id.name))
588 if (l.amount_currency and not l.currency_id):
589 raise osv.except_osv(_('Error!'), _("You cannot create journal items with a secondary currency without recording both 'currency' and 'amount currency' field."))
590 if l.currency_id.id == l.company_id.currency_id.id:
591 raise osv.except_osv(_('Error!'), _("You cannot provide a secondary currency if it is the same than the company one."))
592 if l.amount_currency:
593 if (l.amount_currency > 0.0 and l.credit > 0.0) or (l.amount_currency < 0.0 and l.debit > 0.0):
594 raise osv.except_osv(_('Error!'), _("The amount expressed in the secondary currency must be positive when the journal item is a debit and negative when if it is a credit."))
595 return True
596
568 def _check_no_view(self, cr, uid, ids, context=None):597 def _check_no_view(self, cr, uid, ids, context=None):
569 lines = self.browse(cr, uid, ids, context=context)598 lines = self.browse(cr, uid, ids, context=context)
570 for l in lines:599 for l in lines:
@@ -620,14 +649,15 @@
620 return True649 return True
621650
622 _constraints = [651 _constraints = [
623 (_check_no_view, 'You cannot create journal items on an account of type view.', ['account_id']),652 (_check_all, 'Invalid line.', ['account_id', 'date', 'currency_id','amount_currency', 'company_id']),
624 (_check_no_closed, 'You cannot create journal items on closed account.', ['account_id']),653 # (_check_no_view, 'You cannot create journal items on an account of type view.', ['account_id']),
625 (_check_company_id, 'Account and Period must belong to the same company.', ['company_id']),654 # (_check_no_closed, 'You cannot create journal items on closed account.', ['account_id']),
626 (_check_date, 'The date of your Journal Entry is not in the defined period! You should change the date or remove this constraint from the journal.', ['date']),655 # (_check_company_id, 'Account and Period must belong to the same company.', ['company_id']),
627 (_check_currency, 'The selected account of your Journal Entry forces to provide a secondary currency. You should remove the secondary currency on the account or select a multi-currency view on the journal.', ['currency_id']),656 # (_check_date, 'The date of your Journal Entry is not in the defined period! You should change the date or remove this constraint from the journal.', ['date']),
628 (_check_currency_and_amount, "You cannot create journal items with a secondary currency without recording both 'currency' and 'amount currency' field.", ['currency_id','amount_currency']),657 # (_check_currency, 'The selected account of your Journal Entry forces to provide a secondary currency. You should remove the secondary currency on the account or select a multi-currency view on the journal.', ['currency_id']),
629 (_check_currency_amount, 'The amount expressed in the secondary currency must be positive when the journal item is a debit and negative when if it is a credit.', ['amount_currency']),658 # (_check_currency_and_amount, "You cannot create journal items with a secondary currency without recording both 'currency' and 'amount currency' field.", ['currency_id','amount_currency']),
630 (_check_currency_company, "You cannot provide a secondary currency if it is the same than the company one." , ['currency_id']),659 # (_check_currency_amount, 'The amount expressed in the secondary currency must be positive when the journal item is a debit and negative when if it is a credit.', ['amount_currency']),
660 # (_check_currency_company, "You cannot provide a secondary currency if it is the same than the company one." , ['currency_id']),
631 ]661 ]
632662
633 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id663 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
@@ -1209,20 +1239,6 @@
1209 if not ok:1239 if not ok:
1210 raise osv.except_osv(_('Bad Account!'), _('You cannot use this general account in this journal, check the tab \'Entry Controls\' on the related journal.'))1240 raise osv.except_osv(_('Bad Account!'), _('You cannot use this general account in this journal, check the tab \'Entry Controls\' on the related journal.'))
12111241
1212 if vals.get('analytic_account_id',False):
1213 if journal.analytic_journal_id:
1214 vals['analytic_lines'] = [(0,0, {
1215 'name': vals['name'],
1216 'date': vals.get('date', time.strftime('%Y-%m-%d')),
1217 'account_id': vals.get('analytic_account_id', False),
1218 'unit_amount': vals.get('quantity', 1.0),
1219 'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0),
1220 'general_account_id': vals.get('account_id', False),
1221 'journal_id': journal.analytic_journal_id.id,
1222 'ref': vals.get('ref', False),
1223 'user_id': uid
1224 })]
1225
1226 result = super(account_move_line, self).create(cr, uid, vals, context=context)1242 result = super(account_move_line, self).create(cr, uid, vals, context=context)
1227 # CREATE Taxes1243 # CREATE Taxes
1228 if vals.get('account_tax_id', False):1244 if vals.get('account_tax_id', False):
12291245
=== modified file 'stock/stock.py'
--- stock/stock.py 2013-09-20 11:24:37 +0000
+++ stock/stock.py 2013-09-27 15:33:32 +0000
@@ -2121,12 +2121,8 @@
2121 """ Changes state to confirmed or waiting.2121 """ Changes state to confirmed or waiting.
2122 @return: List of values2122 @return: List of values
2123 """2123 """
2124 todo = []2124 todo = self.search(cr, uid, [('id', 'in', ids), ('state', 'in', ('confirmed', 'waiting'))])
2125 for move in self.browse(cr, uid, ids):2125 return self.check_assign(cr, uid, todo)
2126 if move.state in ('confirmed', 'waiting'):
2127 todo.append(move.id)
2128 res = self.check_assign(cr, uid, todo)
2129 return res
21302126
2131 def force_assign(self, cr, uid, ids, context=None):2127 def force_assign(self, cr, uid, ids, context=None):
2132 """ Changes the state to assigned.2128 """ Changes the state to assigned.