Analytic Budget Report
bzr revid: rde-16a1aba4833ac30683ca2406a9e9adbe78207cd7
This commit is contained in:
parent
296ea07fb6
commit
f806df9f52
|
@ -101,6 +101,16 @@
|
|||
model="account.analytic.account"
|
||||
name="account.analytic.account.year_to_date_check.report"
|
||||
keyword="client_print_multi"/>
|
||||
|
||||
<!--Budget -->
|
||||
<report id="account_analytic_budget_print"
|
||||
string="Print Budget"
|
||||
model="account.analytic.budget.post"
|
||||
name="account.analytic.budget.print"
|
||||
rml="account/project/report/account_analytic_budget_report.rml"
|
||||
auto="False"
|
||||
menu="False"/>
|
||||
|
||||
</data>
|
||||
</terp>
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
@ -0,0 +1,248 @@
|
|||
<?xml version="1.0"?>
|
||||
<document filename="test.pdf">
|
||||
<template pageSize="(612.0,792.0)" title="Test" author="Martin Simon" allowSplitting="20">
|
||||
<pageTemplate id="first">
|
||||
<frame id="first" x1="57.0" y1="57.0" width="498" height="678"/>
|
||||
</pageTemplate>
|
||||
</template>
|
||||
<stylesheet>
|
||||
<blockTableStyle id="Standard_Outline">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table2">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<blockBackground colorName="#e6e6e6" start="0,0" stop="0,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="1,0" stop="1,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="2,0" stop="2,0"/>
|
||||
<blockBackground colorName="#e6e6e6" start="0,1" stop="0,1"/>
|
||||
<blockBackground colorName="#e6e6e6" start="1,1" stop="1,1"/>
|
||||
<blockBackground colorName="#e6e6e6" start="2,1" stop="2,1"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table5">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<lineStyle kind="GRID" colorName="black"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table8">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table9">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table10">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
</blockTableStyle>
|
||||
<blockTableStyle id="Table7">
|
||||
<blockAlignment value="LEFT"/>
|
||||
<blockValign value="TOP"/>
|
||||
<lineStyle kind="GRID" colorName="black"/>
|
||||
</blockTableStyle>
|
||||
<initialize>
|
||||
<paraStyle name="all" alignment="justify"/>
|
||||
</initialize>
|
||||
<paraStyle name="P1" fontName="Times-Roman" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P2" fontName="Times-Bold" fontSize="20.0" leading="25" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P3" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P4" fontName="Times-Roman" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P5" fontName="Times-Bold" fontSize="18.0" leading="22" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P6" fontName="Times-Roman" alignment="CENTER"/>
|
||||
<paraStyle name="P7" fontName="Times-BoldItalic" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P8" fontName="Times-Roman"/>
|
||||
<paraStyle name="P9" fontName="Times-Bold"/>
|
||||
<paraStyle name="P10" fontName="Times-Bold" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P11" fontName="Times-Bold" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P12" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="LEFT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P13" fontName="Times-Roman" fontSize="10.0" leading="13" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P14" fontName="Times-Roman" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P15" fontName="Times-Bold" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P16" fontName="Times-Roman" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P17" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="P18" fontName="Times-Bold" alignment="RIGHT" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Standard" fontName="Times-Roman"/>
|
||||
<paraStyle name="Text body" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="List" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Table Contents" fontName="Times-Roman" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Table Heading" fontName="Times-Roman" alignment="CENTER" spaceBefore="0.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Caption" fontName="Times-Roman" fontSize="10.0" leading="13" spaceBefore="6.0" spaceAfter="6.0"/>
|
||||
<paraStyle name="Index" fontName="Times-Roman"/>
|
||||
</stylesheet>
|
||||
<story>
|
||||
<blockTable colWidths="145.0,189.0,164.0" repeatRows="1" style="Table2">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P1">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P2">Budget Analysis</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P3">From [[ data['form']['date1'] ]]</para>
|
||||
<para style="P3">to [[ data['form']['date2'] ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P4">[[ company.name ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P5">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P3">Currency: <font face="Times-Roman" size="11.0">[[ company.currency_id.name ]]</font></para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<para style="Standard">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<para style="P6">Printing date: [[ time.strftime('%Y-%m-%d') ]] at [[ time.strftime('%H:%M:%S') ]]</para>
|
||||
<para style="P6">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<blockTable colWidths="104.0,53.0,60.0,72.0,73.0,63.0,73.0" repeatRows="1" style="Table5">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P7">Budget item detail</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">Account Number</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">Budget</para>
|
||||
<para style="P7">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">Period Budget</para>
|
||||
<para style="P7">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">Performance</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">Spread</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P7">% performance</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<para style="P8">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
<section>
|
||||
<para style="P8">[[ repeatIn(objects, 'o') ]]</para>
|
||||
<blockTable colWidths="75.0,424.0" style="Table8">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P9">[[ o.code ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P10">[[ o.name ]]</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<blockTable colWidths="103.0,53.0,61.0,72.0,72.0,66.0,71.0" style="Table9">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P11">
|
||||
<font face="Times-Roman">[[ repeatIn(lines(o, data['form']['date1'], data['form']['date2']), 'a') ]] </font>
|
||||
<font face="Times-Roman">[[ a['name'] ]]</font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P12">[[ a['code'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P13">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P13">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P14">[[ '%.2f' % a['achievements'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P13">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P13">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<blockTable colWidths="156.0,61.0,72.0,72.0,66.0,70.0" style="Table10">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P15">Total [[ o.code ]]</para>
|
||||
<para style="Table Contents">[[ repeatIn( post_total(o, data['form']['date1'], data['form']['date2']), 'total') ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P16">[[ '%.2f' % total['prev'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P16">[[ '%.2f' % total['prev_period'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P16">[[ '%.2f' % total['achievements'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P16">[[ '%.2f' % (total['prev_period'] - total['achievements']) ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P16">[[ total['prev_period'] and ('%.2f' % (total['achievements'] / total['prev_period'] * 100.0)) or 0.0]] %</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<para style="Standard">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</section>
|
||||
<blockTable colWidths="156.0,61.0,72.0,72.0,67.0,68.0" style="Table7">
|
||||
<tr>
|
||||
<td>
|
||||
<para style="P17">Results</para>
|
||||
<para style="Table Contents">[[ repeatIn( budget_total(objects, data['form']['date1'], data['form']['date2']), 'total') ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P18">[[ '%.2f' % total['prev'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P18">[[ '%.2f' % total['prev_period'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P18">[[ '%.2f' % total['achievements'] ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P18">[[ '%.2f' % (total['prev_period'] - total['achievements']) ]]</para>
|
||||
</td>
|
||||
<td>
|
||||
<para style="P18">[[ '%.2f' % (total['achievements'] / total['prev_period'] * 100.0) ]] %</para>
|
||||
</td>
|
||||
</tr>
|
||||
</blockTable>
|
||||
<para style="Standard">
|
||||
<font color="white"> </font>
|
||||
</para>
|
||||
</story>
|
||||
</document>
|
||||
|
Loading…
Reference in New Issue