diff --git a/addons/account/project/project_report.xml b/addons/account/project/project_report.xml index a0da52e7b8f..c8438feba15 100644 --- a/addons/account/project/project_report.xml +++ b/addons/account/project/project_report.xml @@ -101,6 +101,16 @@ model="account.analytic.account" name="account.analytic.account.year_to_date_check.report" keyword="client_print_multi"/> + + + + diff --git a/addons/account/project/report/__init__.py b/addons/account/project/report/__init__.py index 67fd34d1bf4..69ff53df539 100644 --- a/addons/account/project/report/__init__.py +++ b/addons/account/project/report/__init__.py @@ -32,4 +32,4 @@ import inverted_analytic_balance import cost_ledger import quantity_cost_ledger import year_to_date_check - +import account_analytic_budget_report diff --git a/addons/account/project/report/account_analytic_budget_report.py b/addons/account/project/report/account_analytic_budget_report.py new file mode 100644 index 00000000000..3ed3c8c270c --- /dev/null +++ b/addons/account/project/report/account_analytic_budget_report.py @@ -0,0 +1,72 @@ +############################################################################## +# +# Copyright (c) 2005-2006 TINY SPRL. (http://tiny.be) All Rights Reserved. +# +# WARNING: This program as such is intended to be used by professional +# programmers who take the whole responsability of assessing all potential +# consequences resulting from its eventual inadequacies and bugs +# End users who are looking for a ready-to-use solution with commercial +# garantees and support are strongly adviced to contract a Free Software +# Service Company +# +# This program is Free Software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License +# as published by the Free Software Foundation; either version 2 +# of the License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +# +############################################################################## + +import time +from report import report_sxw +import datetime + +class account_analytic_budget_report(report_sxw.rml_parse): + def __init__(self, cr, uid, name, context): + super(account_analytic_budget_report, self).__init__(cr, uid, name, context) + self.localcontext.update( { + 'lines': self.lines, + 'budget_total': self.budget_total, + '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'))) + def interval(d1str, d2str): + return (str2date(d2str) - str2date(d1str) + datetime.timedelta(days=1)).days + prev = reduce(lambda x,d: x + d.amount, post_obj.dotation_ids, 0.0) + period_days = interval(date1, date2) + 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) + achievements = reduce(lambda x,l: x+l['achievements'], self.lines(post_obj, date1, date2), 0.0) + return [{'prev': prev, 'prev_period': prev * period_days / total_days, 'achievements': achievements}] + + def budget_total(self, post_objs, date1, date2): + res = {'prev': 0.0, 'prev_period': 0.0, 'achievements': 0.0} + for post_obj in post_objs: + r = self.post_total(post_obj, date1, date2)[0] + for k in r: + res[k] += r[k] + return [res] + + 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) + diff --git a/addons/account/project/report/account_analytic_budget_report.rml b/addons/account/project/report/account_analytic_budget_report.rml new file mode 100644 index 00000000000..520fed1df2f --- /dev/null +++ b/addons/account/project/report/account_analytic_budget_report.rml @@ -0,0 +1,248 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Budget Analysis + + + From [[ data['form']['date1'] ]] + to [[ data['form']['date2'] ]] + + + + + [[ company.name ]] + + + + + + + + Currency: [[ company.currency_id.name ]] + + + + + + + Printing date: [[ time.strftime('%Y-%m-%d') ]] at [[ time.strftime('%H:%M:%S') ]] + + + + + + + Budget item detail + + + Account Number + + + Budget + + + + + + Period Budget + + + + + + Performance + + + Spread + + + % performance + + + + + + +
+ [[ repeatIn(objects, 'o') ]] + + + + [[ o.code ]] + + + [[ o.name ]] + + + + + + + + [[ repeatIn(lines(o, data['form']['date1'], data['form']['date2']), 'a') ]] + [[ a['name'] ]] + + + + [[ a['code'] ]] + + + + + + + + + + + + + [[ '%.2f' % a['achievements'] ]] + + + + + + + + + + + + + + + + + Total [[ o.code ]] + [[ repeatIn( post_total(o, data['form']['date1'], data['form']['date2']), 'total') ]] + + + [[ '%.2f' % total['prev'] ]] + + + [[ '%.2f' % total['prev_period'] ]] + + + [[ '%.2f' % total['achievements'] ]] + + + [[ '%.2f' % (total['prev_period'] - total['achievements']) ]] + + + [[ total['prev_period'] and ('%.2f' % (total['achievements'] / total['prev_period'] * 100.0)) or 0.0]] % + + + + + + +
+ + + + Results + [[ repeatIn( budget_total(objects, data['form']['date1'], data['form']['date2']), 'total') ]] + + + [[ '%.2f' % total['prev'] ]] + + + [[ '%.2f' % total['prev_period'] ]] + + + [[ '%.2f' % total['achievements'] ]] + + + [[ '%.2f' % (total['prev_period'] - total['achievements']) ]] + + + [[ '%.2f' % (total['achievements'] / total['prev_period'] * 100.0) ]] % + + + + + + +
+
+