1
##############################################################################
3
# Copyright (c) 2006 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
##############################################################################
29
from report import report_sxw
32
class account_analytic_profit(report_sxw.rml_parse):
33
def __init__(self, cr, uid, name, context):
34
super(account_analytic_profit, self).__init__(cr, uid, name, context)
35
self.localcontext.update({
37
'user_ids': self._user_ids,
38
'journal_ids': self._journal_ids,
41
def _user_ids(self, lines):
42
user_obj=pooler.get_pool(self.cr.dbname).get('res.users')
43
ids=list(set([b.user_id.id for b in lines]))
44
res=user_obj.browse(self.cr, self.uid, ids)
47
def _journal_ids(self, form, user_id):
48
line_obj=pooler.get_pool(self.cr.dbname).get('account.analytic.line')
49
journal_obj=pooler.get_pool(self.cr.dbname).get('account.analytic.journal')
50
line_ids=line_obj.search(self.cr, self.uid, [
51
('date', '>=', form['date_from']),
52
('date', '<=', form['date_to']),
53
('journal_id', 'in', form['journal_ids'][0][2]),
54
('user_id', '=', user_id),
56
ids=list(set([b.journal_id.id for b in line_obj.browse(self.cr, self.uid, line_ids)]))
57
res=journal_obj.browse(self.cr, self.uid, ids)
60
def _line(self, form, journal_ids, user_ids):
61
pool=pooler.get_pool(self.cr.dbname)
62
line_obj=pool.get('account.analytic.line')
63
product_obj=pool.get('product.product')
64
price_obj=pool.get('product.pricelist')
65
ids=line_obj.search(self.cr, self.uid, [
66
('date', '>=', form['date_from']),
67
('date', '<=', form['date_to']),
68
('journal_id', 'in', journal_ids),
69
('user_id', 'in', user_ids),
72
for line in line_obj.browse(self.cr, self.uid, ids):
75
name=line.to_invoice.name
76
discount=line.to_invoice.factor
78
if line.account_id.pricelist_id:
86
if line.account_id.pricelist_id:
87
pl=line.account_id.pricelist_id.id
88
price=price_obj.price_get(self.cr, self.uid, [pl], line.product_id.id, line.unit_amount or 1.0, line.account_id.partner_id.id)[pl]
92
res[id]={'name': name, 'amount': 0, 'cost':0, 'unit_amount':0,}
93
res[id]['amount']+=round(price * line.unit_amount * (1-(discount or 0.0)/100.0), 2)
94
res[id]['cost']+=line.amount
95
res[id]['unit_amount']+=line.unit_amount
97
res[id]['profit']=res[id]['amount']+res[id]['cost']
98
res[id]['eff']=abs(round(res[id]['amount'] / res[id]['cost'] * 100, 2))
101
def _lines(self, form):
102
line_obj=pooler.get_pool(self.cr.dbname).get('account.analytic.line')
103
ids=line_obj.search(self.cr, self.uid, [
104
('date', '>=', form['date_from']),
105
('date', '<=', form['date_to']),
106
('journal_id', 'in', form['journal_ids'][0][2]),
107
('user_id', 'in', form['employee_ids'][0][2]),
109
res=line_obj.browse(self.cr, self.uid, ids)
112
report_sxw.report_sxw('report.account.analytic.profit', 'account.analytic.line', 'addons/hr_timesheet_invoice/report/account_analytic_profit.rml', parser=account_analytic_profit)