Merge lp:~oddbloke/openobject-addons/623334 into lp:openobject-addons/5.0

Proposed by Dan Watkins
Status: Work in progress
Proposed branch: lp:~oddbloke/openobject-addons/623334
Merge into: lp:openobject-addons/5.0
Diff against target: 313 lines (+56/-114)
3 files modified
account/report/aged_trial_balance.py (+2/-1)
account/report/partner_balance.py (+8/-59)
account/report/third_party_ledger.py (+46/-54)
To merge this branch: bzr merge lp:~oddbloke/openobject-addons/623334
Reviewer Review Type Date Requested Status
OpenERP Core Team Pending
Review via email: mp+33526@code.launchpad.net

This proposal supersedes a proposal from 2010-08-24.

Description of the change

Fixes bug #623334, which involves Partner Account reports in the account module showing incorrect figures.

Essentially, wherever credit and debit are calculated, we now join with the account_moves that the account_move_lines are part of, to ensure that they aren't in Draft status.

In the Partner Ledger report, I've then consolidated the shared SQL strings into _get_line_sql, _get_credit_sql and _get_debit_sql.

Apologies for the proposal spam, I haven't quite got the hang of this part of LP yet.

To post a comment you must log in.
Revision history for this message
Dan Watkins (oddbloke) wrote : Posted in a previous version of this proposal

So this doesn't fully fix bug #623334, that was a mis-type. It does, however, fix the Partner Ledger report problem.

Revision history for this message
Dan Watkins (oddbloke) wrote :

The above comment is no longer correct, I think this does fix bug #623334 fully.

Revision history for this message
Dimitri John Ledkov (ex-credativ) (dle-credativ) wrote :

How come this hasn't been reviewed?

Unmerged revisions

2827. By Dan Watkins

Fix aged_trial_balance report.

2826. By Dan Watkins

Fix individual lines in partner_balance report.

2825. By Dan Watkins

Fix grand total display in the partner_balance report.

2824. By Dan Watkins

Remove unused _sum_sdebit and _sum_scredit methods from partner_balance report.

2823. By Dan Watkins

