[MERGE] lp:880844
bzr revid: qdp-launchpad@openerp.com-20120224092835-8l96jxzym21rkd69
This commit is contained in:
commit
de320e0691
|
@ -37,75 +37,67 @@ class account_analytic_cost_ledger(report_sxw.rml_parse):
|
|||
'sum_credit': self._sum_credit,
|
||||
'sum_balance': self._sum_balance,
|
||||
})
|
||||
self.children = {} # a memo for the method _get_children
|
||||
|
||||
def _lines_g(self, account_id, date1, date2):
|
||||
def _get_children(self, accounts):
|
||||
""" return all children accounts of the given accounts
|
||||
:param accounts: list of browse records of 'account.analytic.account'
|
||||
:return: tuple of account ids
|
||||
"""
|
||||
analytic_obj = self.pool.get('account.analytic.account')
|
||||
res = set()
|
||||
for account in accounts:
|
||||
if account.id not in self.children:
|
||||
self.children[account.id] = analytic_obj.search(self.cr, self.uid, [('parent_id', 'child_of', [account.id])])
|
||||
res.update(self.children[account.id])
|
||||
return tuple(res)
|
||||
|
||||
def _lines_g(self, account, date1, date2):
|
||||
self.cr.execute("SELECT sum(aal.amount) AS balance, aa.code AS code, aa.name AS name, aa.id AS id \
|
||||
FROM account_account AS aa, account_analytic_line AS aal \
|
||||
WHERE (aal.account_id=%s) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \
|
||||
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (account_id, date1, date2))
|
||||
WHERE (aal.account_id IN %s) AND (aal.date>=%s) AND (aal.date<=%s) AND (aal.general_account_id=aa.id) AND aa.active \
|
||||
GROUP BY aa.code, aa.name, aa.id ORDER BY aa.code", (self._get_children([account]), date1, date2))
|
||||
res = self.cr.dictfetchall()
|
||||
|
||||
for r in res:
|
||||
if r['balance'] > 0:
|
||||
r['debit'] = r['balance']
|
||||
r['credit'] = 0.0
|
||||
elif r['balance'] < 0:
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = -r['balance']
|
||||
else:
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = 0.0
|
||||
r['debit'] = r['balance'] if r['balance'] > 0 else 0.0
|
||||
r['credit'] = -r['balance'] if r['balance'] < 0 else 0.0
|
||||
return res
|
||||
|
||||
def _lines_a(self, general_account_id, account_id, date1, date2):
|
||||
def _lines_a(self, general_account, account, date1, date2):
|
||||
self.cr.execute("SELECT aal.name AS name, aal.code AS code, aal.amount AS balance, aal.date AS date, aaj.code AS cj FROM account_analytic_line AS aal, account_analytic_journal AS aaj \
|
||||
WHERE (aal.general_account_id=%s) AND (aal.account_id=%s) AND (aal.date>=%s) AND (aal.date<=%s) \
|
||||
WHERE (aal.general_account_id=%s) AND (aal.account_id IN %s) AND (aal.date>=%s) AND (aal.date<=%s) \
|
||||
AND (aal.journal_id=aaj.id) \
|
||||
ORDER BY aal.date, aaj.code, aal.code", (general_account_id, account_id, date1, date2))
|
||||
ORDER BY aal.date, aaj.code, aal.code", (general_account['id'], self._get_children([account]), date1, date2))
|
||||
res = self.cr.dictfetchall()
|
||||
|
||||
for r in res:
|
||||
if r['balance'] > 0:
|
||||
r['debit'] = r['balance']
|
||||
r['credit'] = 0.0
|
||||
elif r['balance'] < 0:
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = -r['balance']
|
||||
else:
|
||||
r['debit'] = 0.0
|
||||
r['credit'] = 0.0
|
||||
r['debit'] = r['balance'] if r['balance'] > 0 else 0.0
|
||||
r['credit'] = -r['balance'] if r['balance'] < 0 else 0.0
|
||||
return res
|
||||
|
||||
def _account_sum_debit(self, account_id, date1, date2):
|
||||
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id=%s AND date>=%s AND date<=%s AND amount>0", (account_id, date1, date2))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
def _account_sum_debit(self, account, date1, date2):
|
||||
return self._sum_debit(self, [account], date1, date2)
|
||||
|
||||
def _account_sum_credit(self, account_id, date1, date2):
|
||||
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id=%s AND date>=%s AND date<=%s AND amount<0", (account_id, date1, date2))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
def _account_sum_credit(self, account, date1, date2):
|
||||
return self._sum_credit(self, [account], date1, date2)
|
||||
|
||||
def _account_sum_balance(self, account_id, date1, date2):
|
||||
debit = self._account_sum_debit(account_id, date1, date2)
|
||||
credit = self._account_sum_credit(account_id, date1, date2)
|
||||
def _account_sum_balance(self, account, date1, date2):
|
||||
debit = self._account_sum_debit(account, date1, date2)
|
||||
credit = self._account_sum_credit(account, date1, date2)
|
||||
return (debit-credit)
|
||||
|
||||
def _sum_debit(self, accounts, date1, date2):
|
||||
ids = map(lambda x: x.id, accounts)
|
||||
if not ids:
|
||||
return 0.0
|
||||
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0", (tuple(ids), date1, date2,))
|
||||
self.cr.execute("SELECT sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount>0",
|
||||
(self._get_children(accounts), date1, date2,))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
def _sum_credit(self, accounts, date1, date2):
|
||||
ids = map(lambda x: x.id, accounts)
|
||||
if not ids:
|
||||
return 0.0
|
||||
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0", (tuple(ids),date1, date2,))
|
||||
self.cr.execute("SELECT -sum(amount) FROM account_analytic_line WHERE account_id IN %s AND date>=%s AND date<=%s AND amount<0",
|
||||
(self._get_children(accounts), date1, date2,))
|
||||
return self.cr.fetchone()[0] or 0.0
|
||||
|
||||
def _sum_balance(self, accounts, date1, date2):
|
||||
debit = self._sum_debit(accounts, date1, date2) or 0.0
|
||||
credit = self._sum_credit(accounts, date1, date2) or 0.0
|
||||
debit = self._sum_debit(accounts, date1, date2)
|
||||
credit = self._sum_credit(accounts, date1, date2)
|
||||
return (debit-credit)
|
||||
|
||||
report_sxw.report_sxw('report.account.analytic.account.cost_ledger', 'account.analytic.account', 'addons/account/project/report/cost_ledger.rml',parser=account_analytic_cost_ledger, header="internal")
|
||||
|
|
|
@ -229,28 +229,28 @@
|
|||
</tr>
|
||||
</blockTable>
|
||||
<section>
|
||||
<para style="terp_default_2">[[ repeatIn(objects,'o') ]]</para>
|
||||
<para style="terp_default_2">[[ repeatIn(objects,'account') ]]</para>
|
||||
<blockTable colWidths="56.0,273.0,70.0,70.0,70.0" style="Table_Account_Detail">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="terp_default_Bold_9">[[ o.code ]]</para>
|
||||
<para style="terp_default_Bold_9">[[ account.code ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_default_Bold_9">[[ o.complete_name ]]</para>
|
||||
<para style="terp_default_Bold_9">[[ account.complete_name ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_Default_Bold_Right_9_U">[[ formatLang (account_sum_debit(o.id,data['form']['date1'],data['form']['date2'])) ]] </para>
|
||||
<para style="terp_Default_Bold_Right_9_U">[[ formatLang (account_sum_debit(account,data['form']['date1'],data['form']['date2'])) ]] </para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_Default_Bold_Right_9_U">[[ formatLang (account_sum_credit(o.id,data['form']['date1'],data['form']['date2'])) ]] </para>
|
||||
<para style="terp_Default_Bold_Right_9_U">[[ formatLang (account_sum_credit(account,data['form']['date1'],data['form']['date2'])) ]] </para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="terp_Default_Bold_Right_9_U">[[ formatLang (account_sum_balance(o.id,data['form']['date1'],data['form']['date2']))]] [[ company.currency_id.symbol ]]</para>
|
||||
<para style="terp_Default_Bold_Right_9_U">[[ formatLang (account_sum_balance(account,data['form']['date1'],data['form']['date2']))]] [[ company.currency_id.symbol ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<section>
|
||||
<para style="terp_default_2">[[ repeatIn(lines_g(o.id,data['form']['date1'],data['form']['date2']),'move_g') ]]</para>
|
||||
<para style="terp_default_2">[[ repeatIn(lines_g(account,data['form']['date1'],data['form']['date2']),'move_g') ]]</para>
|
||||
<blockTable colWidths="56.0,273.0,70.0,70.0,70.0" style="Table_Move_Line_Detail">
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -271,7 +271,7 @@
|
|||
</tr>
|
||||
</blockTable>
|
||||
<section>
|
||||
<para style="terp_default_2">[[ repeatIn(lines_a(move_g['id'],o.id,data['form']['date1'],data['form']['date2']),'move_a') ]]</para>
|
||||
<para style="terp_default_2">[[ repeatIn(lines_a(move_g,account,data['form']['date1'],data['form']['date2']),'move_a') ]]</para>
|
||||
<blockTable colWidths="56.0,56.0,217.0,70.0,70.0,70.0" style="Table_Move_Line_Content">
|
||||
<tr>
|
||||
<td>
|
||||
|
@ -302,4 +302,4 @@
|
|||
</section>
|
||||
</pto>
|
||||
</story>
|
||||
</document>
|
||||
</document>
|
||||
|
|
Loading…
Reference in New Issue