modifs
[odoo/odoo.git] /
1 # -*- encoding: utf-8 -*-
2 ##############################################################################
3 #
4 # Copyright (c) 2004-2008 TINY SPRL. (http://tiny.be) All Rights Reserved.
5 #
6 # $Id$
7 #
8 # WARNING: This program as such is intended to be used by professional
9 # programmers who take the whole responsability of assessing all potential
10 # consequences resulting from its eventual inadequacies and bugs
11 # End users who are looking for a ready-to-use solution with commercial
12 # garantees and support are strongly adviced to contract a Free Software
13 # Service Company
14 #
15 # This program is Free Software; you can redistribute it and/or
16 # modify it under the terms of the GNU General Public License
17 # as published by the Free Software Foundation; either version 2
18 # of the License, or (at your option) any later version.
19 #
20 # This program is distributed in the hope that it will be useful,
21 # but WITHOUT ANY WARRANTY; without even the implied warranty of
22 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23 # GNU General Public License for more details.
24 #
25 # You should have received a copy of the GNU General Public License
26 # along with this program; if not, write to the Free Software
27 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
28 #
29 ##############################################################################
30
31 from report.interface import report_rml
32 from report.interface import toxml
33 import pooler
34
35
36 class report_custom(report_rml):
37
38     def create_xml(self, cr, uid, ids, datas, context=None):
39         pool = pooler.get_pool(cr.dbname)
40         product_obj = pool.get('product.product')
41         location_obj = pool.get('stock.location')
42
43         products = product_obj.read(cr, uid, ids, ['name','uom_id'])
44         cr.execute('SELECT id FROM stock_location WHERE usage = %s',
45                 ('internal',))
46         location_ids = [ x[0] for x in cr.fetchall() ]
47         location_ids.sort()
48         locs_info = {}
49         locs_name = dict(location_obj.name_get(cr, uid, location_ids))
50         for location_id in locs_name.keys():
51             locs_info[location_id] = location_obj._product_get(cr, uid,
52                     location_id, ids)
53
54         xml = '<?xml version="1.0" ?><report>'
55         for p in products:
56             xml += '<product>' \
57                 '<name>' + toxml(p['name']) + '</name>' \
58                 '<unit>' + toxml(p['uom_id'][1]) + '</unit>' \
59                 '<locations>'
60             for loc_id in locs_info.keys():
61                 if locs_info[loc_id].get(p['id']):
62                     xml += '<location>'
63                     xml += '<loc_name>' + toxml(locs_name[loc_id]) \
64                             + '</loc_name>'
65                     xml += '<loc_qty>' + toxml(locs_info[loc_id].get(p['id'])) \
66                             + '</loc_qty>'
67                     xml += '</location>'
68             xml += '</locations>' \
69                 '</product>'
70         xml += '</report>'
71         return self.post_process_xml_data(cr, uid, xml, context)
72
73 report_custom('report.stock.product.location', 'stock.location', '',
74         'addons/stock/report/product_location.xsl')
75
76
77 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
78