1
##############################################################################
3
# Copyright (c) 2004 TINY SPRL. (http://tiny.be) All Rights Reserved.
4
# Fabien Pinckaers <fp@tiny.Be>
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
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.
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.
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.
27
##############################################################################
31
from report import report_sxw
33
SUMS = ('credit','debit','balance','quantity','revenue')
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( {
40
'lines': self._lines_all,
41
'totals': dict.fromkeys(SUMS, 0.0)
44
def _lines_all(self, accounts, date1, date2):
46
for account in accounts:
47
accs = self._lines(account.id, date1, date2).values()
50
'name': account.complete_name,
52
'qty_max': account.quantity_max or '/',
53
'debit_max': account.amount_max or '/'
56
s=reduce(lambda x,y:x+y[word], accs, 0.0)
58
self.localcontext['totals'][word] += s
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)])
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,
72
result[line.general_account_id.id].update(dict.fromkeys(SUMS, 0.0))
75
if line.amount<0 and line.product_id and line.product_uom_id and line.account_id.pricelist_id:
77
'uom': line.product_uom_id.id
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( {
85
'cj':line.journal_id.code,
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,
94
result[line.general_account_id.id][word] += (result[line.general_account_id.id]['lines'][-1][word] or 0.0)
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)