[MERGE] [FIX] account: performance improvement on account.analytic.lines

don't create new analytic lines at move creation, will do it once the move is balanced
don't remove analytic lines (to avoid duplicates) at the begining of the validation of a move, will do it once we create the new correct analytic lines (opw 597719)

bzr revid: mat@openerp.com-20131206131125-fvzy62qqx3gnwmw5
This commit is contained in:
Martin Trigaux 2013-12-06 14:11:25 +01:00
commit a3847ce648
2 changed files with 2 additions and 19 deletions

View File

@ -1583,11 +1583,6 @@ class account_move(osv.osv):
obj_analytic_line = self.pool.get('account.analytic.line')
obj_move_line = self.pool.get('account.move.line')
for move in self.browse(cr, uid, ids, context):
# Unlink old analytic lines on move_lines
for obj_line in move.line_id:
for obj in obj_line.analytic_lines:
obj_analytic_line.unlink(cr,uid,obj.id)
journal = move.journal_id
amount = 0
line_ids = []

View File

@ -193,6 +193,8 @@ class account_move_line(osv.osv):
if obj_line.analytic_account_id:
if not obj_line.journal_id.analytic_journal_id:
raise osv.except_osv(_('No Analytic Journal!'),_("You have to define an analytic journal on the '%s' journal!") % (obj_line.journal_id.name, ))
if obj_line.analytic_lines:
acc_ana_line_obj.unlink(cr,uid,[obj.id for obj in obj_line.analytic_lines])
vals_line = self._prepare_analytic_line(cr, uid, obj_line, context=context)
acc_ana_line_obj.create(cr, uid, vals_line)
return True
@ -1209,20 +1211,6 @@ class account_move_line(osv.osv):
if not ok:
raise osv.except_osv(_('Bad Account!'), _('You cannot use this general account in this journal, check the tab \'Entry Controls\' on the related journal.'))
if vals.get('analytic_account_id',False):
if journal.analytic_journal_id:
vals['analytic_lines'] = [(0,0, {
'name': vals['name'],
'date': vals.get('date', time.strftime('%Y-%m-%d')),
'account_id': vals.get('analytic_account_id', False),
'unit_amount': vals.get('quantity', 1.0),
'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0),
'general_account_id': vals.get('account_id', False),
'journal_id': journal.analytic_journal_id.id,
'ref': vals.get('ref', False),
'user_id': uid
})]
result = super(account_move_line, self).create(cr, uid, vals, context=context)
# CREATE Taxes
if vals.get('account_tax_id', False):