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
1=== modified file 'account/report/aged_trial_balance.py'
2--- account/report/aged_trial_balance.py 2010-06-14 10:58:21 +0000
3+++ account/report/aged_trial_balance.py 2010-08-24 13:59:55 +0000
4@@ -79,7 +79,7 @@
5 # This dictionary will store the debit-credit for all partners, using partner_id as key.
6 totals = {}
7 self.cr.execute("""SELECT partner_id, SUM(debit-credit)
8- FROM account_move_line AS line, account_account
9+ FROM (account_move_line AS line LEFT JOIN account_move m ON (line.move_id = m.id)), account_account
10 WHERE (line.account_id = account_account.id)
11 AND (account_account.type IN %s)
12 AND (partner_id in %s)
13@@ -87,6 +87,7 @@
14 OR (reconcile_id IN (SELECT recon.id FROM account_move_reconcile AS recon WHERE recon.create_date > %s )))
15 AND (account_account.company_id = %s)
16 AND account_account.active
17+ AND m.state = 'posted'
18 GROUP BY partner_id""" , (
19 self.ACCOUNT_TYPE, partner_ids,
20 form['date1'], form['company_id']))
21
22=== modified file 'account/report/partner_balance.py'
23--- account/report/partner_balance.py 2010-08-17 07:00:51 +0000
24+++ account/report/partner_balance.py 2010-08-24 13:59:55 +0000
25@@ -37,8 +37,6 @@
26 'sum_debit': self._sum_debit,
27 'sum_credit': self._sum_credit,
28 'sum_litige': self._sum_litige,
29- 'sum_sdebit': self._sum_sdebit,
30- 'sum_scredit': self._sum_scredit,
31 'solde_debit': self._solde_balance_debit,
32 'solde_credit': self._solde_balance_credit,
33 'get_company': self._get_company,
34@@ -213,9 +211,11 @@
35 ") AS enlitige " \
36 "FROM account_move_line l LEFT JOIN res_partner p ON (l.partner_id=p.id) " \
37 "JOIN account_account ac ON (l.account_id = ac.id)" \
38+ "LEFT JOIN account_move m ON (l.move_id = m.id) " \
39 "WHERE ac.type IN %s " \
40 "AND l.date IN %s " \
41 "AND ac.company_id = %s " \
42+ "AND m.state = 'posted' " \
43 "GROUP BY p.id, p.ref, p.name,l.account_id,ac.name,ac.code " \
44 "ORDER BY l.account_id,p.name",
45 (tuple(self.date_lst), self.ACCOUNT_TYPE, tuple(self.date_lst), data['form']['company_id']))
46@@ -355,8 +355,10 @@
47 self.cr.execute(
48 "SELECT sum(debit) " \
49 "FROM account_move_line AS l " \
50+ "LEFT JOIN account_move m ON (l.move_id = m.id) " \
51 "WHERE l.account_id IN (" + self.account_ids + ") " \
52- "AND l.date IN %s",
53+ "AND l.date IN %s" \
54+ "AND m.state = 'posted' ",
55 (tuple(self.date_lst),))
56 temp_res = float(self.cr.fetchone()[0] or 0.0)
57 result_tmp = result_tmp + temp_res
58@@ -374,8 +376,10 @@
59 self.cr.execute(
60 "SELECT sum(credit) " \
61 "FROM account_move_line AS l " \
62+ "LEFT JOIN account_move m ON (l.move_id = m.id) " \
63 "WHERE l.account_id IN (" + self.account_ids + ") " \
64- "AND l.date IN %s",
65+ "AND l.date IN %s" \
66+ "AND m.state = 'posted' ",
67 (tuple(self.date_lst),))
68 temp_res = float(self.cr.fetchone()[0] or 0.0)
69 result_tmp = result_tmp + temp_res
70@@ -401,61 +405,6 @@
71
72 return result_tmp
73
74- def _sum_sdebit(self,data):
75- if not self.ids:
76- return 0.0
77- account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
78- result_tmp = 0.0
79- a = 0.0
80- if self.date_lst:
81- self.cr.execute(
82- "SELECT CASE WHEN sum(debit) > sum(credit) " \
83- "THEN sum(debit) - sum(credit) " \
84- "ELSE 0 " \
85- "END " \
86- "FROM account_move_line AS l " \
87- "WHERE l.account_id IN (" + self.account_ids + ") " \
88- "AND l.date IN %s " \
89- "GROUP BY l.partner_id",
90- (tuple(self.date_lst),))
91- a = self.cr.fetchone()[0]
92-
93- if self.cr.fetchone() != None:
94- result_tmp = result_tmp + (a or 0.0)
95- else:
96- result_tmp = 0.0
97-
98- return result_tmp
99-
100- def _sum_scredit(self,data):
101-
102- if not self.ids:
103- return 0.0
104- account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
105-
106- result_tmp = 0.0
107- a = 0.0
108- if self.date_lst:
109- self.cr.execute(
110- "SELECT CASE WHEN sum(debit) < sum(credit) " \
111- "THEN sum(credit) - sum(debit) " \
112- "ELSE 0 " \
113- "END " \
114- "FROM account_move_line AS l " \
115- "WHERE l.account_id IN (" + self.account_ids + ") " \
116- "AND l.date IN %s " \
117- "GROUP BY l.partner_id",
118- (tuple(self.date_lst),))
119- a = self.cr.fetchone()[0] or 0.0
120-
121- if self.cr.fetchone() != None:
122- result_tmp = result_tmp + (a or 0.0)
123-
124- else:
125- result_tmp = 0.0
126-
127- return result_tmp
128-
129 def _solde_balance_debit(self,data):
130 debit, credit = self._sum_debit(data), self._sum_credit(data)
131 return debit > credit and debit - credit
132
133=== modified file 'account/report/third_party_ledger.py'
134--- account/report/third_party_ledger.py 2010-05-27 10:59:00 +0000
135+++ account/report/third_party_ledger.py 2010-08-24 13:59:55 +0000
136@@ -256,12 +256,15 @@
137 if self.date_lst_string:
138 self.cr.execute(
139 "SELECT l.id,l.date,j.code, l.ref, l.name, l.debit, l.credit " \
140- "FROM account_move_line l " \
141+ "FROM (account_move_line l " \
142 "LEFT JOIN account_journal j " \
143- "ON (l.journal_id = j.id) " \
144+ "ON (l.journal_id = j.id)) " \
145+ "LEFT JOIN account_move m " \
146+ "ON (l.move_id = m.id) " \
147 "WHERE l.partner_id = %s " \
148 "AND l.account_id IN (" + self.account_ids + ") " \
149 "AND l.date IN (" + self.date_lst_string + ") " \
150+ "AND m.state = 'posted' " \
151 " " + RECONCILE_TAG + " "\
152 "ORDER BY l.id",
153 (partner.id,))
154@@ -274,6 +277,19 @@
155
156 return full_account
157
158+ def _get_line_sql(self):
159+ return "SELECT sum(line.%s) " \
160+ "FROM account_move_line line " \
161+ "LEFT JOIN account_move m ON (line.move_id = m.id) " \
162+ "WHERE line.account_id IN (" + self.account_ids + ") " \
163+ "AND m.state = 'posted' "
164+
165+ def _get_credit_sql(self):
166+ return self._get_line_sql() % ("credit", )
167+
168+ def _get_debit_sql(self):
169+ return self._get_line_sql() % ("debit", )
170+
171 def _sum_debit_partner(self, partner,data):
172
173 account_move_line_obj = pooler.get_pool(self.cr.dbname).get('account.move.line')
174@@ -283,13 +299,10 @@
175 else:
176 RECONCILE_TAG = "AND reconcile_id IS NULL"
177 if self.date_lst and data['form']['soldeinit'] :
178- self.cr.execute(
179- "SELECT sum(debit) " \
180- "FROM account_move_line " \
181- "WHERE partner_id = %s " \
182- "AND account_id IN (" + self.account_ids + ") " \
183- "AND reconcile_id IS NULL " \
184- "AND date < %s " ,
185+ self.cr.execute(self._get_debit_sql() +
186+ "AND line.partner_id = %s " \
187+ "AND line.reconcile_id IS NULL " \
188+ "AND line.date < %s ",
189 (partner.id, self.date_lst[0],))
190 contemp = self.cr.fetchone()
191 if contemp != None:
192@@ -298,13 +311,10 @@
193 result_tmp = result_tmp + 0.0
194
195 if self.date_lst_string:
196- self.cr.execute(
197- "SELECT sum(debit) " \
198- "FROM account_move_line " \
199- "WHERE partner_id = %s " \
200- "AND account_id IN (" + self.account_ids + ") " \
201+ self.cr.execute(self._get_debit_sql() +
202+ "AND line.partner_id = %s " \
203 " " + RECONCILE_TAG + " " \
204- "AND date IN (" + self.date_lst_string + ") " ,
205+ "AND line.date IN (" + self.date_lst_string + ") ",
206 (partner.id,))
207
208 contemp = self.cr.fetchone()
209@@ -322,13 +332,10 @@
210 else:
211 RECONCILE_TAG = "AND reconcile_id IS NULL"
212 if self.date_lst and data['form']['soldeinit'] :
213- self.cr.execute(
214- "SELECT sum(credit) " \
215- "FROM account_move_line " \
216- "WHERE partner_id=%s " \
217- "AND account_id IN (" + self.account_ids + ") " \
218- "AND reconcile_id IS NULL " \
219- "AND date < %s " ,
220+ self.cr.execute(self._get_credit_sql() +
221+ "AND line.partner_id=%s " \
222+ "AND line.reconcile_id IS NULL " \
223+ "AND line.date < %s ",
224 (partner.id,self.date_lst[0],))
225 contemp = self.cr.fetchone()
226 if contemp != None:
227@@ -337,13 +344,10 @@
228 result_tmp = result_tmp + 0.0
229
230 if self.date_lst_string:
231- self.cr.execute(
232- "SELECT sum(credit) " \
233- "FROM account_move_line " \
234- "WHERE partner_id=%s " \
235- "AND account_id IN (" + self.account_ids + ") " \
236+ self.cr.execute(self._get_credit_sql() +
237+ "AND line.partner_id=%s " \
238 " " + RECONCILE_TAG + " " \
239- "AND date IN (" + self.date_lst_string + ") " ,
240+ "AND line.date IN (" + self.date_lst_string + ") ",
241 (partner.id,))
242
243 contemp = self.cr.fetchone()
244@@ -363,13 +367,10 @@
245 else:
246 RECONCILE_TAG = "AND reconcile_id IS NULL"
247 if self.date_lst and data['form']['soldeinit'] :
248- self.cr.execute(
249- "SELECT sum(debit) " \
250- "FROM account_move_line " \
251- "WHERE partner_id IN (" + self.partner_ids + ") " \
252- "AND account_id IN (" + self.account_ids + ") " \
253- "AND reconcile_id IS NULL " \
254- "AND date < %s " ,
255+ self.cr.execute(self._get_debit_sql() +
256+ "AND line.partner_id IN (" + self.partner_ids + ") " \
257+ "AND line.reconcile_id IS NULL " \
258+ "AND line.date < %s ",
259 (self.date_lst[0],))
260 contemp = self.cr.fetchone()
261 if contemp != None:
262@@ -378,13 +379,10 @@
263 result_tmp = result_tmp + 0.0
264
265 if self.date_lst_string:
266- self.cr.execute(
267- "SELECT sum(debit) " \
268- "FROM account_move_line " \
269- "WHERE partner_id IN (" + self.partner_ids + ") " \
270- "AND account_id IN (" + self.account_ids + ") " \
271+ self.cr.execute(self._get_debit_sql() +
272+ "AND line.partner_id IN (" + self.partner_ids + ") " \
273 " " + RECONCILE_TAG + " " \
274- "AND date IN (" + self.date_lst_string + ") "
275+ "AND line.date IN (" + self.date_lst_string + ") ",
276 )
277
278 contemp = self.cr.fetchone()
279@@ -406,13 +404,10 @@
280 else:
281 RECONCILE_TAG = "AND reconcile_id IS NULL"
282 if self.date_lst and data['form']['soldeinit'] :
283- self.cr.execute(
284- "SELECT sum(credit) " \
285- "FROM account_move_line " \
286- "WHERE partner_id IN (" + self.partner_ids + ") " \
287- "AND account_id IN (" + self.account_ids + ") " \
288- "AND reconcile_id IS NULL " \
289- "AND date < %s " ,
290+ self.cr.execute(self._get_credit_sql() +
291+ "AND line.partner_id IN (" + self.partner_ids + ") " \
292+ "AND line.reconcile_id IS NULL " \
293+ "AND line.date < %s ",
294 (self.date_lst[0],))
295 contemp = self.cr.fetchone()
296 if contemp != None:
297@@ -421,13 +416,10 @@
298 result_tmp = result_tmp + 0.0
299
300 if self.date_lst_string:
301- self.cr.execute(
302- "SELECT sum(credit) " \
303- "FROM account_move_line " \
304- "WHERE partner_id IN (" + self.partner_ids + ") " \
305- "AND account_id IN (" + self.account_ids + ") " \
306+ self.cr.execute(self._get_credit_sql() +
307+ "AND line.partner_id IN (" + self.partner_ids + ") " \
308 " " + RECONCILE_TAG + " " \
309- "AND date IN (" + self.date_lst_string + ") "
310+ "AND line.date IN (" + self.date_lst_string + ") ",
311 )
312 contemp = self.cr.fetchone()
313 if contemp != None: