[FIX] account: performance improvement on analytic line creation
authorMartin Trigaux <mat@openerp.com>
Fri, 6 Dec 2013 10:46:59 +0000 (11:46 +0100)
committerMartin Trigaux <mat@openerp.com>
Fri, 6 Dec 2013 10:46:59 +0000 (11:46 +0100)
 remove analytic lines (to avoid duplicates) only when create new one instead of each validation of the account move
don't create new analytic lines at move creation, will do it once the move is balanced (unbalanced move should not create analytic lines yet)

bzr revid: mat@openerp.com-20131206104659-vct8a5l9o4nmhwqs

addons/account/account.py
addons/account/account_move_line.py

index e37ea0e..5dce6aa 100644 (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 = []
index 3282609..babd4e9 100644 (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):