~technofluid-team/openobject-addons/technofluid_multiple_installations

« back to all changes in this revision

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