[fix] problem in o2m
[odoo/odoo.git] / addons / auction / report / total.py
1 # -*- coding: utf-8 -*-
2 ##############################################################################
3 #
4 #    OpenERP, Open Source Management Solution
5 #    Copyright (C) 2004-2010 Tiny SPRL (<http://tiny.be>).
6 #
7 #    This program is free software: you can redistribute it and/or modify
8 #    it under the terms of the GNU Affero General Public License as
9 #    published by the Free Software Foundation, either version 3 of the
10 #    License, or (at your option) any later version.
11 #
12 #    This program is distributed in the hope that it will be useful,
13 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
14 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 #    GNU Affero General Public License for more details.
16 #
17 #    You should have received a copy of the GNU Affero General Public License
18 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
19 #
20 ##############################################################################
21
22 import time
23 import netsvc
24
25 from report.interface import report_rml
26
27 def toxml(val):
28     return val.replace('&', '&amp;').replace('<','&lt;').replace('>','&gt;').decode('utf-8').encode('latin1')
29
30 class report_custom(report_rml):
31     def __init__(self, name, table, tmpl, xsl):
32         report_rml.__init__(self, name, table, tmpl, xsl)
33
34     def create_xml(self, cr, uid, ids, datas, context=None):
35         lots = self.pool.get('auction.lots').read(cr, uid , ids, ['obj_price','ach_login','obj_comm','lot_est1','lot_est2','bord_vnd_id','ach_emp','auction_id'])
36         auction = self.pool.get('auction.dates').read(cr, uid, [lots[0]['auction_id'][0]])[0]
37
38         unsold = comm = emp = paid = unpaid = 0
39         est1 = est2 = adj = 0
40         paid_ids = []
41         unpaid_ids = []
42         buyer = {}
43         seller = {}
44
45         for l in lots:
46             if l['lot_est2']:
47                 est2 += l['lot_est2'] or 0.0
48
49             if l['lot_est1']:
50                 est1 += l['lot_est1'] or 0.0
51
52             if l['obj_price']:
53                 adj += l['obj_price'] or 0.0
54
55             if l['obj_comm']:
56                 comm += 1
57
58             if l['ach_emp']:
59                 emp += 1
60
61             if l['ach_pay_id']:
62                 paid_ids.append(l['id'])
63                 paid += l['obj_price']
64             else:
65                 unpaid_ids.append(l['id'])
66                 unpaid += l['obj_price']
67
68             if l['obj_price']==0:
69                 unsold+=1
70
71             buyer[l['ach_login']]=1
72             seller[l['bord_vnd_id']]=1
73
74
75         debit = adj
76         costs = self.pool.get('auction.lots').compute_seller_costs(cr, uid, ids)
77         for cost in costs:
78             debit += cost['amount']
79
80
81         xml = '''<?xml version="1.0" encoding="ISO-8859-1"?>
82 <report>
83     <date>%s</date>
84     <auction>
85         <title>%s</title>
86         <date>%s</date>
87     </auction>
88     <objects>
89         <obj_nbr>%d</obj_nbr>
90         <est_min>%.2f</est_min>
91         <est_max>%.2f</est_max>
92         <unsold>%d</unsold>
93         <obj_price>%.2f</obj_price>
94     </objects>
95     <buyer>
96         <buy_nbr>%d</buy_nbr>
97         <paid_nbr>%d</paid_nbr>
98         <comm_nbr>%d</comm_nbr>
99         <taken_nbr>%d</taken_nbr>
100         <credit>%.2f</credit>
101         <paid>%.2f</paid>
102     </buyer>
103     <seller>
104         <sell_nbr>%d</sell_nbr>
105         <debit>%.2f</debit>
106     </seller>
107 </report>''' % (time.strftime('%d/%m/%Y'), toxml(auction['name']), auction['auction1'], len(lots), est1, est2, unsold, adj, len(buyer), len(paid_ids), comm, emp, unpaid, paid, len(seller), debit)
108
109         return self.post_process_xml_data(cr, uid, xml, context)
110
111 report_custom('report.auction.total', 'auction.lots', '', 'addons/auction/report/total.xsl')
112
113
114 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
115