LEFT | RIGHT |
1 #This file is part of Tryton. The COPYRIGHT file at the top level of | 1 #This file is part of Tryton. The COPYRIGHT file at the top level of |
2 #this repository contains the full copyright notices and license terms. | 2 #this repository contains the full copyright notices and license terms. |
3 import copy | 3 import copy |
4 import xml | 4 import xml |
5 from xml import dom | 5 from xml import dom |
6 from xml.dom import minidom | 6 from xml.dom import minidom |
7 import sys | 7 import sys |
8 import base64 | 8 import base64 |
9 try: | 9 try: |
10 import cStringIO as StringIO | 10 import cStringIO as StringIO |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
108 action_report_obj = self.pool.get('ir.action.report') | 108 action_report_obj = self.pool.get('ir.action.report') |
109 action_report_ids = action_report_obj.search([ | 109 action_report_ids = action_report_obj.search([ |
110 ('report_name', '=', self._name) | 110 ('report_name', '=', self._name) |
111 ]) | 111 ]) |
112 if not action_report_ids: | 112 if not action_report_ids: |
113 raise Exception('Error', 'Report (%s) not find!' % self._name) | 113 raise Exception('Error', 'Report (%s) not find!' % self._name) |
114 action_report = action_report_obj.browse(action_report_ids[0]) | 114 action_report = action_report_obj.browse(action_report_ids[0]) |
115 objects = None | 115 objects = None |
116 if action_report.model: | 116 if action_report.model: |
117 objects = self._get_objects(ids, action_report.model, datas) | 117 objects = self._get_objects(ids, action_report.model, datas) |
118 type, data = self.parse(action_report, objects, datas) | 118 type, data = self.parse(action_report, objects, datas, {}) |
119 return (type, base64.encodestring(data), action_report.direct_print, | 119 return (type, base64.encodestring(data), action_report.direct_print, |
120 action_report.name) | 120 action_report.name) |
121 | 121 |
122 def _get_objects(self, ids, model, datas): | 122 def _get_objects(self, ids, model, datas): |
123 model_obj = self.pool.get(model) | 123 model_obj = self.pool.get(model) |
124 return model_obj.browse(ids) | 124 return model_obj.browse(ids) |
125 | 125 |
126 def parse(self, report, objects, datas, localcontext=None): | 126 def parse(self, report, objects, datas, localcontext): |
127 localcontext = localcontext or {} | 127 ''' |
| 128 Parse the report. |
| 129 |
| 130 :param report: a BrowseRecord of the ir.action.report |
| 131 :param objects: a BrowseRecordList of the records on which parse report |
| 132 :param datas: a dictionary with datas that will be set in local context |
| 133 of the report |
| 134 :param localcontext: the context used to parse the report |
| 135 :return: a tuple with: |
| 136 report type |
| 137 report |
| 138 ''' |
128 localcontext['datas'] = datas | 139 localcontext['datas'] = datas |
129 localcontext['user'] = self.pool.get('res.user' | 140 localcontext['user'] = self.pool.get('res.user' |
130 ).browse(Transaction().user) | 141 ).browse(Transaction().user) |
131 localcontext['formatLang'] = lambda *args, **kargs: \ | 142 localcontext['formatLang'] = lambda *args, **kargs: \ |
132 self.format_lang(*args, **kargs) | 143 self.format_lang(*args, **kargs) |
133 localcontext['decodestring'] = decodestring | 144 localcontext['decodestring'] = decodestring |
134 localcontext['StringIO'] = StringIO.StringIO | 145 localcontext['StringIO'] = StringIO.StringIO |
135 localcontext['time'] = time | 146 localcontext['time'] = time |
136 localcontext['datetime'] = datetime | 147 localcontext['datetime'] = datetime |
137 localcontext['context'] = Transaction().context | 148 localcontext['context'] = Transaction().context |
(...skipping 178 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
316 date = datetime.datetime(*time.strptime(str(value), | 327 date = datetime.datetime(*time.strptime(str(value), |
317 string_pattern)[:6]) | 328 string_pattern)[:6]) |
318 else: | 329 else: |
319 date = datetime.datetime(*(value.timetuple()[:6])) | 330 date = datetime.datetime(*(value.timetuple()[:6])) |
320 return lang_obj.strftime(date, code, locale_format) | 331 return lang_obj.strftime(date, code, locale_format) |
321 if currency: | 332 if currency: |
322 return lang_obj.currency(lang, value, currency, grouping=grouping, | 333 return lang_obj.currency(lang, value, currency, grouping=grouping, |
323 symbol=symbol) | 334 symbol=symbol) |
324 return lang_obj.format(lang, '%.' + str(digits) + 'f', value, | 335 return lang_obj.format(lang, '%.' + str(digits) + 'f', value, |
325 grouping=grouping, monetary=monetary) | 336 grouping=grouping, monetary=monetary) |
LEFT | RIGHT |