~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

Viewing changes to hr_timesheet_invoice/report/cost_ledger.py

  • Committer: pinky
  • Date: 2006-12-07 13:41:40 UTC
  • Revision ID: pinky-dedd7f8a42bd4557112a0513082691b8590ad6cc
New trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
 
4
#                    Fabien Pinckaers <fp@tiny.Be>
 
5
#
 
6
# WARNING: This program as such is intended to be used by professional
 
7
# programmers who take the whole responsability of assessing all potential
 
8
# consequences resulting FROM its eventual inadequacies AND bugs
 
9
# End users who are looking for a ready-to-use solution with commercial
 
10
# garantees AND support are strongly adviced to contract a Free Software
 
11
# Service Company
 
12
#
 
13
# This program is Free Software; you can redistribute it AND/or
 
14
# modify it under the terms of the GNU General Public License
 
15
# as published by the Free Software Foundation; either version 2
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This program is distributed in the hope that it will be useful,
 
19
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
# GNU General Public License for more details.
 
22
#
 
23
# You should have received a copy of the GNU General Public License
 
24
# along with this program; if not, write to the Free Software
 
25
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
26
#
 
27
##############################################################################
 
28
 
 
29
import pooler
 
30
import time
 
31
from report import report_sxw
 
32
 
 
33
SUMS  = ('credit','debit','balance','quantity','revenue')
 
34
 
 
35
class account_analytic_cost_ledger(report_sxw.rml_parse):
 
36
        def __init__(self, cr, uid, name, context):
 
37
                super(account_analytic_cost_ledger, self).__init__(cr, uid, name, context)
 
38
                self.localcontext.update( {
 
39
                        'time': time,
 
40
                        'lines': self._lines_all,
 
41
                        'totals': dict.fromkeys(SUMS, 0.0)
 
42
                })
 
43
 
 
44
        def _lines_all(self, accounts, date1, date2):
 
45
                result = []
 
46
                for account in accounts:
 
47
                        accs =  self._lines(account.id, date1, date2).values()
 
48
                        result.append( {
 
49
                                'code': account.code,
 
50
                                'name': account.complete_name,
 
51
                                'accounts': accs,
 
52
                                'qty_max': account.quantity_max or '/',
 
53
                                'debit_max': account.amount_max or '/'
 
54
                        })
 
55
                        for word in SUMS:
 
56
                                s=reduce(lambda x,y:x+y[word], accs, 0.0)
 
57
                                result[-1][word] = s
 
58
                                self.localcontext['totals'][word] += s
 
59
                return result
 
60
 
 
61
        def _lines(self, account_id, date1, date2):
 
62
                lineobj = self.pool.get('account.analytic.line')
 
63
                line_ids = lineobj.search(self.cr, self.uid, [('account_id','=',account_id), ('date','>=',date1), ('date','<=',date2)])
 
64
                result = {}
 
65
                for line in lineobj.browse(self.cr, self.uid, line_ids):
 
66
                        if line.general_account_id.id not in result:
 
67
                                result[line.general_account_id.id] = {
 
68
                                        'code': line.general_account_id.code,
 
69
                                        'name': line.general_account_id.name,
 
70
                                        'lines': []
 
71
                                }
 
72
                                result[line.general_account_id.id].update(dict.fromkeys(SUMS, 0.0))
 
73
 
 
74
                        revenue = 0.0
 
75
                        if line.amount<0 and line.product_id and line.product_uom_id and line.account_id.pricelist_id:
 
76
                                c = {
 
77
                                        'uom': line.product_uom_id.id
 
78
                                }
 
79
                                id = line.account_id.pricelist_id.id
 
80
                                price = self.pool.get('product.pricelist').price_get(self.cr, self.uid, [id],
 
81
                                        line.product_id.id, line.unit_amount, c)[id]
 
82
                                revenue = round(price * line.unit_amount, 2)
 
83
                        result[line.general_account_id.id]['lines'].append( {
 
84
                                'date':line.date,
 
85
                                'cj':line.journal_id.code,
 
86
                                'name': line.name,
 
87
                                'quantity': line.unit_amount,
 
88
                                'credit': line.amount <0 and -line.amount or 0,
 
89
                                'debit': line.amount >0 and line.amount or 0,
 
90
                                'balance': line.amount,
 
91
                                'revenue': revenue
 
92
                        } )
 
93
                        for word in SUMS:
 
94
                                result[line.general_account_id.id][word] += (result[line.general_account_id.id]['lines'][-1][word] or 0.0)
 
95
                return result
 
96
 
 
97
report_sxw.report_sxw('report.account.analytic.account.cost_ledger', 'account.analytic.account', 'addons/hr_timesheet_invoice/report/cost_ledger.rml',parser=account_analytic_cost_ledger)
 
98