Fix third party ledger report.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'account/report/aged_trial_balance.py'
--- account/report/aged_trial_balance.py 2010-06-14 10:58:21 +0000
+++ account/report/aged_trial_balance.py 2010-08-24 13:59:55 +0000
@@ -79,7 +79,7 @@
79 # This dictionary will store the debit-credit for all partners, using partner_id as key.79 # This dictionary will store the debit-credit for all partners, using partner_id as key.
80 totals = {}80 totals = {}
81 self.cr.execute("""SELECT partner_id, SUM(debit-credit)81 self.cr.execute("""SELECT partner_id, SUM(debit-credit)
82 FROM account_move_line AS line, account_account82 FROM (account_move_line AS line LEFT JOIN account_move m ON (line.move_id = m.id)), account_account
83 WHERE (line.account_id = account_account.id)83 WHERE (line.account_id = account_account.id)
84 AND (account_account.type IN %s)84 AND (account_account.type IN %s)
85 AND (partner_id in %s)85 AND (partner_id in %s)
@@ -87,6 +87,7 @@
87 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))87 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
88 AND (account_account.company_id = %s)88 AND (account_account.company_id = %s)
89 AND account_account.active89 AND account_account.active
90 AND m.state = 'posted'
90 GROUP BY partner_id""" , (91 GROUP BY partner_id""" , (
91 self.ACCOUNT_TYPE, partner_ids,92 self.ACCOUNT_TYPE, partner_ids,
92 form['date1'], form['company_id']))93 form['date1'], form['company_id']))
9394
=== modified file 'account/report/partner_balance.py'
--- account/report/partner_balance.py 2010-08-17 07:00:51 +0000
+++ account/report/partner_balance.py 2010-08-24 13:59:55 +0000
@@ -37,8 +37,6 @@
37 'sum_debit': self._sum_debit,37 'sum_debit': self._sum_debit,
38 'sum_credit': self._sum_credit,38 'sum_credit': self._sum_credit,
39 'sum_litige': self._sum_litige,39 'sum_litige': self._sum_litige,
40 'sum_sdebit': self._sum_sdebit,
41 'sum_scredit': self._sum_scredit,
42 'solde_debit': self._solde_balance_debit,40 'solde_debit': self._solde_balance_debit,
43 'solde_credit': self._solde_balance_credit,41 'solde_credit': self._solde_balance_credit,
44 'get_company': self._get_company,42 'get_company': self._get_company,
@@ -213,9 +211,11 @@
213 ") AS enlitige " \211 ") AS enlitige " \
214 "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \212 "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
215 "JOIN account_account ac ON (l.account_id = ac.id)" \213 "JOIN account_account ac ON (l.account_id = ac.id)" \
214 "LEFT JOIN account_move m ON (l.move_id = m.id) " \
216 "WHERE ac.type IN %s " \215 "WHERE ac.type IN %s " \
217 "AND l.date IN %s " \216 "AND l.date IN %s " \
218 "AND ac.company_id = %s " \217 "AND ac.company_id = %s " \
218 "AND m.state = 'posted' " \
219 "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \219 "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
220 "ORDER BY l.account_id,p.name",220 "ORDER BY l.account_id,p.name",
221 (tuple(self.date_lst), self.ACCOUNT_TYPE, tuple(self.date_lst), data['form']['company_id']))221 (tuple(self.date_lst), self.ACCOUNT_TYPE, tuple(self.date_lst), data['form']['company_id']))
@@ -355,8 +355,10 @@
355 self.cr.execute(355 self.cr.execute(
356 "SELECT sum(debit) " \356 "SELECT sum(debit) " \
357 "FROM account_move_line AS l " \357 "FROM account_move_line AS l " \
358 "LEFT JOIN account_move m ON (l.move_id = m.id) " \
358 "WHERE l.account_id IN (" + self.account_ids + ") " \359 "WHERE l.account_id IN (" + self.account_ids + ") " \
359 "AND l.date IN %s",360 "AND l.date IN %s" \
361 "AND m.state = 'posted' ",
360 (tuple(self.date_lst),))362 (tuple(self.date_lst),))
361 temp_res = float(self.cr.fetchone()[0] or 0.0)363 temp_res = float(self.cr.fetchone()[0] or 0.0)
362 result_tmp = result_tmp + temp_res364 result_tmp = result_tmp + temp_res
@@ -374,8 +376,10 @@
374 self.cr.execute(376 self.cr.execute(
375 "SELECT sum(credit) " \377 "SELECT sum(credit) " \
376 "FROM account_move_line AS l " \378 "FROM account_move_line AS l " \
379 "LEFT JOIN account_move m ON (l.move_id = m.id) " \
377 "WHERE l.account_id IN (" + self.account_ids + ") " \380 "WHERE l.account_id IN (" + self.account_ids + ") " \
378 "AND l.date IN %s",381 "AND l.date IN %s" \
382 "AND m.state = 'posted' ",
379 (tuple(self.date_lst),))383 (tuple(self.date_lst),))
380 temp_res = float(self.cr.fetchone()[0] or 0.0)384 temp_res = float(self.cr.fetchone()[0] or 0.0)
381 result_tmp = result_tmp + temp_res385 result_tmp = result_tmp + temp_res
@@ -401,61 +405,6 @@
401405
402 return result_tmp406 return result_tmp
403407
404 def _sum_sdebit(self,data):
405 if not self.ids:
406 return 0.0
407 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
408 result_tmp = 0.0
409 a = 0.0
410 if self.date_lst:
411 self.cr.execute(
412 "SELECT CASE WHEN sum(debit) > sum(credit) " \
413 "THEN sum(debit) - sum(credit) " \
414 "ELSE 0 " \
415 "END " \
416 "FROM account_move_line AS l " \
417 "WHERE l.account_id IN (" + self.account_ids + ") " \
418 "AND l.date IN %s " \
419 "GROUP BY l.partner_id",
420 (tuple(self.date_lst),))
421 a = self.cr.fetchone()[0]
422
423 if self.cr.fetchone() != None:
424 result_tmp = result_tmp + (a or 0.0)
425 else:
426 result_tmp = 0.0
427
428 return result_tmp
429
430 def _sum_scredit(self,data):
431
432 if not self.ids:
433 return 0.0
434 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
435
436 result_tmp = 0.0
437 a = 0.0
438 if self.date_lst:
439 self.cr.execute(
440 "SELECT CASE WHEN sum(debit) < sum(credit) " \
441 "THEN sum(credit) - sum(debit) " \
442 "ELSE 0 " \
443 "END " \
444 "FROM account_move_line AS l " \
445 "WHERE l.account_id IN (" + self.account_ids + ") " \
446 "AND l.date IN %s " \
447 "GROUP BY l.partner_id",
448 (tuple(self.date_lst),))
449 a = self.cr.fetchone()[0] or 0.0
450
451 if self.cr.fetchone() != None:
452 result_tmp = result_tmp + (a or 0.0)
453
454 else:
455 result_tmp = 0.0
456
457 return result_tmp
458
459 def _solde_balance_debit(self,data):408 def _solde_balance_debit(self,data):
460 debit, credit = self._sum_debit(data), self._sum_credit(data)409 debit, credit = self._sum_debit(data), self._sum_credit(data)
461 return debit > credit and debit - credit410 return debit > credit and debit - credit
462411
=== modified file 'account/report/third_party_ledger.py'
--- account/report/third_party_ledger.py 2010-05-27 10:59:00 +0000
+++ account/report/third_party_ledger.py 2010-08-24 13:59:55 +0000
@@ -256,12 +256,15 @@
256 if self.date_lst_string:256 if self.date_lst_string:
257 self.cr.execute(257 self.cr.execute(
258 "SELECT l.id,l.date,j.code, l.ref, l.name, l.debit, l.credit " \258 "SELECT l.id,l.date,j.code, l.ref, l.name, l.debit, l.credit " \
259 "FROM account_move_line l " \259 "FROM (account_move_line l " \
260 "LEFT JOIN account_journal j " \260 "LEFT JOIN account_journal j " \
261 "ON (l.journal_id = j.id) " \261 "ON (l.journal_id = j.id)) " \
262 "LEFT JOIN account_move m " \
263 "ON (l.move_id = m.id) " \
262 "WHERE l.partner_id = %s " \264 "WHERE l.partner_id = %s " \
263 "AND l.account_id IN (" + self.account_ids + ") " \265 "AND l.account_id IN (" + self.account_ids + ") " \
264 "AND l.date IN (" + self.date_lst_string + ") " \266 "AND l.date IN (" + self.date_lst_string + ") " \
267 "AND m.state = 'posted' " \
265 " " + RECONCILE_TAG + " "\268 " " + RECONCILE_TAG + " "\
266 "ORDER BY l.id",269 "ORDER BY l.id",
267 (partner.id,))270 (partner.id,))
@@ -274,6 +277,19 @@
274277
275 return full_account278 return full_account
276279
280 def _get_line_sql(self):
281 return "SELECT sum(line.%s) " \
282 "FROM account_move_line line " \
283 "LEFT JOIN account_move m ON (line.move_id = m.id) " \
284 "WHERE line.account_id IN (" + self.account_ids + ") " \
285 "AND m.state = 'posted' "
286
287 def _get_credit_sql(self):
288 return self._get_line_sql() % ("credit", )
289
290 def _get_debit_sql(self):
291 return self._get_line_sql() % ("debit", )
292
277 def _sum_debit_partner(self, partner,data):293 def _sum_debit_partner(self, partner,data):
278294
279 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')295 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
@@ -283,13 +299,10 @@
283 else:299 else:
284 RECONCILE_TAG = "AND reconcile_id IS NULL"300 RECONCILE_TAG = "AND reconcile_id IS NULL"
285 if self.date_lst and data['form']['soldeinit'] :301 if self.date_lst and data['form']['soldeinit'] :
286 self.cr.execute(302 self.cr.execute(self._get_debit_sql() +
287 "SELECT sum(debit) " \303 "AND line.partner_id = %s " \
288 "FROM account_move_line " \304 "AND line.reconcile_id IS NULL " \
289 "WHERE partner_id = %s " \305 "AND line.date < %s ",
290 "AND account_id IN (" + self.account_ids + ") " \
291 "AND reconcile_id IS NULL " \
292 "AND date < %s " ,
293 (partner.id, self.date_lst[0],))306 (partner.id, self.date_lst[0],))
294 contemp = self.cr.fetchone()307 contemp = self.cr.fetchone()
295 if contemp != None:308 if contemp != None:
@@ -298,13 +311,10 @@
298 result_tmp = result_tmp + 0.0311 result_tmp = result_tmp + 0.0
299312
300 if self.date_lst_string:313 if self.date_lst_string:
301 self.cr.execute(314 self.cr.execute(self._get_debit_sql() +
302 "SELECT sum(debit) " \315 "AND line.partner_id = %s " \
303 "FROM account_move_line " \
304 "WHERE partner_id = %s " \
305 "AND account_id IN (" + self.account_ids + ") " \
306 " " + RECONCILE_TAG + " " \316 " " + RECONCILE_TAG + " " \
307 "AND date IN (" + self.date_lst_string + ") " ,317 "AND line.date IN (" + self.date_lst_string + ") ",
308 (partner.id,))318 (partner.id,))
309319
310 contemp = self.cr.fetchone()320 contemp = self.cr.fetchone()
@@ -322,13 +332,10 @@
322 else:332 else:
323 RECONCILE_TAG = "AND reconcile_id IS NULL"333 RECONCILE_TAG = "AND reconcile_id IS NULL"
324 if self.date_lst and data['form']['soldeinit'] :334 if self.date_lst and data['form']['soldeinit'] :
325 self.cr.execute(335 self.cr.execute(self._get_credit_sql() +
326 "SELECT sum(credit) " \336 "AND line.partner_id=%s " \
327 "FROM account_move_line " \337 "AND line.reconcile_id IS NULL " \
328 "WHERE partner_id=%s " \338 "AND line.date < %s ",
329 "AND account_id IN (" + self.account_ids + ") " \
330 "AND reconcile_id IS NULL " \
331 "AND date < %s " ,
332 (partner.id,self.date_lst[0],))339 (partner.id,self.date_lst[0],))
333 contemp = self.cr.fetchone()340 contemp = self.cr.fetchone()
334 if contemp != None:341 if contemp != None:
@@ -337,13 +344,10 @@
337 result_tmp = result_tmp + 0.0344 result_tmp = result_tmp + 0.0
338345
339 if self.date_lst_string:346 if self.date_lst_string:
340 self.cr.execute(347 self.cr.execute(self._get_credit_sql() +
341 "SELECT sum(credit) " \348 "AND line.partner_id=%s " \
342 "FROM account_move_line " \
343 "WHERE partner_id=%s " \
344 "AND account_id IN (" + self.account_ids + ") " \
345 " " + RECONCILE_TAG + " " \349 " " + RECONCILE_TAG + " " \
346 "AND date IN (" + self.date_lst_string + ") " ,350 "AND line.date IN (" + self.date_lst_string + ") ",
347 (partner.id,))351 (partner.id,))
348352
349 contemp = self.cr.fetchone()353 contemp = self.cr.fetchone()
@@ -363,13 +367,10 @@
363 else:367 else:
364 RECONCILE_TAG = "AND reconcile_id IS NULL"368 RECONCILE_TAG = "AND reconcile_id IS NULL"
365 if self.date_lst and data['form']['soldeinit'] :369 if self.date_lst and data['form']['soldeinit'] :
366 self.cr.execute(370 self.cr.execute(self._get_debit_sql() +
367 "SELECT sum(debit) " \371 "AND line.partner_id IN (" + self.partner_ids + ") " \
368 "FROM account_move_line " \372 "AND line.reconcile_id IS NULL " \
369 "WHERE partner_id IN (" + self.partner_ids + ") " \373 "AND line.date < %s ",
370 "AND account_id IN (" + self.account_ids + ") " \
371 "AND reconcile_id IS NULL " \
372 "AND date < %s " ,
373 (self.date_lst[0],))374 (self.date_lst[0],))
374 contemp = self.cr.fetchone()375 contemp = self.cr.fetchone()
375 if contemp != None:376 if contemp != None:
@@ -378,13 +379,10 @@
378 result_tmp = result_tmp + 0.0379 result_tmp = result_tmp + 0.0
379380
380 if self.date_lst_string:381 if self.date_lst_string:
381 self.cr.execute(382 self.cr.execute(self._get_debit_sql() +
382 "SELECT sum(debit) " \383 "AND line.partner_id IN (" + self.partner_ids + ") " \
383 "FROM account_move_line " \
384 "WHERE partner_id IN (" + self.partner_ids + ") " \
385 "AND account_id IN (" + self.account_ids + ") " \
386 " " + RECONCILE_TAG + " " \384 " " + RECONCILE_TAG + " " \
387 "AND date IN (" + self.date_lst_string + ") "385 "AND line.date IN (" + self.date_lst_string + ") ",
388 )386 )
389387
390 contemp = self.cr.fetchone()388 contemp = self.cr.fetchone()
@@ -406,13 +404,10 @@
406 else:404 else:
407 RECONCILE_TAG = "AND reconcile_id IS NULL"405 RECONCILE_TAG = "AND reconcile_id IS NULL"
408 if self.date_lst and data['form']['soldeinit'] :406 if self.date_lst and data['form']['soldeinit'] :
409 self.cr.execute(407 self.cr.execute(self._get_credit_sql() +
410 "SELECT sum(credit) " \408 "AND line.partner_id IN (" + self.partner_ids + ") " \
411 "FROM account_move_line " \409 "AND line.reconcile_id IS NULL " \
412 "WHERE partner_id IN (" + self.partner_ids + ") " \410 "AND line.date < %s ",
413 "AND account_id IN (" + self.account_ids + ") " \
414 "AND reconcile_id IS NULL " \
415 "AND date < %s " ,
416 (self.date_lst[0],))411 (self.date_lst[0],))
417 contemp = self.cr.fetchone()412 contemp = self.cr.fetchone()
418 if contemp != None:413 if contemp != None:
@@ -421,13 +416,10 @@
421 result_tmp = result_tmp + 0.0416 result_tmp = result_tmp + 0.0
422417
423 if self.date_lst_string:418 if self.date_lst_string:
424 self.cr.execute(419 self.cr.execute(self._get_credit_sql() +
425 "SELECT sum(credit) " \420 "AND line.partner_id IN (" + self.partner_ids + ") " \
426 "FROM account_move_line " \
427 "WHERE partner_id IN (" + self.partner_ids + ") " \
428 "AND account_id IN (" + self.account_ids + ") " \
429 " " + RECONCILE_TAG + " " \421 " " + RECONCILE_TAG + " " \
430 "AND date IN (" + self.date_lst_string + ") "422 "AND line.date IN (" + self.date_lst_string + ") ",
431 )423 )
432 contemp = self.cr.fetchone()424 contemp = self.cr.fetchone()
433 if contemp != None:425 if contemp != None: