From 987f13f04fe4648a7215ce22c444aefe9b216389 Mon Sep 17 00:00:00 2001 From: rde <> Date: Mon, 15 Jan 2007 10:56:28 +0000 Subject: [PATCH] Budgets for analytic accounts. First implementation bzr revid: rde-d57541435c36d85a69260466afe86dbc05a108d7 --- addons/account/project/project_report.xml | 8 ------ addons/account/project/project_wizard.xml | 6 +++++ .../report/account_analytic_budget_report.py | 27 ++++++------------- .../report/account_analytic_budget_report.rml | 4 +-- addons/account/report/budget_report.py | 1 + 5 files changed, 17 insertions(+), 29 deletions(-) diff --git a/addons/account/project/project_report.xml b/addons/account/project/project_report.xml index 8ba1ca243d3..66b21c87ad1 100644 --- a/addons/account/project/project_report.xml +++ b/addons/account/project/project_report.xml @@ -103,14 +103,6 @@ keyword="client_print_multi"/> - - - + diff --git a/addons/account/project/report/account_analytic_budget_report.py b/addons/account/project/report/account_analytic_budget_report.py index b95fca8cb64..670feb0ec3e 100644 --- a/addons/account/project/report/account_analytic_budget_report.py +++ b/addons/account/project/report/account_analytic_budget_report.py @@ -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): @@ -38,7 +39,7 @@ class account_analytic_budget_report(report_sxw.rml_parse): 'post_total': self.post_total, 'time': time, }) - + def post_total(self, post_obj, date1, date2): def str2date(date_str): 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: 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}) + res.append({'name': a.name, 'code': a.code, 'achievements': compute_achievements(a)}) -# 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) diff --git a/addons/account/project/report/account_analytic_budget_report.rml b/addons/account/project/report/account_analytic_budget_report.rml index 520fed1df2f..a3a47ce869e 100644 --- a/addons/account/project/report/account_analytic_budget_report.rml +++ b/addons/account/project/report/account_analytic_budget_report.rml @@ -80,7 +80,7 @@ - Budget Analysis + Analytic Budget Analysis From [[ data['form']['date1'] ]] @@ -158,7 +158,7 @@ - [[ repeatIn(lines(o, data['form']['date1'], data['form']['date2']), 'a') ]] + -- [[ repeatIn(lines(o, data['form']['date1'], data['form']['date2']), 'a') ]] -- [[ a['name'] ]] diff --git a/addons/account/report/budget_report.py b/addons/account/report/budget_report.py index e4d40d08306..4f0ef987692 100644 --- a/addons/account/report/budget_report.py +++ b/addons/account/report/budget_report.py @@ -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):