~anton-chepurov/aeroo/7.0

« back to all changes in this revision

Viewing changes to report_aeroo_printscreen/parser.py

  • Committer: root
  • Date: 2013-05-16 15:53:25 UTC
  • Revision ID: root@erp.kndati.lv-20130516155325-x7v319i9a6avw58g
1.2.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
##############################################################################
 
2
#
 
3
# Copyright (c) 2008-2011 Alistek Ltd (http://www.alistek.com) All Rights Reserved.
 
4
#                    General contacts <info@alistek.com>
 
5
#
 
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
 
11
# Service Company
 
12
#
 
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 3
 
16
# of the License, or (at your option) any later version.
 
17
#
 
18
# This module is GPLv3 or newer and incompatible
 
19
# with OpenERP SA "AGPL + Private Use License"!
 
20
#
 
21
# This program is distributed in the hope that it will be useful,
 
22
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
23
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
24
# GNU General Public License for more details.
 
25
#
 
26
# You should have received a copy of the GNU General Public License
 
27
# along with this program; if not, write to the Free Software
 
28
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
29
#
 
30
##############################################################################
 
31
 
 
32
from report import report_sxw
 
33
from lxml import etree
 
34
 
 
35
class Parser(report_sxw.rml_parse):
 
36
    def __init__(self, cr, uid, name, context):
 
37
        super(Parser, self).__init__(cr, uid, name, context)
 
38
        model = self.pool.get(context['model'])
 
39
        ids = context['ids']
 
40
 
 
41
        model_id = self.pool.get('ir.model').search(cr, uid, [('model','=',model._name)])
 
42
        if model_id:
 
43
            model_desc = self.pool.get('ir.model').browse(cr, uid, model_id[0], context).name
 
44
        else:
 
45
            model_desc = model._description
 
46
 
 
47
        result = model.fields_view_get(cr, uid, view_type='tree', context=context)
 
48
        fields_type = dict(map(lambda name: (name, result['fields'][name]['type']), result['fields']))
 
49
        fields_order = self._parse_string(result['arch'])
 
50
        rows = model.read(cr, uid, ids, context=context)
 
51
 
 
52
        self.localcontext.update({
 
53
            'screen_fields': fields_order,
 
54
            'screen_fields_type': fields_type,
 
55
            'screen_rows': rows,
 
56
            'screen_model': context['model'],
 
57
            'screen_title': model_desc,
 
58
          
 
59
        })
 
60
 
 
61
    def _parse_node(self, root_node):
 
62
        result = []
 
63
        for node in root_node:
 
64
            if node.tag == 'field':
 
65
                result.append(node.get('name'))
 
66
            else:
 
67
                result.extend(self._parse_node(node))
 
68
        return result
 
69
 
 
70
    def _parse_string(self, view):
 
71
        try:
 
72
            dom = etree.XML(view.encode('utf-8'))
 
73
        except:
 
74
            dom = etree.XML(view)   
 
75
        return self._parse_node(dom)
 
76