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"/>
|
keyword="client_print_multi"/>
|
||||||
|
|
||||||
<!--Budget -->
|
<!--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
|
<report
|
||||||
id="account_analytic_budget_print"
|
id="account_analytic_budget_print"
|
||||||
string="Print Budget"
|
string="Print Budget"
|
||||||
|
|
|
@ -7,5 +7,11 @@
|
||||||
name="account.analytic.budget.spread"
|
name="account.analytic.budget.spread"
|
||||||
menu="False"
|
menu="False"
|
||||||
id="wizard_account_analytic_budget_spread"/>
|
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>
|
</data>
|
||||||
</terp>
|
</terp>
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
import time
|
import time
|
||||||
from report import report_sxw
|
from report import report_sxw
|
||||||
import datetime
|
import datetime
|
||||||
|
import operator
|
||||||
|
|
||||||
class account_analytic_budget_report(report_sxw.rml_parse):
|
class account_analytic_budget_report(report_sxw.rml_parse):
|
||||||
def __init__(self, cr, uid, name, context):
|
def __init__(self, cr, uid, name, context):
|
||||||
|
@ -38,7 +39,7 @@ class account_analytic_budget_report(report_sxw.rml_parse):
|
||||||
'post_total': self.post_total,
|
'post_total': self.post_total,
|
||||||
'time': time,
|
'time': time,
|
||||||
})
|
})
|
||||||
|
|
||||||
def post_total(self, post_obj, date1, date2):
|
def post_total(self, post_obj, date1, date2):
|
||||||
def str2date(date_str):
|
def str2date(date_str):
|
||||||
return datetime.date.fromtimestamp(time.mktime(time.strptime(date_str, '%Y-%m-%d')))
|
return datetime.date.fromtimestamp(time.mktime(time.strptime(date_str, '%Y-%m-%d')))
|
||||||
|
@ -49,9 +50,7 @@ class account_analytic_budget_report(report_sxw.rml_parse):
|
||||||
for d in post_obj.dotation_ids:
|
for d in post_obj.dotation_ids:
|
||||||
i = interval(d.period_id.date_start, d.period_id.date_stop)
|
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)
|
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)
|
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}]
|
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]
|
res[k] += r[k]
|
||||||
return [res]
|
return [res]
|
||||||
|
|
||||||
#NEW recursive method
|
|
||||||
def lines(self, post_obj, date1, date2):
|
def lines(self, post_obj, date1, date2):
|
||||||
def compute_achievements(a):
|
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))
|
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)
|
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
|
return node_achievements + childs_achievements
|
||||||
|
|
||||||
res = []
|
res = []
|
||||||
|
|
||||||
for a in post_obj.account_ids:
|
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)})
|
||||||
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
|
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)
|
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>
|
</para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P2">Budget Analysis</para>
|
<para style="P2">Analytic Budget Analysis</para>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
<para style="P3">From [[ data['form']['date1'] ]]</para>
|
<para style="P3">From [[ data['form']['date1'] ]]</para>
|
||||||
|
@ -158,7 +158,7 @@
|
||||||
<tr>
|
<tr>
|
||||||
<td>
|
<td>
|
||||||
<para style="P11">
|
<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>
|
<font face="Times-Roman">[[ a['name'] ]]</font>
|
||||||
</para>
|
</para>
|
||||||
</td>
|
</td>
|
||||||
|
|
|
@ -28,6 +28,7 @@
|
||||||
import time
|
import time
|
||||||
from report import report_sxw
|
from report import report_sxw
|
||||||
import datetime
|
import datetime
|
||||||
|
import operator
|
||||||
|
|
||||||
class budget_report(report_sxw.rml_parse):
|
class budget_report(report_sxw.rml_parse):
|
||||||
def __init__(self, cr, uid, name, context):
|
def __init__(self, cr, uid, name, context):
|
||||||
|
|
Loading…
Reference in New Issue