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
1=== modified file 'account/account.py'
2--- account/account.py 2013-09-18 14:31:46 +0000
3+++ account/account.py 2013-09-27 15:33:32 +0000
4@@ -1580,11 +1580,6 @@
5 obj_analytic_line = self.pool.get('account.analytic.line')
6 obj_move_line = self.pool.get('account.move.line')
7 for move in self.browse(cr, uid, ids, context):
8- # Unlink old analytic lines on move_lines
9- for obj_line in move.line_id:
10- for obj in obj_line.analytic_lines:
11- obj_analytic_line.unlink(cr,uid,obj.id)
12-
13 journal = move.journal_id
14 amount = 0
15 line_ids = []
16
17=== modified file 'account/account_bank_statement.py'
18--- account/account_bank_statement.py 2013-06-07 11:38:29 +0000
19+++ account/account_bank_statement.py 2013-09-27 15:33:32 +0000
20@@ -220,9 +220,8 @@
21 res_currency_obj = self.pool.get('res.currency')
22 amt_cur = -res_currency_obj.compute(cr, uid, company_currency_id, cur_id, amount, context=context)
23
24- res = self._prepare_move_line_vals(cr, uid, st_line, move_id, debit, credit,
25+ return self._prepare_move_line_vals(cr, uid, st_line, move_id, debit, credit,
26 amount_currency=amt_cur, currency_id=cur_id, analytic_id=anl_id, context=context)
27- return res
28
29 def _get_counter_part_account(sefl, cr, uid, st_line, context=None):
30 """Retrieve the account to use in the counterpart move.
31@@ -342,7 +341,7 @@
32 account_bank_statement_line_obj.write(cr, uid, [st_line.id], {
33 'move_ids': [(4, move_id, False)]
34 })
35- torec = []
36+
37 acc_cur = ((st_line.amount<=0) and st.journal_id.default_debit_account_id) or st_line.account_id
38
39 context.update({
40@@ -353,18 +352,14 @@
41
42 bank_move_vals = self._prepare_bank_move_line(cr, uid, st_line, move_id, amount,
43 company_currency_id, context=context)
44- move_line_id = account_move_line_obj.create(cr, uid, bank_move_vals, context=context)
45- torec.append(move_line_id)
46-
47 counterpart_move_vals = self._prepare_counterpart_move_line(cr, uid, st_line, move_id,
48 amount, company_currency_id, context=context)
49- account_move_line_obj.create(cr, uid, counterpart_move_vals, context=context)
50-
51- for line in account_move_line_obj.browse(cr, uid, [x.id for x in
52- account_move_obj.browse(cr, uid, move_id,
53- context=context).line_id],
54- context=context):
55- if line.state <> 'valid':
56+
57+ account_move_obj.write(cr, uid, [move_id], {'line_id': [(0, 0, bank_move_vals), (0, 0, counterpart_move_vals)]}, context)
58+
59+ invalid_line_ids = account_move_line_obj.search(cr, uid, [('move_id', '=', move_id), ('state', '<>', 'valid')], context=context)
60+ if invalid_line_ids:
61+ for line in account_move_line_obj.browse(cr, uid, invalid_line_ids, context=context):
62 raise osv.except_osv(_('Error!'),
63 _('Journal item "%s" is not valid.') % line.name)
64
65
66=== modified file 'account/account_move_line.py'
67--- account/account_move_line.py 2013-09-18 14:31:46 +0000
68+++ account/account_move_line.py 2013-09-27 15:33:32 +0000
69@@ -193,6 +193,8 @@
70 if obj_line.analytic_account_id:
71 if not obj_line.journal_id.analytic_journal_id:
72 raise osv.except_osv(_('No Analytic Journal!'),_("You have to define an analytic journal on the '%s' journal!") % (obj_line.journal_id.name, ))
73+ if obj_line.analytic_lines:
74+ acc_ana_line_obj.unlink(cr,uid,[obj.id for obj in obj_line.analytic_lines])
75 vals_line = self._prepare_analytic_line(cr, uid, obj_line, context=context)
76 acc_ana_line_obj.create(cr, uid, vals_line)
77 return True
78@@ -565,6 +567,33 @@
79 if not cr.fetchone():
80 cr.execute('CREATE INDEX account_move_line_journal_id_period_id_index ON account_move_line (journal_id, period_id)')
81
82+ def _check_all(self, cr, uid, ids, context=None):
83+ for l in self.browse(cr, uid, ids, context=context):
84+ if l.account_id.type == 'view':
85+ 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))
86+ elif l.account_id.type == 'closed':
87+ raise osv.except_osv(_('Error!'), _('You cannot create journal items on a closed account %s %s.') % (l.account_id.code, l.account_id.name))
88+
89+ if l.company_id != l.account_id.company_id or l.company_id != l.period_id.company_id:
90+ raise osv.except_osv(_('Error!'), _('Account and Period must belong to the company %s.') % (l.company_id.name))
91+
92+ if l.journal_id.allow_date:
93+ 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'):
94+ 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.'))
95+
96+ if l.account_id.currency_id:
97+ if not l.currency_id or not l.currency_id.id == l.account_id.currency_id.id:
98+ raise osv.except_osv(_('Error!'), _('The selected account %s of your Journal Entry forces to provide a secondary currency. ' \
99+ 'You should remove the secondary currency on the account or select a multi-currency view on the journal.' % l.account_id.name))
100+ if (l.amount_currency and not l.currency_id):
101+ raise osv.except_osv(_('Error!'), _("You cannot create journal items with a secondary currency without recording both 'currency' and 'amount currency' field."))
102+ if l.currency_id.id == l.company_id.currency_id.id:
103+ raise osv.except_osv(_('Error!'), _("You cannot provide a secondary currency if it is the same than the company one."))
104+ if l.amount_currency:
105+ if (l.amount_currency > 0.0 and l.credit > 0.0) or (l.amount_currency < 0.0 and l.debit > 0.0):
106+ 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."))
107+ return True
108+
109 def _check_no_view(self, cr, uid, ids, context=None):
110 lines = self.browse(cr, uid, ids, context=context)
111 for l in lines:
112@@ -620,14 +649,15 @@
113 return True
114
115 _constraints = [
116- (_check_no_view, 'You cannot create journal items on an account of type view.', ['account_id']),
117- (_check_no_closed, 'You cannot create journal items on closed account.', ['account_id']),
118- (_check_company_id, 'Account and Period must belong to the same company.', ['company_id']),
119- (_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']),
120- (_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']),
121- (_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']),
122- (_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']),
123- (_check_currency_company, "You cannot provide a secondary currency if it is the same than the company one." , ['currency_id']),
124+ (_check_all, 'Invalid line.', ['account_id', 'date', 'currency_id','amount_currency', 'company_id']),
125+ # (_check_no_view, 'You cannot create journal items on an account of type view.', ['account_id']),
126+ # (_check_no_closed, 'You cannot create journal items on closed account.', ['account_id']),
127+ # (_check_company_id, 'Account and Period must belong to the same company.', ['company_id']),
128+ # (_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']),
129+ # (_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']),
130+ # (_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']),
131+ # (_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']),
132+ # (_check_currency_company, "You cannot provide a secondary currency if it is the same than the company one." , ['currency_id']),
133 ]
134
135 #TODO: ONCHANGE_ACCOUNT_ID: set account_tax_id
136@@ -1209,20 +1239,6 @@
137 if not ok:
138 raise osv.except_osv(_('Bad Account!'), _('You cannot use this general account in this journal, check the tab \'Entry Controls\' on the related journal.'))
139
140- if vals.get('analytic_account_id',False):
141- if journal.analytic_journal_id:
142- vals['analytic_lines'] = [(0,0, {
143- 'name': vals['name'],
144- 'date': vals.get('date', time.strftime('%Y-%m-%d')),
145- 'account_id': vals.get('analytic_account_id', False),
146- 'unit_amount': vals.get('quantity', 1.0),
147- 'amount': vals.get('debit', 0.0) or vals.get('credit', 0.0),
148- 'general_account_id': vals.get('account_id', False),
149- 'journal_id': journal.analytic_journal_id.id,
150- 'ref': vals.get('ref', False),
151- 'user_id': uid
152- })]
153-
154 result = super(account_move_line, self).create(cr, uid, vals, context=context)
155 # CREATE Taxes
156 if vals.get('account_tax_id', False):
157
158=== modified file 'stock/stock.py'
159--- stock/stock.py 2013-09-20 11:24:37 +0000
160+++ stock/stock.py 2013-09-27 15:33:32 +0000
161@@ -2121,12 +2121,8 @@
162 """ Changes state to confirmed or waiting.
163 @return: List of values
164 """
165- todo = []
166- for move in self.browse(cr, uid, ids):
167- if move.state in ('confirmed', 'waiting'):
168- todo.append(move.id)
169- res = self.check_assign(cr, uid, todo)
170- return res
171+ todo = self.search(cr, uid, [('id', 'in', ids), ('state', 'in', ('confirmed', 'waiting'))])
172+ return self.check_assign(cr, uid, todo)
173
174 def force_assign(self, cr, uid, ids, context=None):
175 """ Changes the state to assigned.