Budgets for analytic accounts. First implementation
bzr revid: rde-d57541435c36d85a69260466afe86dbc05a108d7
This commit is contained in:
parent
cd7e51a4cd
commit
987f13f04f
|
@ -103,14 +103,6 @@
|
|||
keyword="client_print_multi"/>
|
||||
|
||||
<!--Budget -->
|
||||
<wizard
|
||||
string="Budget"
|
||||
model="account.analytic.budget.post"
|
||||
name="account.analytic.budget.report"
|
||||
keyword="client_print_multi"
|
||||
id="wizard_account_analytic_budget_report"/>
|
||||
|
||||
|
||||
<report
|
||||
id="account_analytic_budget_print"
|
||||
string="Print Budget"
|
||||
|
|
|
@ -7,5 +7,11 @@
|
|||
name="account.analytic.budget.spread"
|
||||
menu="False"
|
||||
id="wizard_account_analytic_budget_spread"/>
|
||||
<wizard
|
||||
string="Budget"
|
||||
model="account.analytic.budget.post"
|
||||
name="account.analytic.budget.report"
|
||||
keyword="client_print_multi"
|
||||
id="wizard_account_analytic_budget_report"/>
|
||||
</data>
|
||||
</terp>
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
import time
|
||||
from report import report_sxw
|
||||
import datetime
|
||||
import operator
|
||||
|
||||
class account_analytic_budget_report(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
|
@ -49,9 +50,7 @@ class account_analytic_budget_report(report_sxw.rml_parse):
|
|||
for d in post_obj.dotation_ids:
|
||||
i = interval(d.period_id.date_start, d.period_id.date_stop)
|
||||
total_days = reduce(lambda x,d: x+interval(d.period_id.date_start, d.period_id.date_stop), post_obj.dotation_ids, 0)
|
||||
#OLD <==>
|
||||
achievements = reduce(lambda x,l: x+l['achievements'], self.lines(post_obj, date1, date2), 0.0)
|
||||
##node_achievements = reduce(operator.add, [
|
||||
|
||||
return [{'prev': prev, 'prev_period': prev * period_days / total_days, 'achievements': achievements}]
|
||||
|
||||
|
@ -63,30 +62,20 @@ class account_analytic_budget_report(report_sxw.rml_parse):
|
|||
res[k] += r[k]
|
||||
return [res]
|
||||
|
||||
#NEW recursive method
|
||||
def lines(self, post_obj, date1, date2):
|
||||
def compute_achievements(a):
|
||||
self.cr.execute("SELECT COALESCE(SUM(debit-credit), 0) FROM account_move_line WHERE account_id=%d AND date>=%s AND date<=%s and state<>'draft'", (a.id, date1, date2))
|
||||
|
||||
node_achievements = float(self.cr.fetchone()[0]) * (post_obj.sens=='produit' and -1 or 1)
|
||||
childs_achievements = reduce(operator.add, [compute_achievements(c) for c in a.child_ids])
|
||||
childs_achievements = reduce(operator.add, [compute_achievements(c) for c in a.child_ids], 0)
|
||||
return node_achievements + childs_achievements
|
||||
|
||||
res = []
|
||||
|
||||
for a in post_obj.account_ids:
|
||||
achievements = account_achievements(a, date1, date2)
|
||||
res.append({'name': a.name, 'code': a.code, 'achievements': compute_achievements(a)})
|
||||
|
||||
return res
|
||||
|
||||
# OLD, nonrecursive method !
|
||||
# def lines(self, post_obj, date1, date2):
|
||||
# res = []
|
||||
# for a in post_obj.account_ids:
|
||||
# self.cr.execute("SELECT COALESCE(SUM(debit-credit), 0) FROM account_move_line WHERE account_id=%d AND date>=%s AND date<=%s and state<>'draft'", (a.id, date1, date2))
|
||||
# achievements = float(self.cr.fetchone()[0]) * (post_obj.sens=='produit' and -1 or 1)
|
||||
# res.append({'name': a.name, 'code': a.code, 'achievements': achievements})
|
||||
|
||||
# return res
|
||||
|
||||
report_sxw.report_sxw('report.account.analytic.budget.print', 'account.analytic.budget.post', 'addons/account/project/report/account_analytic_budget_report.rml',parser=account_analytic_budget_report)
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@
|
|||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">Budget Analysis</para>
|
||||
<para style="P2">Analytic Budget Analysis</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P3">From [[ data['form']['date1'] ]]</para>
|
||||
|
@ -158,7 +158,7 @@
|
|||
<tr>
|
||||
<td>
|
||||
<para style="P11">
|
||||
<font face="Times-Roman">[[ repeatIn(lines(o, data['form']['date1'], data['form']['date2']), 'a') ]] </font>
|
||||
<font face="Times-Roman">-- [[ repeatIn(lines(o, data['form']['date1'], data['form']['date2']), 'a') ]] -- </font>
|
||||
<font face="Times-Roman">[[ a['name'] ]]</font>
|
||||
</para>
|
||||
</td>
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
import time
|
||||
from report import report_sxw
|
||||
import datetime
|
||||
import operator
|
||||
|
||||
class budget_report(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
|
|
Loading…
Reference in New Issue