Merge lp:~unifield-team/unifield-addons/us-887-addons into lp:unifield-addons

Proposed by jftempo
Status: Merged
Merged at revision: 4685
Proposed branch: lp:~unifield-team/unifield-addons/us-887-addons
Merge into: lp:unifield-addons
Diff against target: 119 lines (+44/-21)
1 file modified
account/report/account_general_ledger.py (+44/-21)
To merge this branch: bzr merge lp:~unifield-team/unifield-addons/us-887-addons
Reviewer Review Type Date Requested Status
UniField Reviewer Team Pending
Review via email: mp+285317@code.launchpad.net
To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'account/report/account_general_ledger.py'
2--- account/report/account_general_ledger.py 2016-01-29 15:56:02 +0000
3+++ account/report/account_general_ledger.py 2016-02-08 10:51:55 +0000
4@@ -352,9 +352,8 @@
5 return res
6
7 if not initial_balance_mode:
8- move_state = ['draft','posted']
9- if self.target_move == 'posted':
10- move_state = ['posted', '']
11+ move_state_in = "('posted')" if self.target_move == 'posted' \
12+ else "('draft', 'posted')"
13
14 # First compute all counterpart strings for every move_id where this account appear.
15 # Currently, the counterpart info is used only in landscape mode
16@@ -405,11 +404,11 @@
17 LEFT JOIN account_account ac on (ac.id=l.account_id)
18 JOIN account_journal j on (l.journal_id=j.id)
19 WHERE %s AND m.state IN %s AND l.account_id = %%s{{reconcile}} ORDER by %s
20- """ %(self.query, tuple(move_state), sql_sort)
21+ """ %(self.query, move_state_in, sql_sort)
22 sql = sql.replace('{{reconcile}}',
23 self.unreconciled_filter and \
24 " AND reconcile_id is null and ac.reconcile ='t'" or '')
25- self.cr.execute(sql, (account.id,))
26+ self.cr.execute(sql, (account.id, ))
27 res = self.cr.dictfetchall()
28 else:
29 if self.init_balance:
30@@ -460,12 +459,41 @@
31 """
32 :return : (is_view, amount, )
33 """
34+ def compute_initial_balance():
35+ # drill child accounts entries (always fonctional ccy)
36+ aa_obj = self.pool.get('account.account')
37+ account_ids = aa_obj._get_children_and_consol(self.cr, self.uid,
38+ [account.id])
39+ if not account_ids:
40+ return 0.
41+
42+ move_state = [ 'posted', ] if self.target_move == 'posted' \
43+ else [ 'draft', 'posted', ]
44+ if field == 'balance':
45+ sum_expr = '(sum(l.debit) - sum(l.credit))'
46+ else:
47+ sum_expr = 'sum(l.{field})'.replace('{field}', field)
48+ sql = 'SELECT {sum}' \
49+ ' FROM account_move_line l' \
50+ ' JOIN account_move am ON am.id = l.move_id' \
51+ ' LEFT JOIN account_period per ON per.id = l.period_id' \
52+ ' WHERE per.number = 0' \
53+ ' AND am.state in %s AND l.account_id in %s'
54+ sql = sql.replace('{sum}', sum_expr)
55+ self.cr.execute(sql, (tuple(move_state), tuple(account_ids), ))
56+
57+ return self.cr.fetchone()[0] or 0.
58+
59 if account.type == 'view':
60 amount = getattr(account, field)
61 if not account.parent_id:
62- # deduce balance of not displayed accounts
63+ # MSF CoA root: deduce balance of not displayed accounts
64 if field in self._deduce_accounts_data:
65 amount = amount - self._deduce_accounts_data[field]
66+ if not ccy and self.init_balance:
67+ # all views: include the optional initial balance of IB period 0
68+ # entries
69+ amount += compute_initial_balance()
70 return True, self._currency_conv(amount)
71
72 return False, 0.
73@@ -528,9 +556,8 @@
74 if is_view:
75 return amount
76
77- move_state = ['draft','posted']
78- if self.target_move == 'posted':
79- move_state = ['posted','']
80+ move_state = [ 'posted', ] if self.target_move == 'posted' \
81+ else [ 'draft', 'posted', ]
82
83 initial_balance = False
84 if self.init_balance:
85@@ -555,9 +582,8 @@
86 if is_view:
87 return amount
88
89- move_state = ['draft','posted']
90- if self.target_move == 'posted':
91- move_state = ['posted','']
92+ move_state = [ 'posted', ] if self.target_move == 'posted' \
93+ else [ 'draft', 'posted', ]
94
95 initial_balance = False
96 if self.init_balance:
97@@ -587,16 +613,13 @@
98 else:
99 ccy_pattern = ""
100
101- move_state = ['draft','posted']
102- if self.target_move == 'posted':
103- move_state = ['posted','']
104+ move_state = [ 'posted', ] if self.target_move == 'posted' \
105+ else [ 'draft', 'posted', ]
106
107- initial_balance = False
108- if self.init_balance:
109- if booking:
110- initial_balance = is_sub_total and ccy or False
111- else:
112- initial_balance = not is_sub_total
113+ # add initial balance if ticked in wizard and booking subtotal
114+ # amount or any functional amount
115+ initial_balance = self.init_balance and (
116+ (booking and is_sub_total and ccy) or True) or False
117 amount = self.__sum_amount_account(account, move_state, 'balance',
118 ccy=ccy, booking=booking, initial_balance=initial_balance)
119 return self._currency_conv(amount)

Subscribers

People subscribed via source and target branches

to all changes: