Merge lp:~mechiscogo/aeroo/mx into lp:aeroo/trunk

Proposed by Prabhu
Status: Needs review
Proposed branch: lp:~mechiscogo/aeroo/mx
Merge into: lp:aeroo/trunk
Diff against target: 3132 lines (+3039/-0)
17 files modified
ExtraFunctions.py (+367/-0)
__init__.py (+31/-0)
__openerp__.py (+37/-0)
barcode/EANBarCode.py (+148/-0)
barcode/__init__.py (+30/-0)
barcode/barcode.py (+59/-0)
barcode/code128.py (+184/-0)
barcode/code39.py (+153/-0)
currency_to_text.py (+490/-0)
data/report_aeroo_data.xml (+25/-0)
domain_parser.py (+45/-0)
report_aeroo.py (+636/-0)
report_view.xml (+224/-0)
report_xml.py (+365/-0)
wizard/__init__.py (+30/-0)
wizard/report_actions.py (+118/-0)
wizard/report_actions_remove.py (+97/-0)
To merge this branch: bzr merge lp:~mechiscogo/aeroo/mx
Reviewer Review Type Date Requested Status
Alistek developers - http://www.alistek.com Pending
Review via email: mp+113566@code.launchpad.net
To post a comment you must log in.

Unmerged revisions

2. By mechiscogo <mechiscogo@openerp>

Adds MXN (Mexican peso) and Spanish translations to currency_to_text. All the translations for Spanish have the Mexican format: <amount in words> <cents>/100 <currency>

1. By mechiscogo <mechiscogo@openerp>

Agrega moneda MXN y traducciones al español en currency_to_text. Todas las traducciones llevan formato para México <importe con letra> <centavos>/100 <moneda>

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== added file 'ExtraFunctions.py'
2--- ExtraFunctions.py 1970-01-01 00:00:00 +0000
3+++ ExtraFunctions.py 2012-07-05 12:25:24 +0000
4@@ -0,0 +1,367 @@
5+##############################################################################
6+#
7+# Copyright (c) 2008-2009 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
8+# General contacts <info@kndati.lv>
9+#
10+# WARNING: This program as such is intended to be used by professional
11+# programmers who take the whole responsability of assessing all potential
12+# consequences resulting from its eventual inadequacies and bugs
13+# End users who are looking for a ready-to-use solution with commercial
14+# garantees and support are strongly adviced to contract a Free Software
15+# Service Company
16+#
17+# This program is Free Software; you can redistribute it and/or
18+# modify it under the terms of the GNU General Public License
19+# as published by the Free Software Foundation; either version 2
20+# of the License, or (at your option) any later version.
21+#
22+# This program is distributed in the hope that it will be useful,
23+# but WITHOUT ANY WARRANTY; without even the implied warranty of
24+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25+# GNU General Public License for more details.
26+#
27+# You should have received a copy of the GNU General Public License
28+# along with this program; if not, write to the Free Software
29+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
30+#
31+##############################################################################
32+
33+from barcode import barcode
34+from tools import translate
35+from domain_parser import domain2statement
36+from currency_to_text import currency_to_text
37+import base64
38+import StringIO
39+from PIL import Image
40+import pooler
41+import time
42+import osv
43+from report import report_sxw
44+from tools.translate import _
45+import netsvc
46+
47+class ExtraFunctions(object):
48+ """ This class contains some extra functions which
49+ can be called from the report's template.
50+ """
51+ def __init__(self, cr, uid, report_id, context):
52+ self.cr = cr
53+ self.uid = uid
54+ self.pool = pooler.get_pool(self.cr.dbname)
55+ self.report_id = report_id
56+ self.context = context
57+ self.functions = {
58+ 'asarray':self._asarray,
59+ 'asimage':self._asimage,
60+ 'html_embed_image':self._embed_image,
61+ 'get_attachments':self._get_attachments,
62+ 'get_name':self._get_name,
63+ 'get_label':self._get_label,
64+ 'getLang':self._get_lang,
65+ 'get_selection_item':self._get_selection_items('item'),
66+ 'safe':self._get_safe,
67+ 'countif':self._countif,
68+ 'count':self._count,
69+ 'sumif':self._sumif,
70+ 'sum':self._sum,
71+ 'max':self._max,
72+ 'min':self._min,
73+ 'average':self._average,
74+ 'large':self._large,
75+ 'small':self._small,
76+ 'count_blank':self._count_blank,
77+ '_':self._translate_text,
78+ 'gettext':self._translate_text,
79+ 'currency_to_text':self._currency2text(context['company'].currency_id.name), #self._currency2text(context['company'].currency_id.code),
80+ 'barcode':barcode.make_barcode,
81+ 'debugit':self.debugit,
82+ 'dec_to_time':self._dec2time,
83+ 'chunks':self._chunks,
84+ 'browse':self._browse,
85+ 'field_size':self._field_size,
86+ 'bool_as_icon':self._bool_as_icon,
87+ 'time':time,
88+ 'report_xml': self._get_report_xml(),
89+ 'get_log': self._perm_read(self.cr, self.uid),
90+ 'get_selection_items': self._get_selection_items(),
91+ }
92+
93+ def _perm_read(self, cr, uid):
94+ def get_log(obj, field=None):
95+ if field:
96+ return obj.perm_read(self.uid, [obj.id])[0][field]
97+ else:
98+ return obj.perm_read(self.uid, [obj.id])[0]
99+ return get_log
100+
101+ def _get_report_xml(self):
102+ return self.pool.get('ir.actions.report.xml').browse(self.cr, self.uid, self.report_id)
103+
104+ def _get_lang(self, source='current'):
105+ if source=='current':
106+ return self.context['lang'] or self.context['user_lang']
107+ elif source=='company':
108+ return self.context['user'].company_id.partner_id.lang
109+ elif source=='user':
110+ return self.context['user_lang']
111+
112+ def _bool_as_icon(self, val, kind=0):
113+ if isinstance(kind, (list, tuple)):
114+ if val==True:
115+ return kind [0]
116+ elif val==False:
117+ return kind[1]
118+ else:
119+ return kind[2]
120+ bool_kind = {0:{True:self._translate_text('True'), False:self._translate_text('False'), None:""},
121+ 1:{True:self._translate_text('T'), False:self._translate_text('F'), None:""},
122+ 2:{True:self._translate_text('Yes'), False:self._translate_text('No'), None:""},
123+ 3:{True:self._translate_text('Y'), False:self._translate_text('N'), None:""},
124+ 4:{True:'+', False:'-', None:""},
125+ 5:{True:'[ + ]', False:'[ - ]', None:"[ ]"},
126+ 6:{True:'[ x ]', False:'[ ]', None:"[ ]"},
127+ }
128+ return bool_kind.get(kind, {}).get(val, val)
129+
130+ def _dec2time(self, dec, h_format, min_format):
131+ if dec==0.0:
132+ return None
133+ elif int(dec)==0:
134+ return min_format.replace('%M', str(int(round((dec-int(dec))*60))))
135+ elif dec-int(dec)==0.0:
136+ return h_format.replace('%H', str(int(dec)))
137+ else:
138+ return h_format.replace('%H', str(int(dec)))+min_format.replace('%M', str(int(round((dec-int(dec))*60))))
139+
140+ def _currency2text(self, currency):
141+ def c_to_text(sum, currency=currency, language=None):
142+ return unicode(currency_to_text(sum, currency, language or self._get_lang()), "UTF-8")
143+ return c_to_text
144+
145+ def _translate_text(self, source):
146+ trans_obj = self.pool.get('ir.translation')
147+ trans = trans_obj.search(self.cr,self.uid,[('res_id','=',self.report_id),('type','=','report'),('src','=',source),('lang','=',self.context['lang'] or self.context['user_lang'])])
148+ if not trans:
149+ trans_obj.create(self.cr, self.uid, {'src':source,'type':'report','lang':self._get_lang(),'res_id':self.report_id,'name':('ir.actions.report.xml,%s' % source)[:128]})
150+ return translate(self.cr, False, 'report', self._get_lang(), source) or source
151+
152+ def _countif(self, attr, domain):
153+ statement = domain2statement(domain)
154+ expr = "for o in objects:\n\tif%s:\n\t\tcount+=1" % statement
155+ localspace = {'objects':attr, 'count':0}
156+ exec expr in localspace
157+ return localspace['count']
158+
159+ def _count_blank(self, attr, field):
160+ expr = "for o in objects:\n\tif not o.%s:\n\t\tcount+=1" % field
161+ localspace = {'objects':attr, 'count':0}
162+ exec expr in localspace
163+ return localspace['count']
164+
165+ def _count(self, attr):
166+ return len(attr)
167+
168+ def _sumif(self, attr, sum_field, domain):
169+ statement = domain2statement(domain)
170+ expr = "for o in objects:\n\tif%s:\n\t\tsumm+=float(o.%s)" % (statement, sum_field)
171+ localspace = {'objects':attr, 'summ':0}
172+ exec expr in localspace
173+ return localspace['summ']
174+
175+ def _sum(self, attr, sum_field):
176+ expr = "for o in objects:\n\tsumm+=float(o.%s)" % sum_field
177+ localspace = {'objects':attr, 'summ':0}
178+ exec expr in localspace
179+ return localspace['summ']
180+
181+ def _max(self, attr, field):
182+ expr = "for o in objects:\n\tvalue_list.append(o.%s)" % field
183+ localspace = {'objects':attr, 'value_list':[]}
184+ exec expr in localspace
185+ return max(localspace['value_list'])
186+
187+ def _min(self, attr, field):
188+ expr = "for o in objects:\n\tvalue_list.append(o.%s)" % field
189+ localspace = {'objects':attr, 'value_list':[]}
190+ exec expr in localspace
191+ return min(localspace['value_list'])
192+
193+ def _average(self, attr, field):
194+ expr = "for o in objects:\n\tvalue_list.append(o.%s)" % field
195+ localspace = {'objects':attr, 'value_list':[]}
196+ exec expr in localspace
197+ return float(sum(localspace['value_list']))/float(len(localspace['value_list']))
198+
199+ def _asarray(self, attr, field):
200+ expr = "for o in objects:\n\tvalue_list.append(o.%s)" % field
201+ localspace = {'objects':attr, 'value_list':[]}
202+ exec expr in localspace
203+ return localspace['value_list']
204+
205+ def _get_name(self, obj):
206+ if obj.__class__==osv.orm.browse_record:
207+ return self.pool.get(obj._table_name).name_get(self.cr, self.uid, [obj.id], {'lang':self._get_lang()})[0][1]
208+ return ''
209+
210+ #def _get_label(self, obj, field):
211+ # try:
212+ # if isinstance(obj, report_sxw.browse_record_list):
213+ # obj = obj[0]
214+ # if isinstance(obj, (str,unicode)):
215+ # model = obj
216+ # else:
217+ # model = obj._table_name
218+ # if isinstance(obj, (str,unicode)) or hasattr(obj, field):
219+ # label = self.pool.get(model)._columns[field].string
220+ # return translate(self.cr, False, 'field', self._get_lang(), label) or label
221+ # except Exception, e:
222+ # return ''
223+
224+ def _get_label(self, obj, field):
225+ try:
226+ if isinstance(obj, report_sxw.browse_record_list):
227+ obj = obj[0]
228+ if isinstance(obj, (str,unicode)):
229+ model = obj
230+ else:
231+ model = obj._table_name
232+ if isinstance(obj, (str,unicode)) or hasattr(obj, field):
233+ labels = self.pool.get(model).fields_get(self.cr, self.uid, fields=[field], context=self.context)
234+ return labels[field]['string']
235+ except Exception, e:
236+ return ''
237+
238+ def _field_size(self, obj, field):
239+ try:
240+ if getattr(obj, field):
241+ size = self.pool.get(obj._table_name)._columns[field].size
242+ return size
243+ except Exception:
244+ return ''
245+
246+ def _get_selection_items(self, kind='items'):
247+ def get_selection_item(obj, field, value=None):
248+ try:
249+ if isinstance(obj, report_sxw.browse_record_list):
250+ obj = obj[0]
251+ if isinstance(obj, (str,unicode)):
252+ model = obj
253+ field_val = value
254+ else:
255+ model = obj._table_name
256+ field_val = getattr(obj, field)
257+ if kind=='item':
258+ if field_val:
259+ return dict(self.pool.get(model).fields_get(self.cr, self.uid, fields=[field], context=self.context)[field]['selection'])[field_val]
260+ elif kind=='items':
261+ return self.pool.get(model).fields_get(self.cr, self.uid, fields=[field], context=self.context)[field]['selection']
262+ #selection = self.pool.get(model)._columns[field].selection
263+ #if selection.__class__==list:
264+ # val_dict = dict(selection)
265+ #else:
266+ # val_dict = dict(selection(self.pool.get(model), self.cr, self.uid, {'lang':self._get_lang()}))
267+ #return val_dict[field_val]
268+ return ''
269+ except Exception:
270+ return ''
271+ return get_selection_item
272+
273+ def _get_attachments(self, o, index=None):
274+ attach_obj = self.pool.get('ir.attachment')
275+ srch_param = [('res_model','=',o._name),('res_id','=',o.id)]
276+ if type(index)==str:
277+ srch_param.append(('name','=',index))
278+ attachments = attach_obj.search(self.cr,self.uid,srch_param)
279+ res = [x['datas'] for x in attach_obj.read(self.cr,self.uid,attachments,['datas']) if x['datas']]
280+ if type(index)==int:
281+ return res[index]
282+ return len(res)==1 and res[0] or res
283+
284+ def _asimage(self, field_value, rotate=None):
285+ if not field_value:
286+ return StringIO.StringIO(), 'image/png'
287+ field_value = base64.decodestring(field_value)
288+ tf = StringIO.StringIO(field_value)
289+ tf.seek(0)
290+ im=Image.open(tf)
291+ try:
292+ if rotate!=None:
293+ im=im.rotate(int(rotate))
294+ tf.seek(0)
295+ im.save(tf, im.format.lower())
296+ except Exception, e:
297+ pass
298+ size_x = str(im.size[0]/96.0)+'in'
299+ size_y = str(im.size[1]/96.0)+'in'
300+ return tf, 'image/%s' % im.format.lower(), size_x, size_y
301+
302+ def _embed_image(self, extention, img, width=0, height=0) :
303+ "Transform a DB image into an embeded HTML image"
304+ try:
305+ if width :
306+ width = 'width="%spx"'%(width)
307+ else :
308+ width = ' '
309+ if height :
310+ height = 'width="%spx"'%(height)
311+ else :
312+ height = ' '
313+ toreturn = '<img %s %s src="data:image/%s;base64,%s">' % (width, height, extention, str(img))
314+ return toreturn
315+ except Exception, exp:
316+ print exp
317+ return 'No image'
318+
319+ def _large(self, attr, field, n):
320+ array=self._asarray(attr, field)
321+ try:
322+ n-=1
323+ while(n):
324+ array.remove(max(array))
325+ n-=1
326+ return max(array)
327+ except ValueError, e:
328+ return None
329+
330+ def _small(self, attr, field, n):
331+ array=self._asarray(attr, field)
332+ try:
333+ n-=1
334+ while(n):
335+ array.remove(min(array))
336+ n-=1
337+ return min(array)
338+ except ValueError, e:
339+ return None
340+
341+ def _chunks(self, l, n):
342+ """ Yield successive n-sized chunks from l.
343+ """
344+ for i in xrange(0, len(l), n):
345+ yield l[i:i+n]
346+
347+ def _browse(self, *args):
348+ if not args or (args and not args[0]):
349+ return None
350+ if len(args)==1:
351+ model, id = args[0].split(',')
352+ id = int(id)
353+ elif len(args)==2:
354+ model, id = args
355+ else:
356+ raise None
357+ return self.pool.get(model).browse(self.cr, self.uid, id)
358+
359+ def _get_safe(self, expression, obj):
360+ try:
361+ return eval(expression, {'o':obj})
362+ except Exception, e:
363+ return None
364+
365+ def debugit(self, object):
366+ """ Run the server from command line and
367+ call 'debugit' from the template to inspect variables.
368+ """
369+ import pdb;pdb.set_trace()
370+ return
371+
372
373=== added file '__init__.py'
374--- __init__.py 1970-01-01 00:00:00 +0000
375+++ __init__.py 2012-07-05 12:25:24 +0000
376@@ -0,0 +1,31 @@
377+##############################################################################
378+#
379+# Copyright (c) 2008-2009 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
380+# General contacts <info@kndati.lv>
381+#
382+# WARNING: This program as such is intended to be used by professional
383+# programmers who take the whole responsability of assessing all potential
384+# consequences resulting from its eventual inadequacies and bugs
385+# End users who are looking for a ready-to-use solution with commercial
386+# garantees and support are strongly adviced to contract a Free Software
387+# Service Company
388+#
389+# This program is Free Software; you can redistribute it and/or
390+# modify it under the terms of the GNU General Public License
391+# as published by the Free Software Foundation; either version 2
392+# of the License, or (at your option) any later version.
393+#
394+# This program is distributed in the hope that it will be useful,
395+# but WITHOUT ANY WARRANTY; without even the implied warranty of
396+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
397+# GNU General Public License for more details.
398+#
399+# You should have received a copy of the GNU General Public License
400+# along with this program; if not, write to the Free Software
401+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
402+#
403+##############################################################################
404+
405+import report_xml
406+import report_aeroo
407+import wizard
408
409=== added file '__openerp__.py'
410--- __openerp__.py 1970-01-01 00:00:00 +0000
411+++ __openerp__.py 2012-07-05 12:25:24 +0000
412@@ -0,0 +1,37 @@
413+# -*- encoding: utf-8 -*-
414+
415+#########################################################################
416+# #
417+# Copyright (C) 2009 Domsense s.r.l. #
418+# @authors: Simone Orsi #
419+# Copyright (C) 2009-2010 KN dati, Ltd #
420+# #
421+#This program is free software: you can redistribute it and/or modify #
422+#it under the terms of the GNU General Public License as published by #
423+#the Free Software Foundation, either version 3 of the License, or #
424+#(at your option) any later version. #
425+# #
426+#This program is distributed in the hope that it will be useful, #
427+#but WITHOUT ANY WARRANTY; without even the implied warranty of #
428+#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
429+#GNU General Public License for more details. #
430+# #
431+#You should have received a copy of the GNU General Public License #
432+#along with this program. If not, see <http://www.gnu.org/licenses/>. #
433+#########################################################################
434+
435+{
436+ 'name': 'Aeroo Reports',
437+ 'version': '1.0',
438+ 'category': 'Generic Modules/Aeroo Reporting',
439+ 'description': """ Make possible to easily create complicated reports with OOo.
440+ Requires "relatorio", "openoffice.org", "openoffice-python" to be installed.
441+ """,
442+ 'author': 'KN dati Ltd, Simone Orsi - Domsense',
443+ 'website': 'http://www.alistek.com',
444+ 'depends': ['base'],
445+ "init_xml" : [],
446+ 'update_xml': ["report_view.xml", "data/report_aeroo_data.xml", "security/ir.model.access.csv"],
447+ 'installable': True,
448+ 'active': False,
449+}
450
451=== added directory 'barcode'
452=== added file 'barcode/EANBarCode.py'
453--- barcode/EANBarCode.py 1970-01-01 00:00:00 +0000
454+++ barcode/EANBarCode.py 2012-07-05 12:25:24 +0000
455@@ -0,0 +1,148 @@
456+# Copyright (c) 2009-2010 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
457+# General contacts <info@kndati.lv>
458+
459+from tools import config
460+
461+"""
462+This class generate EAN bar code, it required PIL (python imaging library)
463+installed.
464+
465+If the code has not checksum (12 digits), it added automatically.
466+
467+Create bar code sample :
468+ from EANBarCode import EanBarCode
469+ bar = EanBarCode()
470+ bar.getImage("9782212110708",50,"gif")
471+
472+"""
473+
474+class EanBarCode:
475+ """ Compute the EAN bar code """
476+ def __init__(self):
477+ A = {0 : "0001101", 1 : "0011001", 2 : "0010011", 3 : "0111101", 4 : "0100011",
478+ 5 : "0110001", 6 : "0101111", 7 : "0111011", 8 : "0110111", 9 : "0001011"}
479+ B = {0 : "0100111", 1 : "0110011", 2 : "0011011", 3 : "0100001", 4 : "0011101",
480+ 5 : "0111001", 6 : "0000101", 7 : "0010001", 8 : "0001001", 9 : "0010111"}
481+ C = {0 : "1110010", 1 : "1100110", 2 : "1101100", 3 : "1000010", 4 : "1011100",
482+ 5 : "1001110", 6 : "1010000", 7 : "1000100", 8 : "1001000", 9 : "1110100"}
483+ self.groupC = C
484+
485+ self.family = {0 : (A,A,A,A,A,A), 1 : (A,A,B,A,B,B), 2 : (A,A,B,B,A,B), 3 : (A,A,B,B,B,A), 4 : (A,B,A,A,B,B),
486+ 5 : (A,B,B,A,A,B), 6 : (A,B,B,B,A,A), 7 : (A,B,A,B,A,B), 8 : (A,B,A,B,B,A), 9 : (A,B,B,A,B,A)}
487+
488+
489+ def makeCode(self, code):
490+ """ Create the binary code
491+ return a string which contains "0" for white bar, "1" for black bar, "L" for long bar """
492+
493+ # Convert code string in integer list
494+ self.EAN13 = []
495+ for digit in code:
496+ self.EAN13.append(int(digit))
497+
498+ # If the code has already a checksum
499+ if len(self.EAN13) == 13:
500+ # Verify checksum
501+ self.verifyChecksum(self.EAN13)
502+ # If the code has not yet checksum
503+ elif len(self.EAN13) == 12:
504+ # Add checksum value
505+ self.EAN13.append(self.computeChecksum(self.EAN13))
506+
507+ # Get the left codage class
508+ left = self.family[self.EAN13[0]]
509+
510+ # Add start separator
511+ strCode = 'L0L'
512+
513+ # Compute the left part of bar code
514+ for i in range(0,6):
515+ strCode += left[i][self.EAN13[i+1]]
516+
517+ # Add middle separator
518+ strCode += '0L0L0'
519+
520+ # Compute the right codage class
521+ for i in range (7,13):
522+ strCode += self.groupC[self.EAN13[i]]
523+
524+ # Add stop separator
525+ strCode += 'L0L'
526+
527+ return strCode
528+
529+
530+ def computeChecksum(self, arg):
531+ """ Compute the checksum of bar code """
532+ # UPCA/EAN13
533+ weight=[1,3]*6
534+ magic=10
535+ sum = 0
536+
537+ for i in range(12): # checksum based on first 12 digits.
538+ sum = sum + int(arg[i]) * weight[i]
539+ z = ( magic - (sum % magic) ) % magic
540+ if z < 0 or z >= magic:
541+ return None
542+ return z
543+
544+
545+ def verifyChecksum(self, bits):
546+ """ Verify the checksum """
547+ computedChecksum = self.computeChecksum(bits[:12])
548+ codeBarChecksum = bits[12]
549+
550+ if codeBarChecksum != computedChecksum:
551+ raise Exception ("Bad checksum is %s and should be %s"%(codeBarChecksum, computedChecksum))
552+
553+
554+ def getImage(self, value, height = 50, xw=1, rotate=None, extension = "PNG"):
555+ """ Get an image with PIL library
556+ value code barre value
557+ height height in pixel of the bar code
558+ extension image file extension"""
559+ import Image, ImageFont, ImageDraw, os
560+ from string import lower, upper
561+
562+ # Get the bar code list
563+ bits = self.makeCode(value)
564+
565+ # Get thee bar code with the checksum added
566+ code = ""
567+ for digit in self.EAN13:
568+ code += "%d"%digit
569+
570+ # Create a new image
571+ position = 8
572+ im = Image.new("1",(len(bits)+position,height))
573+
574+ # Load font
575+ font = ImageFont.load(config['addons_path']+"/report_aeroo/barcode/courB08.pil")
576+
577+ # Create drawer
578+ draw = ImageDraw.Draw(im)
579+
580+ # Erase image
581+ draw.rectangle(((0,0),(im.size[0],im.size[1])),fill=256)
582+
583+ # Draw first part of number
584+ draw.text((0, height-9), code[0], font=font, fill=0)
585+
586+ # Draw first part of number
587+ draw.text((position+7, height-9), code[1:7], font=font, fill=0)
588+
589+ # Draw second part of number
590+ draw.text((len(bits)/2+6+position, height-9), code[7:], font=font, fill=0)
591+
592+ # Draw the bar codes
593+ for bit in range(len(bits)):
594+ # Draw normal bar
595+ if bits[bit] == '1':
596+ draw.rectangle(((bit+position,0),(bit+position,height-10)),fill=0)
597+ # Draw long bar
598+ elif bits[bit] == 'L':
599+ draw.rectangle(((bit+position,0),(bit+position,height-3)),fill=0)
600+
601+ # Save the result image
602+ return im
603+
604
605=== added file 'barcode/FreeMonoBold.ttf'
606Binary files barcode/FreeMonoBold.ttf 1970-01-01 00:00:00 +0000 and barcode/FreeMonoBold.ttf 2012-07-05 12:25:24 +0000 differ
607=== added file 'barcode/__init__.py'
608--- barcode/__init__.py 1970-01-01 00:00:00 +0000
609+++ barcode/__init__.py 2012-07-05 12:25:24 +0000
610@@ -0,0 +1,30 @@
611+##############################################################################
612+#
613+# Copyright (c) 2008-2009 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
614+# General contacts <info@kndati.lv>
615+#
616+# WARNING: This program as such is intended to be used by professional
617+# programmers who take the whole responsability of assessing all potential
618+# consequences resulting from its eventual inadequacies and bugs
619+# End users who are looking for a ready-to-use solution with commercial
620+# garantees and support are strongly adviced to contract a Free Software
621+# Service Company
622+#
623+# This program is Free Software; you can redistribute it and/or
624+# modify it under the terms of the GNU General Public License
625+# as published by the Free Software Foundation; either version 2
626+# of the License, or (at your option) any later version.
627+#
628+# This program is distributed in the hope that it will be useful,
629+# but WITHOUT ANY WARRANTY; without even the implied warranty of
630+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
631+# GNU General Public License for more details.
632+#
633+# You should have received a copy of the GNU General Public License
634+# along with this program; if not, write to the Free Software
635+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
636+#
637+##############################################################################
638+
639+import barcode
640+
641
642=== added file 'barcode/barcode.py'
643--- barcode/barcode.py 1970-01-01 00:00:00 +0000
644+++ barcode/barcode.py 2012-07-05 12:25:24 +0000
645@@ -0,0 +1,59 @@
646+##############################################################################
647+#
648+# Copyright (c) 2008-2009 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
649+# General contacts <info@kndati.lv>
650+#
651+# WARNING: This program as such is intended to be used by professional
652+# programmers who take the whole responsability of assessing all potential
653+# consequences resulting from its eventual inadequacies and bugs
654+# End users who are looking for a ready-to-use solution with commercial
655+# garantees and support are strongly adviced to contract a Free Software
656+# Service Company
657+#
658+# This program is Free Software; you can redistribute it and/or
659+# modify it under the terms of the GNU General Public License
660+# as published by the Free Software Foundation; either version 2
661+# of the License, or (at your option) any later version.
662+#
663+# This program is distributed in the hope that it will be useful,
664+# but WITHOUT ANY WARRANTY; without even the implied warranty of
665+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
666+# GNU General Public License for more details.
667+#
668+# You should have received a copy of the GNU General Public License
669+# along with this program; if not, write to the Free Software
670+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
671+#
672+##############################################################################
673+
674+from code128 import get_code
675+from code39 import create_c39
676+from EANBarCode import EanBarCode
677+try:
678+ from cStringIO import StringIO
679+except ImportError:
680+ from StringIO import StringIO
681+
682+def make_barcode(code, code_type='ean13', rotate=None, height=50, xw=1):
683+ if code:
684+ if code_type.lower()=='ean13':
685+ bar=EanBarCode()
686+ im = bar.getImage(code,height)
687+ elif code_type.lower()=='code128':
688+ im = get_code(code, xw, height)
689+ elif code_type.lower()=='code39':
690+ im = create_c39(height, xw, code)
691+ else:
692+ return StringIO(), 'image/png'
693+
694+ tf = StringIO()
695+ try:
696+ if rotate!=None:
697+ im=im.rotate(int(rotate))
698+ except Exception, e:
699+ pass
700+ im.save(tf, 'png')
701+ size_x = str(im.size[0]/96.0)+'in'
702+ size_y = str(im.size[1]/96.0)+'in'
703+ return tf, 'image/png', size_x, size_y
704+
705
706=== added file 'barcode/code128.py'
707--- barcode/code128.py 1970-01-01 00:00:00 +0000
708+++ barcode/code128.py 2012-07-05 12:25:24 +0000
709@@ -0,0 +1,184 @@
710+# Copyright (c) 2009-2010 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
711+# General contacts <info@kndati.lv>
712+# This list was cut'n'pasted verbatim from the "Code 128 Specification Page"
713+# at http://www.adams1.com/pub/russadam/128code.html
714+
715+codelist="""0 SP SP 00 2 1 2 2 2 2
716+1 ! ! 01 2 2 2 1 2 2
717+2 " " 02 2 2 2 2 2 1
718+3 # # 03 1 2 1 2 2 3
719+4 $ $ 04 1 2 1 3 2 2
720+5 % % 05 1 3 1 2 2 2
721+6 & & 06 1 2 2 2 1 3
722+7 ' ' 07 1 2 2 3 1 2
723+8 ( ( 08 1 3 2 2 1 2
724+9 ) ) 09 2 2 1 2 1 3
725+10 * * 10 2 2 1 3 1 2
726+11 + + 11 2 3 1 2 1 2
727+12 , , 12 1 1 2 2 3 2
728+13 - - 13 1 2 2 1 3 2
729+14 . . 14 1 2 2 2 3 1
730+15 / / 15 1 1 3 2 2 2
731+16 0 0 16 1 2 3 1 2 2
732+17 1 1 17 1 2 3 2 2 1
733+18 2 2 18 2 2 3 2 1 1
734+19 3 3 19 2 2 1 1 3 2
735+20 4 4 20 2 2 1 2 3 1
736+21 5 5 21 2 1 3 2 1 2
737+22 6 6 22 2 2 3 1 1 2
738+23 7 7 23 3 1 2 1 3 1
739+24 8 8 24 3 1 1 2 2 2
740+25 9 9 25 3 2 1 1 2 2
741+26 : : 26 3 2 1 2 2 1
742+27 ; ; 27 3 1 2 2 1 2
743+28 < < 28 3 2 2 1 1 2
744+29 = = 29 3 2 2 2 1 1
745+30 > > 30 2 1 2 1 2 3
746+31 ? ? 31 2 1 2 3 2 1
747+32 @ @ 32 2 3 2 1 2 1
748+33 A A 33 1 1 1 3 2 3
749+34 B B 34 1 3 1 1 2 3
750+35 C C 35 1 3 1 3 2 1
751+36 D D 36 1 1 2 3 1 3
752+37 E E 37 1 3 2 1 1 3
753+38 F F 38 1 3 2 3 1 1
754+39 G G 39 2 1 1 3 1 3
755+40 H H 40 2 3 1 1 1 3
756+41 I I 41 2 3 1 3 1 1
757+42 J J 42 1 1 2 1 3 3
758+43 K K 43 1 1 2 3 3 1
759+44 L L 44 1 3 2 1 3 1
760+45 M M 45 1 1 3 1 2 3
761+46 N N 46 1 1 3 3 2 1
762+47 O O 47 1 3 3 1 2 1
763+48 P P 48 3 1 3 1 2 1
764+49 Q Q 49 2 1 1 3 3 1
765+50 R R 50 2 3 1 1 3 1
766+51 S S 51 2 1 3 1 1 3
767+52 T T 52 2 1 3 3 1 1
768+53 U U 53 2 1 3 1 3 1
769+54 V V 54 3 1 1 1 2 3
770+55 W W 55 3 1 1 3 2 1
771+56 X X 56 3 3 1 1 2 1
772+57 Y Y 57 3 1 2 1 1 3
773+58 Z Z 58 3 1 2 3 1 1
774+59 [ [ 59 3 3 2 1 1 1
775+60 \\ \\ 60 3 1 4 1 1 1
776+61 ] ] 61 2 2 1 4 1 1
777+62 ^ ^ 62 4 3 1 1 1 1
778+63 _ _ 63 1 1 1 2 2 4
779+64 NUL ' 64 1 1 1 4 2 2
780+65 SOH a 65 1 2 1 1 2 4
781+66 STX b 66 1 2 1 4 2 1
782+67 ETX c 67 1 4 1 1 2 2
783+68 EOT d 68 1 4 1 2 2 1
784+69 ENQ e 69 1 1 2 2 1 4
785+70 ACK f 70 1 1 2 4 1 2
786+71 BEL g 61 1 2 2 1 1 4
787+72 BS h 72 1 2 2 4 1 1
788+73 HT i 73 1 4 2 1 1 2
789+74 LF j 74 1 4 2 2 1 1
790+75 VT k 75 2 4 1 2 1 1
791+76 FF l 76 2 2 1 1 1 4
792+77 CR m 77 4 1 3 1 1 1
793+78 SO n 78 2 4 1 1 1 2
794+79 SI o 79 1 3 4 1 1 1
795+80 DLE p 80 1 1 1 2 4 2
796+81 DC1 q 81 1 2 1 1 4 2
797+82 DC2 r 82 1 2 1 2 4 1
798+83 DC3 s 83 1 1 4 2 1 2
799+84 DC4 t 84 1 2 4 1 1 2
800+85 NAK u 85 1 2 4 2 1 1
801+86 SYN v 86 4 1 1 2 1 2
802+87 ETB w 87 4 2 1 1 1 2
803+88 CAN x 88 4 2 1 2 1 1
804+89 EM y 89 2 1 2 1 4 1
805+90 SUB z 90 2 1 4 1 2 1
806+91 ESC { 91 4 1 2 1 2 1
807+92 FS | 92 1 1 1 1 4 3
808+93 GS } 93 1 1 1 3 4 1
809+94 RS ~ 94 1 3 1 1 4 1
810+95 (Hex 7F) US DEL 95 1 1 4 1 1 3
811+96 (Hex 80) FNC 3 FNC 3 96 1 1 4 3 1 1
812+97 (Hex 81) FNC 2 FNC 2 97 4 1 1 1 1 3
813+98 (Hex 82) SHIFT SHIFT 98 4 1 1 3 1 1
814+99 (Hex 83) CODE C CODE C 99 1 1 3 1 4 1
815+100 (Hex 84) CODE B FNC 4 CODE B 1 1 4 1 3 1
816+101 (Hex 85) FNC 4 CODE A CODE A 3 1 1 1 4 1
817+102 (Hex 86) FNC 1 FNC 1 FNC 1 4 1 1 1 3 1"""
818+
819+
820+
821+
822+other="""103 (Hex 87) START (Code A) 2 1 1 4 1 2
823+104 (Hex 88) START (Code B) 2 1 1 2 1 4
824+105 (Hex 89) START (Code C) 2 1 1 2 3 2
825+106 STOP 2 3 3 1 1 1 2"""
826+
827+
828+codes={}
829+values={}
830+for l in codelist.split('\n'):
831+ l.strip()
832+ num,a1,b1,c1,code=l.split('\t')
833+ num=int(num.split(' ')[0])
834+ values[num]=[int(x) for x in code.split()]
835+ codes[b1.strip()]=num
836+
837+codes[' ']=codes['SP']
838+
839+for l in other.split('\n'):
840+ l.strip()
841+ num,name,code=l.split('\t')
842+ num=int(num.split(' ')[0])
843+ values[num]=[int(x) for x in code.split()]
844+ codes[name.strip()]=num
845+
846+def encode_message(msg):
847+ startnum=codes['START (Code B)']
848+ message=values[startnum][:]
849+ chksum=startnum
850+ mult=1
851+ for c in msg:
852+ if not codes.has_key(c):
853+ raise "No code for "+c
854+ chksum=chksum+mult*codes[c]
855+ mult=mult+1
856+ message=message+values[codes[c]]
857+
858+ chksum=chksum%103
859+
860+ message=message+values[chksum]
861+ message=message+values[codes['STOP']]
862+
863+ return message
864+
865+
866+import Image, os
867+def get_code(message,xw=1,h=100,rotate=None):
868+ """ message is message to code.
869+ xw is horizontal multiplier (in pixels width of narrowest bar)
870+ h is height in pixels.
871+
872+ Returns a Python Imaging Library object."""
873+
874+ widths=[xw*20]+encode_message(message)+[xw*20]
875+
876+ bits=[]
877+ i=1
878+ for w in widths:
879+ bits=bits+[i]*w*xw
880+ i=1-i
881+
882+ #print len(bits)
883+ #print bits
884+
885+ i=Image.new('1',(len(bits),h),1)
886+
887+ for b in range(len(bits)):
888+ for y in range(h):
889+ i.putpixel((b,y),255*bits[b])
890+
891+ return i
892+
893+
894
895=== added file 'barcode/code39.py'
896--- barcode/code39.py 1970-01-01 00:00:00 +0000
897+++ barcode/code39.py 2012-07-05 12:25:24 +0000
898@@ -0,0 +1,153 @@
899+# Copyright (c) 2008 marscel.wordpress.com
900+#
901+# Copyright (c) 2010 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
902+# General contacts <info@kndati.lv>
903+
904+# Code39.py v1
905+# Requires Python and Python Imaging Library (PIL),
906+# has been tested with Python v2.6 and PIL v1.1.6
907+
908+# Usage example:
909+# code39.py 100 2 "Hello World" barcode.png
910+#
911+# This creates a PNG image "barcode.png" containing a barcode of the height of 100px
912+# a min line width of 2px with "Hello World" encoded as "*HELLO WORLD*" in Code 39
913+
914+import Image, ImageDraw, ImageFont, sys
915+from tools import config
916+
917+marginx = 10
918+marginy = 10
919+fontsize = 15
920+
921+charmap = {
922+'*':[0,3,0,1,2,1,2,1,0],
923+'-':[0,3,0,1,0,1,2,1,2],
924+'$':[0,3,0,3,0,3,0,1,0],
925+'%':[0,1,0,3,0,3,0,3,0],
926+' ':[0,3,2,1,0,1,2,1,0],
927+'.':[2,3,0,1,0,1,2,1,0],
928+'/':[0,3,0,3,0,1,0,3,0],
929+'+':[0,3,0,1,0,3,0,3,0],
930+'0':[0,1,0,3,2,1,2,1,0],
931+'1':[2,1,0,3,0,1,0,1,2],
932+'2':[0,1,2,3,0,1,0,1,2],
933+'3':[2,1,2,3,0,1,0,1,0],
934+'4':[0,1,0,3,2,1,0,1,2],
935+'5':[2,1,0,3,2,1,0,1,0],
936+'6':[0,1,2,3,2,1,0,1,0],
937+'7':[0,1,0,3,0,1,2,1,2],
938+'8':[2,1,0,3,0,1,2,1,0],
939+'9':[0,1,2,3,0,1,2,1,0],
940+'A':[2,1,0,1,0,3,0,1,2],
941+'B':[0,1,2,1,0,3,0,1,2],
942+'C':[2,1,2,1,0,3,0,1,0],
943+'D':[0,1,0,1,2,3,0,1,2],
944+'E':[2,1,0,1,2,3,0,1,0],
945+'F':[0,1,2,1,2,3,0,1,0],
946+'G':[0,1,0,1,0,3,2,1,2],
947+'H':[2,1,0,1,0,3,2,1,0],
948+'I':[0,1,2,1,0,3,2,1,0],
949+'J':[0,1,0,1,2,3,2,1,0],
950+'K':[2,1,0,1,0,1,0,3,2],
951+'L':[0,1,2,1,0,1,0,3,2],
952+'M':[2,1,2,1,0,1,0,3,0],
953+'N':[0,1,0,1,2,1,0,3,2],
954+'O':[2,1,0,1,2,1,0,3,0],
955+'P':[0,1,2,1,2,1,0,3,0],
956+'Q':[0,1,0,1,0,1,2,3,2],
957+'R':[2,1,0,1,0,1,2,3,0],
958+'S':[0,1,2,1,0,1,2,3,0],
959+'T':[0,1,0,1,2,1,2,3,0],
960+'U':[2,3,0,1,0,1,0,1,2],
961+'V':[0,3,2,1,0,1,0,1,2],
962+'W':[2,3,2,1,0,1,0,1,0],
963+'X':[0,3,0,1,2,1,0,1,2],
964+'Y':[2,3,0,1,2,1,0,1,0],
965+'Z':[0,3,2,1,2,1,0,1,0]
966+}
967+
968+def create_c39(height, smallest, text):
969+ pixel_length = 0
970+ i = 0
971+ newtext = ""
972+ machinetext = "*" + text + "*"
973+ seglist = []
974+ while i < len(machinetext):
975+ char = machinetext[i].capitalize()
976+ i = i + 1
977+ try:
978+ map = charmap[char]
979+ if len(map) != 9:
980+ continue
981+
982+ j = 0
983+ while j < 9:
984+ seg = int(map[j])
985+
986+ if seg == 0 or seg == 1:
987+ pixel_length = pixel_length + smallest
988+ seglist.append(seg)
989+ elif seg == 2 or seg == 3:
990+ pixel_length = pixel_length + smallest * 3
991+ seglist.append(seg)
992+
993+ j = j + 1
994+
995+ newtext += char
996+ except:
997+ continue
998+
999+ pixel_length = pixel_length + 2*marginx + len(newtext) * smallest
1000+ pixel_height = height + 2*marginy + fontsize
1001+
1002+ barcode_img = Image.new('RGB', [pixel_length, pixel_height], "white")
1003+
1004+ if len(seglist) == 0:
1005+ return barcode_img
1006+
1007+ i = 0
1008+ draw = ImageDraw.Draw(barcode_img)
1009+ current_x = marginx
1010+
1011+ while i < len(seglist):
1012+ seg = seglist[i]
1013+ color = (255, 255, 255)
1014+ wdth = smallest
1015+
1016+ if seg == 0 or seg == 2:
1017+ color = 0
1018+ if seg == 0:
1019+ wdth = smallest
1020+ else:
1021+ wdth = smallest * 3
1022+ elif seg == 1 or seg == 3:
1023+ color = (255, 255, 255)
1024+ if seg == 1:
1025+ wdth = smallest
1026+ else:
1027+ wdth = smallest * 3
1028+
1029+ j = 1
1030+
1031+ while j <= wdth:
1032+ draw.line((current_x, marginy, current_x, marginy+height), fill=color)
1033+ current_x = current_x + 1
1034+ j = j + 1
1035+
1036+ if ((i+1) % 9) == 0:
1037+ j = 1
1038+ while j <= smallest:
1039+ draw.line((current_x, marginy, current_x, marginy+height), fill=(255,255,255))
1040+ current_x = current_x + 1
1041+ j = j + 1
1042+ i = i + 1
1043+
1044+ font = ImageFont.truetype(config['addons_path']+"/report_aeroo/barcode/FreeMonoBold.ttf", fontsize)
1045+
1046+ draw.text((pixel_length/2 - len(newtext)*(fontsize/2)/2-len(newtext), height+fontsize), newtext, font=font, fill=0)
1047+
1048+ del draw
1049+
1050+ return barcode_img
1051+
1052
1053=== added file 'barcode/courB08.pbm'
1054Binary files barcode/courB08.pbm 1970-01-01 00:00:00 +0000 and barcode/courB08.pbm 2012-07-05 12:25:24 +0000 differ
1055=== added file 'barcode/courB08.pil'
1056Binary files barcode/courB08.pil 1970-01-01 00:00:00 +0000 and barcode/courB08.pil 2012-07-05 12:25:24 +0000 differ
1057=== added file 'currency_to_text.py'
1058--- currency_to_text.py 1970-01-01 00:00:00 +0000
1059+++ currency_to_text.py 2012-07-05 12:25:24 +0000
1060@@ -0,0 +1,490 @@
1061+#!/usr/bin/python
1062+# -*- coding: utf8 -*-
1063+
1064+###########################################################
1065+# Developed by Kaspars Vilkens - KN dati Ltd. (c) 2009
1066+# pep-8, unicode and doctests by Paul Stevens, paul@nfg.nl, 2010
1067+#
1068+# Supported currencies: LVL, EUR, USD, UAH
1069+# Supported sum: 0 ... 999999999999.99
1070+# Supported languages: lv_LV, en_US, ru_RU, uk_UA
1071+###########################################################
1072+import string
1073+
1074+supported_currency = ['LVL','EUR','USD', 'UAH']
1075+supported_language = ['lv_LV','en_US','ru_RU', 'uk_UA']
1076+
1077+def currency_to_text(sum, currency, language):
1078+ """
1079+
1080+ first some simple tests
1081+
1082+ >>> currency_to_text(123, 'EUR', 'en_US')
1083+ 'one hundred twenty three euros zero cents'
1084+
1085+ >>> currency_to_text(1.11, 'EUR', 'en_US')
1086+ 'one euro eleven cents'
1087+
1088+ >>> currency_to_text(1.10, 'USD', 'en_US')
1089+ 'one US dollar ten cents'
1090+
1091+ >>> currency_to_text(1.01, 'USD', 'en_US')
1092+ 'one US dollar one cent'
1093+
1094+ >>> currency_to_text(1.01, 'LVL', 'lv_LV') == 'viens lats viens santīms'
1095+ True
1096+
1097+ >>> currency_to_text(123.12, 'LVL', 'ru_RU') == 'стo двaдцать три лата двенадцать сантимов'
1098+ True
1099+
1100+ >>> currency_to_text(123.12, 'USD', 'ru_RU') == 'стo двaдцать три доллара США двенадцать центов'
1101+ True
1102+
1103+
1104+ """
1105+ if sum < 0 or sum > 999999999999.99 :
1106+ raise Exception('Sum out of bounds: must be from 0 to 999999999999.99')
1107+ if currency not in supported_currency:
1108+ raise Exception("""Unsupported or no currency: must be one of (%s)""" % \
1109+ string.join(supported_currency,','))
1110+ if language not in supported_language:
1111+ raise Exception("""Unsupported or no language: must be one of (%s)""" % \
1112+ string.join(supported_language,','))
1113+#--------------for currencies with 100 fractions
1114+ sum = float(sum)
1115+ sum = round(sum, 2)
1116+ # find out digits before floating point - currency
1117+ sum_cur = int(sum)
1118+ # find out digits after floating point - fractions
1119+ sum_frc = int(round((sum - sum_cur) * 100,0))
1120+ cur_in_words = dtowords(sum_cur, language)
1121+ #print cur_in_words
1122+ frc_in_words = dtowords(sum_frc, language)
1123+ #print frc_in_words
1124+ #------------------------------------
1125+ if language == 'lv_LV' :
1126+ if sum_cur == 1 or (str(sum_cur)[-1] == '1' and str(sum_cur)[-2] != '1'): # is the currency sum one
1127+ if currency == 'LVL':
1128+ cur_in_words += u' lats'
1129+ elif currency == 'EUR':
1130+ cur_in_words += u' eiro'
1131+ elif currency == 'USD':
1132+ cur_in_words += u' dolārs'
1133+ elif currency == 'UAH':
1134+ cur_in_words += u' grivna'
1135+ else:
1136+ if currency == 'LVL':
1137+ cur_in_words += u' lati'
1138+ elif currency == 'EUR':
1139+ cur_in_words += u' eiro'
1140+ elif currency == 'USD':
1141+ cur_in_words += u' dolāri'
1142+ elif currency == 'UAH':
1143+ cur_in_words += u' grivnas'
1144+
1145+ if sum_frc == 1 or (str(sum_frc)[-1] == '1' and str(sum_frc)[-2] != '1'): # is the fraction sum one
1146+ if currency == 'LVL':
1147+ frc_in_words += u' santīms'
1148+ elif currency == 'EUR' or currency == 'USD' :
1149+ frc_in_words += u' cents'
1150+ elif currency == 'UAH':
1151+ frc_in_words += u' kapeika'
1152+ else:
1153+ if currency == 'LVL':
1154+ frc_in_words += u' santīmi'
1155+ elif currency == 'EUR' or currency == 'USD':
1156+ frc_in_words += u' centi'
1157+ elif currency == 'UAH':
1158+ frc_in_words += u' kapeikas'
1159+ #------------------------------------
1160+ if language == 'en_US' :
1161+ if sum_cur == 1 or (str(sum_cur)[-1] == '1' and str(sum_cur)[-2] != '1'): # is the currency sum one
1162+ if currency == 'LVL':
1163+ cur_in_words += u' Latvian lats'
1164+ elif currency == 'EUR':
1165+ cur_in_words += u' euro'
1166+ elif currency == 'USD':
1167+ cur_in_words += u' US dollar'
1168+ else:
1169+ if currency == 'LVL':
1170+ cur_in_words += u' Latvian lats'
1171+ elif currency == 'EUR':
1172+ cur_in_words += u' euros'
1173+ elif currency == 'USD':
1174+ cur_in_words += u' dollars'
1175+ if sum_frc == 1 or (str(sum_frc)[-1] == '1' and str(sum_frc)[-2] != '1'): # is the fraction sum one
1176+ if currency == 'LVL':
1177+ frc_in_words += u' santim'
1178+ elif currency == 'EUR' or currency == 'USD':
1179+ frc_in_words += u' cent'
1180+ else:
1181+ if currency == 'LVL':
1182+ frc_in_words += u' santims'
1183+ elif currency == 'EUR' or currency == 'USD' :
1184+ frc_in_words += u' cents'
1185+ #------------------------------------
1186+ if language == 'ru_RU' :
1187+ if sum_cur == 1 or (str(sum_cur)[-1] == '1' and str(sum_cur)[-2] != '1'): # is the currency sum one
1188+ if currency == 'LVL':
1189+ cur_in_words += u' лат'
1190+ elif currency == 'EUR':
1191+ cur_in_words += u' евро'
1192+ elif currency == 'USD':
1193+ cur_in_words += u' доллар США'
1194+ elif (sum_cur in [2, 3, 4]) or (str(sum_cur)[-1] in ['2', '3', '4'] and str(sum_cur)[-2] != '1'):
1195+ if currency == 'LVL':
1196+ cur_in_words += u' лата'
1197+ elif currency == 'EUR' :
1198+ cur_in_words += u' евро'
1199+ elif currency == 'USD' :
1200+ cur_in_words += u' доллара США'
1201+ elif (sum_cur >= 5 and sum_cur <= 20) or str(sum_cur)[-1] not in [2, 3, 4]:
1202+ if currency == 'LVL' :
1203+ cur_in_words += u' латов'
1204+ elif currency == 'EUR' :
1205+ cur_in_words += u' евро'
1206+ elif currency == 'USD' :
1207+ cur_in_words += u' долларов США'
1208+
1209+ if sum_frc == 1 or (str(sum_frc)[-1] == '1' and str(sum_frc)[-2] != '1') : # is the fraction one
1210+ if currency == 'LVL' :
1211+ frc_in_words += u' сантим'
1212+ elif currency == 'EUR' or currency == 'USD' :
1213+ frc_in_words += u' цент'
1214+ elif (sum_frc in [2, 3, 4]) or (str(sum_frc)[-1] in ['2', '3', '4'] and str(sum_frc)[-2] != '1') :
1215+ if currency == 'LVL' :
1216+ frc_in_words += u' сантима'
1217+ elif currency == 'EUR' or currency == 'USD' :
1218+ frc_in_words += u' цента'
1219+ elif (sum_frc >= 5 and sum_frc <= 20) or str(sum_frc)[-1] not in [2, 3, 4] :
1220+ if currency == 'LVL' :
1221+ frc_in_words += u' сантимов'
1222+ elif currency == 'EUR' or currency == 'USD' :
1223+ frc_in_words += u' центов'
1224+ #------------------------------------
1225+ if language == 'uk_UA' :
1226+ if sum_cur == 1 or (str(sum_cur)[-1] == '1' and str(sum_cur)[-2] != '1') : # is the currency sum one
1227+ if currency == 'LVL' :
1228+ cur_in_words += u' лат'
1229+ elif currency == 'EUR' :
1230+ cur_in_words += u' евро'
1231+ elif currency == 'USD' :
1232+ cur_in_words += u' доллар США'
1233+ elif currency == 'UAH' :
1234+ cur_in_words += u' гривня'
1235+ elif (sum_cur in [2, 3, 4]) or (str(sum_cur)[-1] in ['2', '3', '4'] and str(sum_cur)[-2] != '1') :
1236+ if currency == 'LVL' :
1237+ cur_in_words += u' лата'
1238+ elif currency == 'EUR' :
1239+ cur_in_words += u' евро'
1240+ elif currency == 'USD' :
1241+ cur_in_words += u' доллара США'
1242+ elif currency == 'UAH' :
1243+ cur_in_words += u' гривні'
1244+ elif (sum_cur >= 5 and sum_cur <= 20) or str(sum_cur)[-1] not in [2, 3, 4] :
1245+ if currency == 'LVL' :
1246+ cur_in_words += u' латов'
1247+ elif currency == 'EUR' :
1248+ cur_in_words += u' евро'
1249+ elif currency == 'USD' :
1250+ cur_in_words += u' долларов США'
1251+ elif currency == 'UAH' :
1252+ cur_in_words += u' гривень'
1253+
1254+ if sum_frc == 1 or (str(sum_frc)[-1] == '1' and str(sum_frc)[-2] != '1') : # is the fraction one
1255+ if currency == 'LVL' :
1256+ frc_in_words += u' сантим'
1257+ elif currency == 'EUR' or currency == 'USD' :
1258+ frc_in_words += u' цент'
1259+ elif currency == 'UAH' :
1260+ frc_in_words += u' копійка'
1261+ elif (sum_frc in [2, 3, 4]) or (str(sum_frc)[-1] in ['2', '3', '4'] and str(sum_frc)[-2] != '1') :
1262+ if currency == 'LVL' :
1263+ frc_in_words += u' сантима'
1264+ elif currency == 'EUR' or currency == 'USD' :
1265+ frc_in_words += u' цента'
1266+ elif currency == 'UAH' :
1267+ frc_in_words += u' копійки'
1268+ elif (sum_frc >= 5 and sum_frc <= 20) or str(sum_frc)[-1] not in [2, 3, 4] :
1269+ if currency == 'LVL' :
1270+ frc_in_words += u' сантимов'
1271+ elif currency == 'EUR' or currency == 'USD' :
1272+ frc_in_words += u' центов'
1273+ elif currency == 'UAH' :
1274+ frc_in_words += u' копійок'
1275+ frc_in_words = str(sum_frc) + u' коп.'
1276+
1277+ return (cur_in_words + ' ' + frc_in_words).strip().encode('utf-8')
1278+
1279+
1280+def dtowords(sum_integers, language):
1281+ """
1282+ >>> dtowords(0, 'en_US')
1283+ u'zero'
1284+
1285+ >>> dtowords(1, 'en_US')
1286+ u'one'
1287+
1288+ >>> dtowords(11, 'en_US')
1289+ u'eleven'
1290+
1291+ >>> dtowords(169, 'en_US')
1292+ u'one hundred sixty nine'
1293+
1294+ >>> dtowords(12345, 'en_US')
1295+ u'twelve thousand three hundred fourty five'
1296+
1297+ >>> dtowords(123456, 'en_US')
1298+ u'one hundred twenty three thousand four hundred fifty six'
1299+
1300+ >>> dtowords(0, 'lv_LV')
1301+ u'nulle'
1302+
1303+ >>> dtowords(1, 'lv_LV')
1304+ u'viens'
1305+
1306+ >>> dtowords(11, 'lv_LV')
1307+ u'vienpadsmit'
1308+
1309+ >>> dtowords(169, 'lv_LV').encode('utf-8') == 'simts sešdesmit deviņi'
1310+ True
1311+
1312+ >>> dtowords(12345, 'lv_LV').encode('utf-8') == 'divpadsmit tūkstoši trīs simti četrdesmit pieci'
1313+ True
1314+
1315+ >>> dtowords(123456, 'lv_LV').encode('utf-8') == 'simts divdesmit trīs tūkstoši četri simti piecdesmit seši'
1316+ True
1317+
1318+ >>> dtowords(0, 'ru_RU').encode('utf-8') == 'ноль'
1319+ True
1320+
1321+ >>> dtowords(1, 'ru_RU').encode('utf-8') == 'один'
1322+ True
1323+
1324+ >>> dtowords(11, 'ru_RU').encode('utf-8') == 'одиннадцать'
1325+ True
1326+
1327+ >>> dtowords(169, 'ru_RU').encode('utf-8') == 'стo шестьдесят девять'
1328+ True
1329+
1330+ >>> dtowords(12345, 'ru_RU').encode('utf-8') == 'двенадцать тысяч триста сорок пять'
1331+ True
1332+
1333+ >>> dtowords(123456, 'ru_RU').encode('utf-8') == 'стo двaдцать три тысячи четыреста пятьдесят шесть'
1334+ True
1335+
1336+
1337+ """
1338+ diginwords = u''
1339+ if sum_integers == 0:
1340+ return wordify('0', 0, language)
1341+ elif sum_integers > 0:
1342+ lengthx = len(str(sum_integers))
1343+ nrchunks = (lengthx / 3)
1344+ if nrchunks < (float(lengthx) / 3) :
1345+ nrchunks+=1
1346+ inc = 1
1347+ while inc <= nrchunks:
1348+ startpos = (lengthx - inc * 3)
1349+ chunklength = 3
1350+ if startpos < 0:
1351+ chunklength += startpos
1352+ startpos = 0
1353+ chunk = str(sum_integers)[startpos : startpos + chunklength]
1354+ #print str(startpos)+' '+str(chunklength)+' '+ chunk
1355+ wordified = wordify(chunk, inc-1, language)
1356+ inc += 1
1357+ spacer = ''
1358+ if len(diginwords) > 0 :
1359+ spacer = ' '
1360+ diginwords = wordified + spacer + diginwords
1361+ return diginwords
1362+
1363+def wordify(chunk, chunknr, language):
1364+ #print 'chunk '+str(chunk)
1365+ #print 'cunknr '+str(chunknr)
1366+ words = u''
1367+
1368+ if language == 'lv_LV':
1369+ skaitli = [u'nulle', u'viens', u'divi', u'trīs', u'četri', u'pieci',
1370+ u'seši', u'septiņi', u'astoņi', u'deviņi']
1371+ skaitlix = [u'nulle', u'vien', u'div', u'trīs', u'četr', u'piec', u'seš',
1372+ u'septiņ', u'astoņ', u'deviņ']
1373+ skaitli_teens = [u'desmit', u'vienpadsmit', u'divpadsmit', u'trīspadsmit',
1374+ u'četrpadsmit', u'piecpadsmit', u'sešpadsmit',
1375+ u'septiņpadsmit', u'astoņpadsmit', u'deviņpadsmit']
1376+ daudzums = [u'simts', u' tūkstotis', u' miljons', u' miljards']
1377+ daudzumsx = [u' simti', u' tūkstoši', u' miljoni', u' miljardi']
1378+
1379+ elif language == 'en_US':
1380+ skaitli = [u'zero', u'one', u'two', u'three', u'four', u'five', u'six',
1381+ u'seven', u'eight', u'nine']
1382+ skaitlix = [u'zero', u'one', u'twen', u'thir', u'four', u'fif', u'six',
1383+ u'seven', u'eigh', u'nine']
1384+ skaitli_teens = [u'ten', u'eleven', u'twelve', u'thirteen', u'fourteen',
1385+ u'fifteen', u'sixteen', u'seventeen', u'eighteen', u'nineteen']
1386+ daudzums = [u' hundred', u' thousand', u' million', u' billion']
1387+ daudzumsx = daudzums
1388+
1389+ elif language == 'ru_RU':
1390+ skaitli = [u'ноль', u'один', u'два', u'три', u'четыре', u'пять', u'шесть',
1391+ u'семь', u'восемь', u'девять']
1392+ skaitlix = [u'', u'один', u'двa', u'три', u'четыре', u'пять', u'шесть',
1393+ u'семь', u'восемь', u'девять']
1394+ skaitli_teens = [u'десять', u'одиннадцать', u'двенадцать', u'тринадцать',
1395+ u'четырнадцать', u'пятнадцать', u'шестнадцать', u'семнадцать',
1396+ u'восемнадцать', u'девятнадцать']
1397+ daudzums = [u'стo', u' тысяча', u' миллион', u' миллиард']
1398+ daudzumsx = [u'сoт', u' тысяч', u' миллионов', u' миллиардов']
1399+
1400+ elif language == 'uk_UA' :
1401+ skaitli = [u'ноль', u'один', u'два', u'три', u'чотири', u'п\'ять', u'шість',
1402+ u'сім', u'вісім', u'дев\'ять']
1403+ skaitlix = [u'', u'один', u'двa', u'три', u'чотири', u'п\'ять', u'шість',
1404+ u'сім', u'вісім', u'дев\'ять']
1405+ skaitli_teens = [u'десять', u'одинадцять', u'дванадцять', u'тринадцять',
1406+ u'чотирнадцять', u'п\'ятнадцять', u'шістнадцять', u'сімнадцять',
1407+ u'вісімнадцять', u'дев\'ятнадцять']
1408+ daudzums = [u'стo', u' тисяча', u' мiллiон', u' мiллiард']
1409+ daudzumsx = [u'сoт', u' тисяч', u' мiллiонiв', u' мiллiардов']
1410+ digit1 = u''
1411+ digit2 = u''
1412+ digit3 = u''
1413+ chunklength = len(chunk)
1414+ # placing digits in right places
1415+ if chunklength == 1:
1416+ digit3 = chunk[0 : 1]
1417+ if chunklength == 2:
1418+ digit2 = chunk[0 : 1]
1419+ digit3 = chunk[1 : 2]
1420+ if chunklength == 3:
1421+ digit1 = chunk[0 : 1]
1422+ digit2 = chunk[1 : 2]
1423+ digit3 = chunk[-1]
1424+ # processing zero
1425+ if chunklength == 1 and digit3 == '0' :
1426+ return skaitli[0]
1427+ # processing hundreds
1428+ if chunklength == 3 :
1429+ if digit1 == '1' :
1430+ if language == 'lv_LV' or language == 'ru_RU' or language == 'uk_UA':
1431+ words += daudzums[0]
1432+ elif language == 'en_US' :
1433+ words += skaitli[int(digit1)] + daudzumsx[0]
1434+ else :
1435+ if language == 'lv_LV' :
1436+ if int(digit1) > 1 : words += skaitli[int(digit1)] + daudzumsx[0]
1437+ elif language == 'en_US' :
1438+ if int(digit1) > 1 : words += skaitli[int(digit1)] + daudzumsx[0]
1439+ elif language == 'ru_RU' :
1440+ if int(digit1) == 2 :
1441+ words += u'двести'
1442+ elif int(digit1) == 3 :
1443+ words += u'триста'
1444+ elif int(digit1) == 4 :
1445+ words += u'четыреста'
1446+ elif int(digit1) >= 5 :
1447+ words += skaitli[int(digit1)] + daudzumsx[0]
1448+ elif language == 'uk_UA' :
1449+ if int(digit1) == 2 :
1450+ words += u'двісті'
1451+ elif int(digit1) == 3 :
1452+ words += u'триста'
1453+ elif int(digit1) == 4 :
1454+ words += u'чотириста'
1455+ elif int(digit1) >= 5 :
1456+ words += skaitli[int(digit1)] + daudzumsx[0]
1457+ # processing tens
1458+ if chunklength > 1:
1459+ spacer = ''
1460+ if len(words) > 0 : spacer = ' '
1461+ if digit2 == '1':
1462+ if language == 'lv_LV' or language == 'en_US' or language == 'ru_RU' or language == 'uk_UA':
1463+ words += spacer + skaitli_teens[int(digit3)]
1464+ else:
1465+ if language == 'lv_LV':
1466+ if int(digit2) > 1 and int(digit2) > 0:
1467+ words += spacer + skaitlix[int(digit2)] + u'desmit'
1468+ elif language == 'en_US':
1469+ if int(digit2) > 1 and int(digit2) > 0:
1470+ words += spacer + skaitlix[int(digit2)] + u'ty'
1471+ elif language == 'ru_RU':
1472+ if int(digit2) > 1 and int(digit2) < 4:
1473+ words += spacer + skaitlix[int(digit2)] + u'дцать'
1474+ elif digit2 == '4':
1475+ words += spacer + u'сорок'
1476+ elif int(digit2) >= 5 and int(digit2) != 9:
1477+ words += spacer + skaitlix[int(digit2)] + u'десят'
1478+ elif digit2 == '9':
1479+ words += spacer + u'девяносто'
1480+ elif language == 'uk_UA' :
1481+ if int(digit2) > 1 and int(digit2) < 4:
1482+ words += spacer + skaitlix[int(digit2)] + u'дцять'
1483+ elif digit2 == '4':
1484+ words += spacer + u'сорок'
1485+ elif int(digit2) >= 5 and int(digit2) != 9:
1486+ words += spacer + skaitlix[int(digit2)] + u'десят'
1487+ elif digit2 == '9':
1488+ words += spacer + u'дев\'яносто'
1489+ # processing ones
1490+ if chunklength > 0 and digit2 != '1' :
1491+ spacer = ''
1492+ if len(words) > 0: spacer = u' '
1493+ if language == 'lv_LV' or language == 'en_US':
1494+ if int(digit3) > 0:
1495+ words += spacer + skaitli[int(digit3)]
1496+ elif language == 'ru_RU':
1497+ if chunknr == 1:
1498+ if int(digit3) == 1:
1499+ words += spacer + u'одна'
1500+ elif int(digit3) == 2:
1501+ words += spacer + u'две'
1502+ elif int(digit3) >= 3 and int(digit3) != 0:
1503+ words += spacer + skaitli[int(digit3)]
1504+ else:
1505+ if int(digit3) > 0: words += spacer + skaitli[int(digit3)]
1506+ elif language == 'uk_UA' :
1507+ if chunknr == 1 :
1508+ if int(digit3) == 1 : words += spacer + u'одна'
1509+ elif int(digit3) == 2 : words += spacer + u'дві'
1510+ elif int(digit3) >= 3 and int(digit3) != 0: words += spacer + skaitli[int(digit3)]
1511+ else:
1512+ if int(digit3) > 0 : words += spacer + skaitli[int(digit3)]
1513+ # end processing
1514+ if len(words) > 0 :
1515+
1516+ if digit3 == '1' and chunknr > 0:
1517+ return words + daudzums[chunknr]
1518+ elif digit3 != '1' and chunknr > 0:
1519+ if language == 'lv_LV' or language == 'en_US' :
1520+ return words + daudzumsx[chunknr]
1521+ elif language == 'ru_RU' :
1522+ if (int(digit3) == 2 or int(digit3) == 3 or int(digit3) == 4) and digit2 != '1' :
1523+ if chunknr == 1 :
1524+ return words + u' тысячи'
1525+ elif chunknr == 2 :
1526+ return words + u' миллионa'
1527+ elif chunknr == 3 :
1528+ return words + u' миллиардa'
1529+ else:
1530+ return words + daudzumsx[chunknr]
1531+ elif language == 'uk_UA' :
1532+ if (int(digit3) == 2 or int(digit3) == 3 or int(digit3) == 4) and digit2 != '1' :
1533+ if chunknr == 1 :
1534+ return words + u' тисячі'
1535+ elif chunknr == 2 :
1536+ return words + u' мілліонa'
1537+ elif chunknr == 3 :
1538+ return words + u' мілліардa'
1539+ else:
1540+ return words + daudzumsx[chunknr]
1541+ else:
1542+ return words
1543+ else:
1544+ return ''
1545+
1546+
1547+if __name__ == '__main__':
1548+ import doctest
1549+ doctest.testmod()
1550+
1551
1552=== added directory 'data'
1553=== added file 'data/report_aeroo_data.xml'
1554--- data/report_aeroo_data.xml 1970-01-01 00:00:00 +0000
1555+++ data/report_aeroo_data.xml 2012-07-05 12:25:24 +0000
1556@@ -0,0 +1,25 @@
1557+<?xml version="1.0"?>
1558+<openerp>
1559+ <data noupdate="1">
1560+
1561+ <record model="report.mimetypes" id="report_mimetypes_odt_odt" >
1562+ <field name="name">ODF Text Document (.odt)</field>
1563+ <field name="code">oo-odt</field>
1564+ <field name="compatible_types">oo-odt</field>
1565+ </record>
1566+
1567+ <record model="report.mimetypes" id="report_mimetypes_ods_ods" >
1568+ <field name="name">ODF Spreadsheet (.ods)</field>
1569+ <field name="code">oo-ods</field>
1570+ <field name="compatible_types">oo-ods</field>
1571+ </record>
1572+
1573+ <record model="report.mimetypes" id="report_mimetypes_raw" >
1574+ <field name="name">Generic</field>
1575+ <field name="code">genshi-raw</field>
1576+ <field name="compatible_types">genshi-raw</field>
1577+ </record>
1578+
1579+ </data>
1580+</openerp>
1581+
1582
1583=== added file 'domain_parser.py'
1584--- domain_parser.py 1970-01-01 00:00:00 +0000
1585+++ domain_parser.py 2012-07-05 12:25:24 +0000
1586@@ -0,0 +1,45 @@
1587+##############################################################################
1588+#
1589+# Copyright (c) 2009 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
1590+# General contacts <info@kndati.lv>
1591+#
1592+# WARNING: This program as such is intended to be used by professional
1593+# programmers who take the whole responsability of assessing all potential
1594+# consequences resulting from its eventual inadequacies and bugs
1595+# End users who are looking for a ready-to-use solution with commercial
1596+# garantees and support are strongly adviced to contract a Free Software
1597+# Service Company
1598+#
1599+# This program is Free Software; you can redistribute it and/or
1600+# modify it under the terms of the GNU General Public License
1601+# as published by the Free Software Foundation; either version 2
1602+# of the License, or (at your option) any later version.
1603+#
1604+# This program is distributed in the hope that it will be useful,
1605+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1606+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1607+# GNU General Public License for more details.
1608+#
1609+# You should have received a copy of the GNU General Public License
1610+# along with this program; if not, write to the Free Software
1611+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1612+#
1613+##############################################################################
1614+
1615+def domain2statement(domain):
1616+ statement=''
1617+ operator=False
1618+ for d in domain:
1619+ if not operator:
1620+ if type(d)==str:
1621+ if d=='|':
1622+ operator=' or'
1623+ continue
1624+ else:
1625+ operator=False
1626+ statement+=' o.'+str(d[0])+' '+(d[1]=='=' and '==' or d[1])+' '+(isinstance(d[2], str) and '\''+d[2]+'\'' or str(d[2]))
1627+ if d!=domain[-1]:
1628+ statement+=operator or ' and'
1629+ operator=False
1630+ return statement
1631+
1632
1633=== added file 'report_aeroo.py'
1634--- report_aeroo.py 1970-01-01 00:00:00 +0000
1635+++ report_aeroo.py 2012-07-05 12:25:24 +0000
1636@@ -0,0 +1,636 @@
1637+# -*- encoding: utf-8 -*-
1638+
1639+##############################################################################
1640+#
1641+# Copyright (c) 2009-2010 KN dati, SIA. (http://kndati.lv) All Rights Reserved.
1642+# General contacts <info@kndati.lv>
1643+# Copyright (C) 2009 Domsense s.r.l.
1644+#
1645+# WARNING: This program as such is intended to be used by professional
1646+# programmers who take the whole responsability of assessing all potential
1647+# consequences resulting from its eventual inadequacies and bugs
1648+# End users who are looking for a ready-to-use solution with commercial
1649+# garantees and support are strongly adviced to contract a Free Software
1650+# Service Company
1651+#
1652+# This program is Free Software; you can redistribute it and/or
1653+# modify it under the terms of the GNU General Public License
1654+# as published by the Free Software Foundation; either version 2
1655+# of the License, or (at your option) any later version.
1656+#
1657+# This program is distributed in the hope that it will be useful,
1658+# but WITHOUT ANY WARRANTY; without even the implied warranty of
1659+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1660+# GNU General Public License for more details.
1661+#
1662+# You should have received a copy of the GNU General Public License
1663+# along with this program; if not, write to the Free Software
1664+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
1665+#
1666+##############################################################################
1667+
1668+import os, sys, traceback
1669+import tempfile
1670+import report
1671+from report.report_sxw import *
1672+#import zipfile
1673+try:
1674+ from cStringIO import StringIO
1675+except ImportError:
1676+ from StringIO import StringIO
1677+from xml.dom import minidom
1678+import base64
1679+from osv import osv
1680+from tools.translate import _
1681+import time
1682+import re
1683+import copy
1684+
1685+from addons import load_information_from_description_file
1686+import release
1687+
1688+import aeroolib
1689+from aeroolib.plugins.opendocument import Template, OOSerializer
1690+from genshi.template import NewTextTemplate
1691+import pooler
1692+import netsvc
1693+logger = netsvc.Logger()
1694+
1695+from ExtraFunctions import ExtraFunctions
1696+
1697+class Counter(object):
1698+ def __init__(self, name, start=0, interval=1):
1699+ self.name = name
1700+ self._number = start
1701+ self._interval = interval
1702+
1703+ def next(self):
1704+ curr_number = self._number
1705+ self._number += self._interval
1706+ return curr_number
1707+
1708+ def get_inc(self):
1709+ return self._number
1710+
1711+ def prev(self):
1712+ return self._number-self._interval
1713+
1714+class Aeroo_report(report_sxw):
1715+
1716+ def logger(self, message, level=netsvc.LOG_DEBUG):
1717+ netsvc.Logger().notifyChannel('report_aeroo', level, message)
1718+
1719+ def __init__(self, cr, name, table, rml=False, parser=False, header=True, store=False):
1720+ super(Aeroo_report, self).__init__(name, table, rml, parser, header, store)
1721+ self.logger("registering %s (%s)" % (name, table), netsvc.LOG_INFO)
1722+ self.oo_subreports = []
1723+ self.epl_images = []
1724+ self.counters = {}
1725+
1726+ pool = pooler.get_pool(cr.dbname)
1727+ ir_obj = pool.get('ir.actions.report.xml')
1728+ report_xml_ids = ir_obj.search(cr, 1, [('report_name', '=', name[7:])])
1729+ if report_xml_ids:
1730+ report_xml = ir_obj.browse(cr, 1, report_xml_ids[0])
1731+
1732+ if report_xml.preload_mode == 'preload':
1733+ file_data = report_xml.report_sxw_content
1734+ if not file_data:
1735+ self.logger("template is not defined in %s (%s) !" % (name, table), netsvc.LOG_WARNING)
1736+ template_io = None
1737+ else:
1738+ template_io = StringIO()
1739+ template_io.write(base64.decodestring(file_data))
1740+ style_io=self.get_styles_file(cr, 1, report_xml)
1741+ if template_io:
1742+ self.serializer = OOSerializer(template_io, oo_styles=style_io)
1743+
1744+ ##### Counter functions #####
1745+ def _def_inc(self, name, start=0, interval=1):
1746+ self.counters[name] = Counter(name, start, interval)
1747+
1748+ def _get_inc(self, name):
1749+ return self.counters[name].get_inc()
1750+
1751+ def _prev(self, name):
1752+ return self.counters[name].prev()
1753+
1754+ def _next(self, name):
1755+ return self.counters[name].next()
1756+ #############################
1757+
1758+ def _epl_asimage(self, data):
1759+ from PIL import Image
1760+ from math import ceil
1761+ if not data:
1762+ return ''
1763+ img = Image.open(StringIO(base64.decodestring(data)))
1764+ if img.format!='BMP':
1765+ return ''
1766+ data = base64.decodestring(data)[62:]
1767+ line_len = int(ceil(img.size[0]/32.0)*4)
1768+ temp_data = ''
1769+ for n in range(img.size[1]):
1770+ curr_pos = n*line_len
1771+ temp_data = data[curr_pos:curr_pos+line_len][:int(img.size[0]/8)] + temp_data
1772+
1773+ new_data = ''
1774+ for d in temp_data:
1775+ new_data += chr(ord(d)^255)
1776+ self.epl_images.append(new_data)
1777+ return img.size
1778+
1779+ def _epl2_gw(self, start_x, start_y, data):
1780+ if not data:
1781+ return None
1782+ size_x, size_y = self._epl_asimage(data)
1783+ return 'GW'+str(start_x)+','+str(start_y)+','+str(int(size_x/8))+','+str(size_y)+',<binary_data>'
1784+
1785+ def _include_document(self, aeroo_ooo=False):
1786+ def include_document(data, silent=False):
1787+ if not aeroo_ooo:
1788+ return _("Error! Include document not available!")
1789+ import binascii, urllib2
1790+ dummy_fd, temp_file_name = tempfile.mkstemp(suffix='.odt', prefix='aeroo-report-')
1791+ temp_file = open(temp_file_name, 'wb')
1792+ if os.path.isfile(data):
1793+ fd = file(data, 'rb')
1794+ data = fd.read()
1795+ else:
1796+ error = False
1797+ try:
1798+ url_file = urllib2.urlopen(data)
1799+ data = url_file.read()
1800+ except urllib2.HTTPError:
1801+ os.unlink(temp_file_name)
1802+ error = _('HTTP Error 404! Not file found:')+' %s' % data
1803+ except urllib2.URLError, e:
1804+ os.unlink(temp_file_name)
1805+ error = _('Error!')+' %s' % e
1806+ except IOError, e:
1807+ os.unlink(temp_file_name)
1808+ error = _('Error!')+' %s' % e
1809+ except Exception, e:
1810+ try:
1811+ data = base64.decodestring(data)
1812+ except binascii.Error:
1813+ os.unlink(temp_file_name)
1814+ error = _('Error! Not file found:')+' %s' % data
1815+ if error:
1816+ if not silent:
1817+ return error
1818+ else:
1819+ return None
1820+ try:
1821+ temp_file.write(data)
1822+ finally:
1823+ temp_file.close()
1824+ self.oo_subreports.append(temp_file_name)
1825+ return "<insert_doc('%s')>" % temp_file_name
1826+ return include_document
1827+
1828+ def _subreport(self, cr, uid, output='odt', aeroo_ooo=False, context={}):
1829+ pool = pooler.get_pool(cr.dbname)
1830+ ir_obj = pool.get('ir.actions.report.xml')
1831+ #### for odt documents ####
1832+ def odt_subreport(name=None, obj=None):
1833+ if not aeroo_ooo:
1834+ return _("Error! Subreports not available!")
1835+ report_xml_ids = ir_obj.search(cr, uid, [('report_name', '=', name)], context=context)
1836+ if report_xml_ids:
1837+ report_xml = ir_obj.browse(cr, uid, report_xml_ids[0], context=context)
1838+ data = {'model': obj._table_name, 'id': obj.id, 'report_type': 'aeroo', 'in_format': 'oo-odt'}
1839+ report, output = netsvc.Service._services['report.%s' % name].create_aeroo_report(cr, uid, \
1840+ [obj.id], data, report_xml, context=context, output='odt') # change for OpenERP 6.0 - Service class usage
1841+
1842+ dummy_fd, temp_file_name = tempfile.mkstemp(suffix='.odt', prefix='aeroo-report-')
1843+ temp_file = open(temp_file_name, 'wb')
1844+ try:
1845+ temp_file.write(report)
1846+ finally:
1847+ temp_file.close()
1848+
1849+ self.oo_subreports.append(temp_file_name)
1850+
1851+ return "<insert_doc('%s')>" % temp_file_name
1852+ return None
1853+ #### for text documents ####
1854+ def raw_subreport(name=None, obj=None):
1855+ report_xml_ids = ir_obj.search(cr, uid, [('report_name', '=', name)], context=context)
1856+ if report_xml_ids:
1857+ report_xml = ir_obj.browse(cr, uid, report_xml_ids[0], context=context)
1858+ data = {'model': obj._table_name, 'id': obj.id, 'report_type': 'aeroo', 'in_format': 'genshi-raw'}
1859+ report, output = netsvc.Service._services['report.%s' % name].create_genshi_raw_report(cr, uid, \
1860+ [obj.id], data, report_xml, context=context, output=output) # change for OpenERP 6.0 - Service class usage
1861+ return report
1862+ return None
1863+
1864+ if output=='odt':
1865+ return odt_subreport
1866+ elif output=='raw':
1867+ return raw_subreport
1868+
1869+ def set_xml_data_fields(self, objects, parser):
1870+ xml_data_fields = parser.localcontext.get('xml_data_fields', False)
1871+ if xml_data_fields:
1872+ for field in xml_data_fields:
1873+ for o in objects:
1874+ if getattr(o, field):
1875+ xml_data = base64.decodestring(getattr(o, field))
1876+ xmldoc = minidom.parseString(xml_data)
1877+ setattr(o, field, xmldoc.firstChild)
1878+ return objects
1879+
1880+ def get_other_template(self, cr, uid, data, parser):
1881+ if hasattr(parser, 'get_template'):
1882+ pool = pooler.get_pool(cr.dbname)
1883+ record = pool.get(data['model']).browse(cr, uid, data['id'], {})
1884+ template = parser.get_template(cr, uid, record)
1885+ return template
1886+ else:
1887+ return False
1888+
1889+ def get_styles_file(self, cr, uid, report_xml, context=None):
1890+ pool = pooler.get_pool(cr.dbname)
1891+ style_io=None
1892+ if report_xml.styles_mode!='default':
1893+ if report_xml.styles_mode=='global':
1894+ company_id = pool.get('res.users')._get_company(cr, uid, context=context)
1895+ style_content = pool.get('res.company').browse(cr, uid, company_id, context=context).stylesheet_id
1896+ style_content = style_content and style_content.report_styles or False
1897+ elif report_xml.styles_mode=='specified':
1898+ style_content = report_xml.stylesheet_id
1899+ style_content = style_content and style_content.report_styles or False
1900+ if style_content:
1901+ style_io = StringIO()
1902+ style_io.write(base64.decodestring(style_content))
1903+ return style_io
1904+
1905+ def create_genshi_raw_report(self, cr, uid, ids, data, report_xml, context=None, output='raw'):
1906+ def preprocess(data):
1907+ self.epl_images.reverse()
1908+ while self.epl_images:
1909+ img = self.epl_images.pop()
1910+ data = data.replace('<binary_data>', img, 1)
1911+ return data.replace('\n', '\r\n')
1912+
1913+ if not context:
1914+ context={}
1915+ context = context.copy()
1916+ objects = self.getObjects(cr, uid, ids, context)
1917+ oo_parser = self.parser(cr, uid, self.name2, context=context)
1918+ oo_parser.objects = objects
1919+ self.set_xml_data_fields(objects, oo_parser) # Get/Set XML
1920+ file_data = self.get_other_template(cr, uid, data, oo_parser) or report_xml.report_sxw_content # Get other Tamplate
1921+ ################################################
1922+ if not file_data:
1923+ return False, output
1924+
1925+ oo_parser.localcontext['objects'] = objects
1926+ oo_parser.localcontext['data'] = data
1927+ oo_parser.localcontext['user_lang'] = context['lang']
1928+ if len(objects)>0:
1929+ oo_parser.localcontext['o'] = objects[0]
1930+ xfunc = ExtraFunctions(cr, uid, report_xml.id, oo_parser.localcontext)
1931+ oo_parser.localcontext.update(xfunc.functions)
1932+ oo_parser.localcontext['include_subreport'] = self._subreport(cr, uid, output='raw', aeroo_ooo=False, context=context)
1933+ oo_parser.localcontext['epl2_gw'] = self._epl2_gw
1934+
1935+ self.epl_images = []
1936+ basic = NewTextTemplate(source=file_data)
1937+ #try:
1938+ data = preprocess(basic.generate(**oo_parser.localcontext).render().decode('utf8').encode(report_xml.charset))
1939+ #except Exception, e:
1940+ # self.logger(str(e), netsvc.LOG_ERROR)
1941+ # return False, output
1942+
1943+ if report_xml.content_fname:
1944+ output = report_xml.content_fname
1945+ return data, output
1946+
1947+ def create_aeroo_report(self, cr, uid, ids, data, report_xml, context=None, output='odt'):
1948+ """ Returns an aeroo report generated with aeroolib
1949+ """
1950+ pool = pooler.get_pool(cr.dbname)
1951+ if not context:
1952+ context={}
1953+ context = context.copy()
1954+ if self.name=='report.printscreen.list':
1955+ context['model'] = data['model']
1956+ context['ids'] = ids
1957+
1958+ objects = not context.get('no_objects', False) and self.getObjects(cr, uid, ids, context) or []
1959+ oo_parser = self.parser(cr, uid, self.name2, context=context)
1960+
1961+ oo_parser.objects = objects
1962+ self.set_xml_data_fields(objects, oo_parser) # Get/Set XML
1963+
1964+ style_io=self.get_styles_file(cr, uid, report_xml, context)
1965+ if report_xml.tml_source in ('file', 'database'):
1966+ file_data = base64.decodestring(report_xml.report_sxw_content)
1967+ else:
1968+ file_data = self.get_other_template(cr, uid, data, oo_parser)
1969+ if not file_data and not report_xml.report_sxw_content:
1970+ return False, output
1971+ #elif file_data:
1972+ # template_io = StringIO()
1973+ # template_io.write(file_data or report_xml.report_sxw_content)
1974+ # basic = Template(source=template_io, styles=style_io)
1975+ else:
1976+ if report_xml.preload_mode == 'preload' and hasattr(self, 'serializer'):
1977+ serializer = copy.copy(self.serializer)
1978+ serializer.apply_style(style_io)
1979+ template_io = serializer.template
1980+ else:
1981+ template_io = StringIO()
1982+ template_io.write(file_data or base64.decodestring(report_xml.report_sxw_content) )
1983+ serializer = OOSerializer(template_io, oo_styles=style_io)
1984+ basic = Template(source=template_io, serializer=serializer)
1985+
1986+ #if not file_data:
1987+ # return False, output
1988+
1989+ #basic = Template(source=template_io, serializer=serializer)
1990+
1991+ oo_parser.localcontext['objects'] = objects
1992+ oo_parser.localcontext['data'] = data
1993+ oo_parser.localcontext['user_lang'] = context['lang']
1994+ if len(objects)==1:
1995+ oo_parser.localcontext['o'] = objects[0]
1996+ xfunc = ExtraFunctions(cr, uid, report_xml.id, oo_parser.localcontext)
1997+ oo_parser.localcontext.update(xfunc.functions)
1998+
1999+ ###### Detect report_aeroo_ooo module ######
2000+ aeroo_ooo = False
2001+ cr.execute("SELECT id, state FROM ir_module_module WHERE name='report_aeroo_ooo'")
2002+ helper_module = cr.dictfetchone()
2003+ if helper_module['state'] in ('installed', 'to upgrade'):
2004+ aeroo_ooo = True
2005+ ############################################
2006+
2007+ oo_parser.localcontext['include_subreport'] = self._subreport(cr, uid, output='odt', aeroo_ooo=aeroo_ooo, context=context)
2008+ oo_parser.localcontext['include_document'] = self._include_document(aeroo_ooo)
2009+
2010+ ####### Add counter functons to localcontext #######
2011+ oo_parser.localcontext.update({'def_inc':self._def_inc,
2012+ 'get_inc':self._get_inc,
2013+ 'prev':self._prev,
2014+ 'next':self._next})
2015+
2016+ user_name = pool.get('res.users').browse(cr, uid, uid, {}).name
2017+ model_id = pool.get('ir.model').search(cr, uid, [('model','=',data['model'])])[0]
2018+ model_name = pool.get('ir.model').browse(cr, uid, model_id).name
2019+
2020+ #basic = Template(source=None, filepath=odt_path)
2021+
2022+ basic.Serializer.add_title(model_name)
2023+ basic.Serializer.add_creation_user(user_name)
2024+ version = load_information_from_description_file('report_aeroo')['version']
2025+ basic.Serializer.add_generator_info('Aeroo Lib/%s Aeroo Reports/%s' % (aeroolib.__version__, version))
2026+ basic.Serializer.add_custom_property('Aeroo Reports %s' % version, 'Generator')
2027+ basic.Serializer.add_custom_property('OpenERP %s' % release.version, 'Software')
2028+ basic.Serializer.add_custom_property('http://www.alistek.com/', 'URL')
2029+ basic.Serializer.add_creation_date(time.strftime('%Y-%m-%dT%H:%M:%S'))
2030+
2031+ try:
2032+ data = basic.generate(**oo_parser.localcontext).render().getvalue()
2033+ except Exception, e:
2034+ tb_s = reduce(lambda x, y: x+y, traceback.format_exception(sys.exc_type, sys.exc_value, sys.exc_traceback))
2035+ self.logger(tb_s, netsvc.LOG_ERROR)
2036+ for sub_report in self.oo_subreports:
2037+ os.unlink(sub_report)
2038+ raise Exception(_("Aeroo Reports: Error while generating the report."), e, str(e), _("For more reference inspect error logs."))
2039+ #return False, output
2040+
2041+ ######### OpenOffice extras #########
2042+ DC = netsvc.Service._services.get('openoffice')
2043+ if (output!=report_xml.in_format[3:] or self.oo_subreports):
2044+ if aeroo_ooo and DC:
2045+ try:
2046+ DC.putDocument(data)
2047+ if self.oo_subreports:
2048+ DC.insertSubreports(self.oo_subreports)
2049+ self.oo_subreports = []
2050+ data = DC.saveByStream(report_xml.out_format.filter_name)
2051+ DC.closeDocument()
2052+ #del DC
2053+ except Exception, e:
2054+ self.logger(str(e), netsvc.LOG_ERROR)
2055+ output=report_xml.in_format[3:]
2056+ self.oo_subreports = []
2057+ else:
2058+ output=report_xml.in_format[3:]
2059+ elif output in ('pdf', 'doc', 'xls'):
2060+ output=report_xml.in_format[3:]
2061+ #####################################
2062+
2063+ if report_xml.content_fname:
2064+ output = report_xml.content_fname
2065+ return data, output
2066+
2067+ # override needed to keep the attachments' storing procedure
2068+ def create_single_pdf(self, cr, uid, ids, data, report_xml, context=None):
2069+ if not context:
2070+ context={}
2071+ if report_xml.report_type == 'aeroo':
2072+ if report_xml.out_format.code.startswith('oo-'):
2073+ output = report_xml.out_format.code[3:]
2074+ return self.create_aeroo_report(cr, uid, ids, data, report_xml, context=context, output=output)
2075+ elif report_xml.out_format.code =='genshi-raw':
2076+ return self.create_genshi_raw_report(cr, uid, ids, data, report_xml, context=context, output='raw')
2077+ logo = None
2078+ context = context.copy()
2079+ title = report_xml.name
2080+ rml = report_xml.report_rml_content
2081+ oo_parser = self.parser(cr, uid, self.name2, context=context)
2082+ objs = self.getObjects(cr, uid, ids, context)
2083+ oo_parser.set_context(objs, data, ids, report_xml.report_type)
2084+ processed_rml = self.preprocess_rml(etree.XML(rml),report_xml.report_type)
2085+ if report_xml.header:
2086+ oo_parser._add_header(processed_rml)
2087+ if oo_parser.logo:
2088+ logo = base64.decodestring(oo_parser.logo)
2089+ create_doc = self.generators[report_xml.report_type]
2090+ pdf = create_doc(etree.tostring(processed_rml),oo_parser.localcontext,logo,title.encode('utf8'))
2091+ return (pdf, report_xml.report_type)
2092+
2093+ def create_source_odt(self, cr, uid, ids, data, report_xml, context=None):
2094+ if not context:
2095+ context={}
2096+ pool = pooler.get_pool(cr.dbname)
2097+ results = []
2098+ attach = report_xml.attachment
2099+ if attach:
2100+ objs = self.getObjects(cr, uid, ids, context)
2101+ for obj in objs:
2102+ aname = eval(attach, {'object':obj, 'time':time})
2103+ result = False
2104+ if report_xml.attachment_use and aname and context.get('attachment_use', True):
2105+ aids = pool.get('ir.attachment').search(cr, uid, [('datas_fname','=',aname+'.odt'),('res_model','=',self.table),('res_id','=',obj.id)])
2106+ if aids:
2107+ brow_rec = pool.get('ir.attachment').browse(cr, uid, aids[0])
2108+ if not brow_rec.datas:
2109+ continue
2110+ d = base64.decodestring(brow_rec.datas)
2111+ results.append((d,'odt'))
2112+ continue
2113+ result = self.create_single_pdf(cr, uid, [obj.id], data, report_xml, context)
2114+ try:
2115+ if aname:
2116+ name = aname+'.'+result[1]
2117+ pool.get('ir.attachment').create(cr, uid, {
2118+ 'name': aname,
2119+ 'datas': base64.encodestring(result[0]),
2120+ 'datas_fname': name,
2121+ 'res_model': self.table,
2122+ 'res_id': obj.id,
2123+ }, context=context
2124+ )
2125+ cr.commit()
2126+ except Exception,e:
2127+ self.logger(str(e), netsvc.LOG_ERROR)
2128+ results.append(result)
2129+
2130+ return results and len(results)==1 and results[0] or self.create_single_pdf(cr, uid, ids, data, report_xml, context)
2131+
2132+ # override needed to intercept the call to the proper 'create' method
2133+ def create(self, cr, uid, ids, data, context=None):
2134+ pool = pooler.get_pool(cr.dbname)
2135+ ir_obj = pool.get('ir.actions.report.xml')
2136+ report_xml_ids = ir_obj.search(cr, uid,
2137+ [('report_name', '=', self.name[7:])], context=context)
2138+ if report_xml_ids:
2139+ report_xml = ir_obj.browse(cr, uid, report_xml_ids[0], context=context)
2140+ report_xml.report_rml = None
2141+ report_xml.report_rml_content = None
2142+ report_xml.report_sxw_content_data = None
2143+ report_rml.report_sxw_content = None
2144+ report_rml.report_sxw = None
2145+ else:
2146+ title = ''
2147+ rml = tools.file_open(self.tmpl, subdir=None).read()
2148+ report_type= data.get('report_type', 'pdf')
2149+ class a(object):
2150+ def __init__(self, *args, **argv):
2151+ for key,arg in argv.items():
2152+ setattr(self, key, arg)
2153+ report_xml = a(title=title, report_type=report_type, report_rml_content=rml, name=title, attachment=False, header=self.header)
2154+
2155+ report_type = report_xml.report_type
2156+ if report_type in ['sxw','odt']:
2157+ fnct = self.create_source_odt
2158+ elif report_type in ['pdf','raw','txt','html']:
2159+ fnct = self.create_source_pdf
2160+ elif report_type=='html2html':
2161+ fnct = self.create_source_html2html
2162+ elif report_type=='mako2html':
2163+ fnct = self.create_source_mako2html
2164+ elif report_type=='aeroo':
2165+ if report_xml.out_format.code in ['oo-pdf']:
2166+ fnct = self.create_source_pdf
2167+ elif report_xml.out_format.code in ['oo-odt','oo-ods','oo-doc','oo-xls','genshi-raw']:
2168+ fnct = self.create_source_odt
2169+ else:
2170+ return super(Aeroo_report, self).create(cr, uid, ids, data, context)
2171+ else:
2172+ raise 'Unknown Report Type'
2173+ return fnct(cr, uid, ids, data, report_xml, context)
2174+
2175+class ReportTypeException(Exception):
2176+ def __init__(self, value):
2177+ self.parameter = value
2178+ def __str__(self):
2179+ return repr(self.parameter)
2180+
2181+#########################################################################
2182+
2183+#import imp, sys
2184+#from tools.config import config
2185+
2186+#def load_from_file(path, dbname, key):
2187+# class_inst = None
2188+# expected_class = 'Parser'
2189+
2190+# try:
2191+# if path.find(config['addons_path'])==-1:
2192+# filepath=config['addons_path']+os.path.sep+path
2193+# filepath = os.path.normpath(filepath)
2194+# if not os.path.lexists(filepath):
2195+# filepath = os.path.normpath(config['root_path']+os.path.sep+path)
2196+# sys.path.append(os.path.dirname(filepath))
2197+# mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
2198+# mod_name = '%s_%s_%s' % (dbname,mod_name,key)
2199+
2200+# if file_ext.lower() == '.py':
2201+# py_mod = imp.load_source(mod_name, filepath)
2202+
2203+# elif file_ext.lower() == '.pyc':
2204+# py_mod = imp.load_compiled(mod_name, filepath)
2205+
2206+# if expected_class in dir(py_mod):
2207+# class_inst = py_mod.Parser
2208+# return class_inst
2209+# except Exception, e:
2210+# return None
2211+
2212+#def load_from_source(source):
2213+# expected_class = 'Parser'
2214+# context = {'Parser':None}
2215+# try:
2216+# exec source in context
2217+# return context['Parser']
2218+# except Exception, e:
2219+# return None
2220+
2221+#def delete_report_service(name):
2222+# name = 'report.%s' % name
2223+# if netsvc.Service.exists( name ): # change for OpenERP 6.0 - Service class usage
2224+# netsvc.Service.remove( name ) # change for OpenERP 6.0 - Service class usage
2225+
2226+#def register_report(cr, name, model, tmpl_path, parser):
2227+# name = 'report.%s' % name
2228+# if netsvc.Service.exists( name ): # change for OpenERP 6.0 - Service class usage
2229+# netsvc.Service.remove( name ) # change for OpenERP 6.0 - Service class usage
2230+# Aeroo_report(cr, name, model, tmpl_path, parser=parser)
2231+
2232+#old_register_all = report.interface.register_all
2233+#def new_register_all(db):
2234+# value = old_register_all(db)
2235+
2236+# cr = db.cursor()
2237+
2238+ ########### Run OpenOffice service ###########
2239+# try:
2240+# from report_aeroo_ooo.report import OpenOffice_service
2241+# except Exception, e:
2242+# OpenOffice_service = False
2243+
2244+# if OpenOffice_service:
2245+# cr.execute("SELECT id, state FROM ir_module_module WHERE name='report_aeroo_ooo'")
2246+# helper_module = cr.dictfetchone()
2247+# helper_installed = helper_module['state']=='installed'
2248+
2249+# if OpenOffice_service and helper_installed:
2250+# cr.execute("SELECT host, port FROM oo_config")
2251+# host, port = cr.fetchone()
2252+# try:
2253+# OpenOffice_service(cr, host, port)
2254+# netsvc.Logger().notifyChannel('report_aeroo', netsvc.LOG_INFO, "OpenOffice connection successfully established")
2255+# except DocumentConversionException, e:
2256+# netsvc.Logger().notifyChannel('report_aeroo', netsvc.LOG_WARNING, e)
2257+ ##############################################
2258+
2259+# cr.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'aeroo' ORDER BY id") # change for OpenERP 6.0
2260+# records = cr.dictfetchall()
2261+# for record in records:
2262+# parser=rml_parse
2263+# if record['parser_state']=='loc' and record['parser_loc']:
2264+# parser=load_from_file(record['parser_loc'], db.dbname, record['id']) or parser
2265+# elif record['parser_state']=='def' and record['parser_def']:
2266+# parser=load_from_source("from report import report_sxw\n"+record['parser_def']) or parser
2267+# register_report(cr, record['report_name'], record['model'], record['report_rml'], parser)
2268+# cr.close()
2269+# return value
2270+
2271+#report.interface.register_all = new_register_all
2272+
2273
2274=== added file 'report_view.xml'
2275--- report_view.xml 1970-01-01 00:00:00 +0000
2276+++ report_view.xml 2012-07-05 12:25:24 +0000
2277@@ -0,0 +1,224 @@
2278+<?xml version="1.0" encoding="utf-8"?>
2279+<openerp>
2280+ <data>
2281+
2282+ <record model="ir.ui.view" id="act_report_xml_view1">
2283+ <field name="name">ir.actions.report.xml.aeroo.form</field>
2284+ <field name="model">ir.actions.report.xml</field>
2285+ <field name="priority">14</field>
2286+ <field name="type">form</field>
2287+ <field name="arch" type="xml">
2288+ <form string="Aeroo Report">
2289+ <group col="6" colspan="4">
2290+ <field name="name" select="1"/>
2291+ <field name="model" select="1"/>
2292+ <field name="type" select="1" invisible="1"/>
2293+
2294+ <field name="report_name" select="1"/>
2295+ <field name="usage"/>
2296+ <field name="report_type" invisible="1"/>
2297+ </group>
2298+ <group col="6" colspan="4">
2299+ <field name="in_format" required="1" on_change="change_input_format(in_format)"/>
2300+ <field name="out_format" required="1" domain="[('compatible_types','=',in_format)]"/>
2301+ <field name="content_fname"/>
2302+ </group>
2303+
2304+ <notebook colspan="4">
2305+ <page string="Other Configuration">
2306+ <separator string="Template" colspan="4"/>
2307+ <group colspan="4" col="8">
2308+ <field name="tml_source" colspan="2" required="1"/>
2309+ <group colspan="6">
2310+ <field name="report_sxw_content_data" string="Template Content" attrs="{'invisible': [('tml_source','&lt;&gt;','database')],'required': [('tml_source','=','database')]}"/>
2311+ <field name="report_rml" string="Template path" attrs="{'invisible': [('tml_source','&lt;&gt;','file')],'required': [('tml_source','=','file')]}"/>
2312+ </group>
2313+ </group>
2314+ <group attrs="{'invisible': [('in_format','=','genshi-raw')]}" colspan="4">
2315+ <separator string="Stylesheet" colspan="4"/>
2316+ <group colspan="4" col="8">
2317+ <field name="styles_mode" colspan="2"/>
2318+ <group colspan="6">
2319+ <field name="stylesheet_id" attrs="{'invisible': [('styles_mode','&lt;&gt;','specified')]}"/>
2320+ </group>
2321+ </group>
2322+ </group>
2323+ <group attrs="{'invisible': [('in_format','&lt;&gt;','genshi-raw')]}" colspan="4" col="8">
2324+ <field name="charset" colspan="2"/>
2325+ <separator colspan="2"/>
2326+ </group>
2327+ <group col="2" colspan="2">
2328+ <separator string="Attachments" colspan="2"/>
2329+ <group colspan="2">
2330+ <group colspan="2">
2331+ <field name="attachment"/>
2332+ </group>
2333+ </group>
2334+ <field name="attachment_use" colspan="2"/>
2335+ </group>
2336+ <group col="2" colspan="2">
2337+ <separator string="Miscellaneous" colspan="2"/>
2338+ <field name="preload_mode" attrs="{'invisible': [('in_format','=','genshi-raw'),('tml_source','=','parser')]}"/>
2339+ <field name="multi" colspan="2"/>
2340+ </group>
2341+ </page>
2342+ <page string="Parser">
2343+ <group colspan="2">
2344+ <field name="parser_state"/>
2345+ </group>
2346+ <group attrs="{'invisible': [('parser_state','&lt;&gt;','def')]}" colspan="4" expand="1">
2347+ <separator string="Parser Definition" colspan="4"/>
2348+ <field name="parser_def" nolabel="1"/>
2349+ </group>
2350+ <field name="parser_loc" attrs="{'invisible': [('parser_state','&lt;&gt;','loc')],'required': [('parser_state','=','loc')]}"/>
2351+ </page>
2352+ <page string="Security">
2353+ <separator string="Groups" colspan="4"/>
2354+ <field colspan="4" name="groups_id" nolabel="1"/>
2355+ </page>
2356+ </notebook>
2357+
2358+ </form>
2359+ </field>
2360+ </record>
2361+
2362+ <record id="act_aeroo_report_xml_view_tree" model="ir.ui.view">
2363+ <field name="name">ir.actions.report.xml.tree</field>
2364+ <field name="model">ir.actions.report.xml</field>
2365+ <field name="type">tree</field>
2366+ <field name="arch" type="xml">
2367+ <tree string="Report xml">
2368+ <field name="name"/>
2369+ <field name="model"/>
2370+ <field name="report_name"/>
2371+ <field name="in_format"/>
2372+ <field name="out_format"/>
2373+ <field name="tml_source"/>
2374+ </tree>
2375+ </field>
2376+ </record>
2377+
2378+ <record id="act_aeroo_report_xml_search_view" model="ir.ui.view">
2379+ <field name="name">ir.actions.report.xml.search</field>
2380+ <field name="model">ir.actions.report.xml</field>
2381+ <field name="type">search</field>
2382+ <field name="arch" type="xml">
2383+ <search string="Report xml">
2384+ <group col="10" colspan="4">
2385+ <field name="name"/>
2386+ <field name="model"/>
2387+ <field name="type"/>
2388+ <field name="in_format"/>
2389+ <field name="out_format"/>
2390+ </group>
2391+ <newline/>
2392+ <group expand="0" string="Group By" colspan="4">
2393+ <filter string="Template Mime-type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'in_format'}"/>
2394+ <filter string="Output Mime-type" icon="terp-stock_symbol-selection" domain="[]" context="{'group_by':'out_format'}"/>
2395+ <separator orientation="vertical"/>
2396+ <filter string="Template Source" icon="gtk-copy" domain="[]" context="{'group_by':'tml_source'}"/>
2397+ </group>
2398+ </search>
2399+ </field>
2400+ </record>
2401+
2402+ <record id="view_company_form1" model="ir.ui.view">
2403+ <field name="name">res.company.form</field>
2404+ <field name="model">res.company</field>
2405+ <field name="type">form</field>
2406+ <field name="inherit_id" ref="base.view_company_form"/>
2407+ <field name="arch" type="xml">
2408+ <field name="rml_footer2" position="after">
2409+ <field name="stylesheet_id"/>
2410+ </field>
2411+ </field>
2412+ </record>
2413+
2414+ <record id="view_report_stylesheets_form" model="ir.ui.view">
2415+ <field name="name">report.stylesheets.form</field>
2416+ <field name="model">report.stylesheets</field>
2417+ <field name="type">form</field>
2418+ <field name="arch" type="xml">
2419+ <form string="Report Stylesheet">
2420+ <field name="name" select="1" colspan="4"/>
2421+ <field name="report_styles"/>
2422+ </form>
2423+ </field>
2424+ </record>
2425+
2426+ <record id="view_report_stylesheets_tree" model="ir.ui.view">
2427+ <field name="name">report.stylesheets.tree</field>
2428+ <field name="model">report.stylesheets</field>
2429+ <field name="type">tree</field>
2430+ <field name="arch" type="xml">
2431+ <tree string="Report Stylesheets">
2432+ <field name="name"/>
2433+ </tree>
2434+ </field>
2435+ </record>
2436+
2437+ <record model="ir.actions.act_window" id="action_report_stylesheets">
2438+ <field name="name">Report Stylesheets</field>
2439+ <field name="res_model">report.stylesheets</field>
2440+ <field name="view_type">form</field>
2441+ <field name="view_mode">tree,form</field>
2442+ </record>
2443+
2444+ <act_window name="Translations"
2445+ domain="[('type', '=', 'report'),('res_id', '=', active_id)]"
2446+ view_type="form"
2447+ res_model="ir.translation"
2448+ src_model="ir.actions.report.xml"
2449+ id="act_translations"/>
2450+
2451+ <!-- For the original views -->
2452+ <record model="ir.actions.act_window.view" id="act_report_xml_tree_view">
2453+ <field name="sequence" eval="1"/>
2454+ <field name="view_mode">tree</field>
2455+ <field name="view_id" ref="base.act_report_xml_view_tree"/>
2456+ <field name="act_window_id" ref="base.ir_action_report_xml"/>
2457+ </record>
2458+
2459+ <record model="ir.actions.act_window.view" id="act_report_xml_form_view">
2460+ <field name="sequence" eval="1"/>
2461+ <field name="view_mode">form</field>
2462+ <field name="view_id" ref="base.act_report_xml_view"/>
2463+ <field name="act_window_id" ref="base.ir_action_report_xml"/>
2464+ </record>
2465+ <!--========================-->
2466+
2467+ <wizard string="Add Print Button" model="ir.actions.report.xml" name="aeroo.report_actions" menu="True" id="wizard_oo_report_actions" />
2468+ <wizard string="Remove Print Button" model="ir.actions.report.xml" name="aeroo.report_actions_remove" menu="True" id="wizard_oo_report_actions_remove" />
2469+
2470+ <menuitem name="Aeroo Reports" id="menu_ir_action_aeroo_reports_xml" parent="base.menu_custom"/>
2471+
2472+ <record id="action_aeroo_report_xml_tree" model="ir.actions.act_window">
2473+ <field name="name">Reports</field>
2474+ <field name="type">ir.actions.act_window</field>
2475+ <field name="res_model">ir.actions.report.xml</field>
2476+ <field name="view_type">form</field>
2477+ <field name="view_mode">tree,form</field>
2478+ <field name="domain">[('report_type','=','aeroo')]</field>
2479+ <field name="view_id" ref="act_aeroo_report_xml_view_tree"/>
2480+ <field name="search_view_id" ref="act_aeroo_report_xml_search_view"/>
2481+ </record>
2482+
2483+ <record model="ir.actions.act_window.view" id="act_aeroo_report_xml_tree_view">
2484+ <field name="sequence" eval="1"/>
2485+ <field name="view_mode">tree</field>
2486+ <field name="view_id" ref="act_aeroo_report_xml_view_tree"/>
2487+ <field name="act_window_id" ref="action_aeroo_report_xml_tree"/>
2488+ </record>
2489+
2490+ <record model="ir.actions.act_window.view" id="act_aeroo_report_xml_form_view">
2491+ <field name="sequence" eval="1"/>
2492+ <field name="view_mode">form</field>
2493+ <field name="view_id" ref="act_report_xml_view1"/>
2494+ <field name="act_window_id" ref="action_aeroo_report_xml_tree"/>
2495+ </record>
2496+
2497+ <menuitem action="action_aeroo_report_xml_tree" id="menu_ir_action_aeroo_report_xml" parent="menu_ir_action_aeroo_reports_xml"/>
2498+ <menuitem action="action_report_stylesheets" parent="menu_ir_action_aeroo_reports_xml" id="menu_report_stylesheets"/>
2499+
2500+ </data>
2501+</openerp>
2502
2503=== added file 'report_xml.py'
2504--- report_xml.py 1970-01-01 00:00:00 +0000
2505+++ report_xml.py 2012-07-05 12:25:24 +0000
2506@@ -0,0 +1,365 @@
2507+##############################################################################
2508+#
2509+# Copyright (c) 2009-2010 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
2510+# General contacts <info@kndati.lv>
2511+#
2512+# WARNING: This program as such is intended to be used by professional
2513+# programmers who take the whole responsability of assessing all potential
2514+# consequences resulting from its eventual inadequacies and bugs
2515+# End users who are looking for a ready-to-use solution with commercial
2516+# garantees and support are strongly adviced to contract a Free Software
2517+# Service Company
2518+#
2519+# This program is Free Software; you can redistribute it and/or
2520+# modify it under the terms of the GNU General Public License
2521+# as published by the Free Software Foundation; either version 2
2522+# of the License, or (at your option) any later version.
2523+#
2524+# This program is distributed in the hope that it will be useful,
2525+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2526+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2527+# GNU General Public License for more details.
2528+#
2529+# You should have received a copy of the GNU General Public License
2530+# along with this program; if not, write to the Free Software
2531+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2532+#
2533+##############################################################################
2534+
2535+from osv import osv,fields
2536+import netsvc
2537+from report_aeroo import Aeroo_report
2538+from report.report_sxw import rml_parse
2539+import base64, binascii
2540+import tools
2541+import encodings
2542+from tools.translate import _
2543+
2544+import imp, sys, os
2545+from tools.config import config
2546+
2547+class report_stylesheets(osv.osv):
2548+ '''
2549+ Open ERP Model
2550+ '''
2551+ _name = 'report.stylesheets'
2552+ _description = 'Report Stylesheets'
2553+
2554+ _columns = {
2555+ 'name':fields.char('Name', size=64, required=True),
2556+ 'report_styles' : fields.binary('Template Stylesheet', help='OpenOffice.org stylesheet (.odt)'),
2557+
2558+ }
2559+
2560+report_stylesheets()
2561+
2562+class res_company(osv.osv):
2563+ _name = 'res.company'
2564+ _inherit = 'res.company'
2565+
2566+ _columns = {
2567+ #'report_styles' : fields.binary('Report Styles', help='OpenOffice stylesheet (.odt)'),
2568+ 'stylesheet_id':fields.many2one('report.stylesheets', 'Aeroo Global Stylesheet'),
2569+ }
2570+
2571+res_company()
2572+
2573+class report_mimetypes(osv.osv):
2574+ '''
2575+ Aeroo Report Mime-Type
2576+ '''
2577+ _name = 'report.mimetypes'
2578+ _description = 'Report Mime-Types'
2579+
2580+ _columns = {
2581+ 'name':fields.char('Name', size=64, required=True, readonly=True),
2582+ 'code':fields.char('Code', size=16, required=True, readonly=True),
2583+ 'compatible_types':fields.char('Compatible Mime-Types', size=128, readonly=True),
2584+ 'filter_name':fields.char('Filter Name', size=128, readonly=True),
2585+
2586+ }
2587+
2588+report_mimetypes()
2589+
2590+class report_xml(osv.osv):
2591+ _name = 'ir.actions.report.xml'
2592+ _inherit = 'ir.actions.report.xml'
2593+
2594+ def load_from_file(self, path, dbname, key):
2595+ class_inst = None
2596+ expected_class = 'Parser'
2597+
2598+ try:
2599+ if path.find(config['addons_path'])==-1:
2600+ filepath=config['addons_path']+os.path.sep+path
2601+ filepath = os.path.normpath(filepath)
2602+ if not os.path.lexists(filepath):
2603+ filepath = os.path.normpath(config['root_path']+os.path.sep+path)
2604+ sys.path.append(os.path.dirname(filepath))
2605+ mod_name,file_ext = os.path.splitext(os.path.split(filepath)[-1])
2606+ mod_name = '%s_%s_%s' % (dbname,mod_name,key)
2607+
2608+ if file_ext.lower() == '.py':
2609+ py_mod = imp.load_source(mod_name, filepath)
2610+
2611+ elif file_ext.lower() == '.pyc':
2612+ py_mod = imp.load_compiled(mod_name, filepath)
2613+
2614+ if expected_class in dir(py_mod):
2615+ class_inst = py_mod.Parser
2616+ return class_inst
2617+ except Exception, e:
2618+ return None
2619+
2620+ def load_from_source(self, source):
2621+ expected_class = 'Parser'
2622+ context = {'Parser':None}
2623+ try:
2624+ exec source in context
2625+ return context['Parser']
2626+ except Exception, e:
2627+ return None
2628+
2629+ def delete_report_service(self, name):
2630+ name = 'report.%s' % name
2631+ if netsvc.Service.exists( name ): # change for OpenERP 6.0 - Service class usage
2632+ netsvc.Service.remove( name ) # change for OpenERP 6.0 - Service class usage
2633+
2634+ def register_report(self, cr, name, model, tmpl_path, parser):
2635+ name = 'report.%s' % name
2636+ if netsvc.Service.exists( name ): # change for OpenERP 6.0 - Service class usage
2637+ netsvc.Service.remove( name ) # change for OpenERP 6.0 - Service class usage
2638+ Aeroo_report(cr, name, model, tmpl_path, parser=parser)
2639+
2640+ def register_all(self, cr):
2641+ ########### Run OpenOffice service ###########
2642+ try:
2643+ from report_aeroo_ooo.report import OpenOffice_service
2644+ except Exception, e:
2645+ OpenOffice_service = False
2646+
2647+ if OpenOffice_service:
2648+ cr.execute("SELECT id, state FROM ir_module_module WHERE name='report_aeroo_ooo'")
2649+ helper_module = cr.dictfetchone()
2650+ helper_installed = helper_module['state']=='installed'
2651+
2652+ if OpenOffice_service and helper_installed:
2653+ cr.execute("SELECT host, port FROM oo_config")
2654+ host, port = cr.fetchone()
2655+ try:
2656+ OpenOffice_service(cr, host, port)
2657+ netsvc.Logger().notifyChannel('report_aeroo', netsvc.LOG_INFO, "OpenOffice.org connection successfully established")
2658+ except Exception, e:
2659+ netsvc.Logger().notifyChannel('report_aeroo', netsvc.LOG_WARNING, e)
2660+ ##############################################
2661+
2662+ cr.execute("SELECT * FROM ir_act_report_xml WHERE report_type = 'aeroo' ORDER BY id") # change for OpenERP 6.0
2663+ records = cr.dictfetchall()
2664+ for record in records:
2665+ parser=rml_parse
2666+ if record['parser_state']=='loc' and record['parser_loc']:
2667+ parser=self.load_from_file(record['parser_loc'], cr.dbname, record['id']) or parser
2668+ elif record['parser_state']=='def' and record['parser_def']:
2669+ parser=self.load_from_source("from report import report_sxw\n"+record['parser_def']) or parser
2670+ self.register_report(cr, record['report_name'], record['model'], record['report_rml'], parser)
2671+
2672+
2673+ def _report_content(self, cursor, user, ids, name, arg, context=None):
2674+ res = {}
2675+ for report in self.browse(cursor, user, ids, context=context):
2676+ data = report[name + '_data']# and base64.decodestring(report[name + '_data'])
2677+ if not data and report[name[:-8]]:
2678+ try:
2679+ fp = tools.file_open(report[name[:-8]], mode='rb')
2680+ data = base64.encodestring(fp.read())
2681+ except:
2682+ data = ''
2683+ res[report.id] = data
2684+ return res
2685+
2686+ def _get_encodings(self, cursor, user, context={}):
2687+ l = list(set(encodings._aliases.values()))
2688+ l.sort()
2689+ return zip(l, l)
2690+
2691+ def _report_content_inv(self, cursor, user, id, name, value, arg, context=None):
2692+ if value:
2693+ self.write(cursor, user, id, {name+'_data': value}, context=context)
2694+
2695+ def change_input_format(self, cr, uid, ids, in_format):
2696+ out_format = self.pool.get('report.mimetypes').search(cr, uid, [('code','=',in_format)])
2697+ return {
2698+ 'value':{'out_format': out_format and out_format[0] or False}
2699+ }
2700+
2701+ def _get_in_mimetypes(self, cr, uid, context={}):
2702+ obj = self.pool.get('report.mimetypes')
2703+ ids = obj.search(cr, uid, [('filter_name','=',False)], context=context)
2704+ res = obj.read(cr, uid, ids, ['code', 'name'], context)
2705+ return [(r['code'], r['name']) for r in res] + [('','')]
2706+
2707+ _columns = {
2708+ 'charset':fields.selection(_get_encodings, string='Charset', required=True),
2709+ 'content_fname': fields.char('Override Extension',size=64, help='Here you can override output file extension'),
2710+ 'styles_mode': fields.selection([
2711+ ('default','Not used'),
2712+ ('global', 'Global'),
2713+ ('specified', 'Specified'),
2714+ ], string='Stylesheet'),
2715+ #'report_styles' : fields.binary('Template Styles', help='OpenOffice stylesheet (.odt)'),
2716+ 'stylesheet_id':fields.many2one('report.stylesheets', 'Template Stylesheet'),
2717+ 'preload_mode':fields.selection([
2718+ ('static',_('Static')),
2719+ ('preload',_('Preload')),
2720+ ],'Preload Mode'),
2721+ 'tml_source':fields.selection([
2722+ ('database','Database'),
2723+ ('file','File'),
2724+ ('parser','Parser'),
2725+ ],'Template source', select=True),
2726+ 'parser_def': fields.text('Parser Definition'),
2727+ 'parser_loc':fields.char('Parser location', size=128),
2728+ 'parser_state':fields.selection([
2729+ ('default',_('Default')),
2730+ ('def',_('Definition')),
2731+ ('loc',_('Location')),
2732+ ],'State of Parser', select=True),
2733+ 'in_format': fields.selection(_get_in_mimetypes, 'Template Mime-type'),
2734+ 'out_format':fields.many2one('report.mimetypes', 'Output Mime-type'),
2735+ 'report_sxw_content': fields.function(_report_content,
2736+ fnct_inv=_report_content_inv, method=True,
2737+ type='binary', string='SXW content',),
2738+ }
2739+
2740+ def unlink(self, cr, uid, ids, context=None):
2741+ #TODO: process before delete resource
2742+ trans_obj = self.pool.get('ir.translation')
2743+ trans_ids = trans_obj.search(cr, uid, [('type','=','report'),('res_id','in',ids)])
2744+ trans_obj.unlink(cr, uid, trans_ids)
2745+ ####################################
2746+ reports = self.read(cr, uid, ids, ['report_name','model'])
2747+ for r in reports:
2748+ ir_value_ids = self.pool.get('ir.values').search(cr, uid, [('name','=',r['report_name']),
2749+ ('value','=','ir.actions.report.xml,%s' % r['id']),
2750+ ('model','=',r['model'])
2751+ ])
2752+ if ir_value_ids:
2753+ self.pool.get('ir.values').unlink(cr, uid, ir_value_ids)
2754+ self.pool.get('ir.model.data')._unlink(cr, uid, 'ir.actions.report.xml', ids)
2755+ ####################################
2756+ res = super(report_xml, self).unlink(cr, uid, ids, context)
2757+ return res
2758+
2759+ def create(self, cr, user, vals, context={}):
2760+ #if context and not self.pool.get('ir.model').search(cr, user, [('model','=',vals['model'])]):
2761+ # raise osv.except_osv(_('Object model is not correct !'),_('Please check "Object" field !') )
2762+ if 'report_type' in vals and vals['report_type'] == 'aeroo':
2763+ parser=rml_parse
2764+ if vals['parser_state']=='loc' and vals['parser_loc']:
2765+ parser=self.load_from_file(vals['parser_loc'], cr.dbname, vals['name'].lower().replace(' ','_')) or parser
2766+ elif vals['parser_state']=='def' and vals['parser_def']:
2767+ parser=self.load_from_source("from report import report_sxw\n"+vals['parser_def']) or parser
2768+
2769+ res_id = super(report_xml, self).create(cr, user, vals, context)
2770+ try:
2771+ self.register_report(cr, vals['report_name'], vals['model'], vals.get('report_rml', False), parser)
2772+ except Exception, e:
2773+ raise osv.except_osv(_('Report registration error !'), _('Report was not registered in system !'))
2774+ return res_id
2775+
2776+ res_id = super(report_xml, self).create(cr, user, vals, context)
2777+ return res_id
2778+
2779+ def write(self, cr, user, ids, vals, context=None):
2780+ if 'report_sxw_content_data' in vals:
2781+ if vals['report_sxw_content_data']:
2782+ try:
2783+ base64.decodestring(vals['report_sxw_content_data'])
2784+ except binascii.Error:
2785+ vals['report_sxw_content_data'] = False
2786+ if type(ids)==list:
2787+ ids = ids[0]
2788+ record = self.read(cr, user, ids)
2789+ #if context and 'model' in vals and not self.pool.get('ir.model').search(cr, user, [('model','=',vals['model'])]):
2790+ # raise osv.except_osv(_('Object model is not correct !'),_('Please check "Object" field !') )
2791+ if vals.get('report_type', record['report_type']) == 'aeroo':
2792+ parser=rml_parse
2793+ if vals.get('parser_state', False)=='loc':
2794+ parser = self.load_from_file(vals.get('parser_loc', False) or record['parser_loc'], cr.dbname, record['id']) or parser
2795+ elif vals.get('parser_state', False)=='def':
2796+ parser = self.load_from_source("from report import report_sxw\n"+(vals.get('parser_loc', False) or record['parser_def'] or '')) or parser
2797+ elif vals.get('parser_state', False)=='default':
2798+ parser = rml_parse
2799+ elif record['parser_state']=='loc':
2800+ parser = self.load_from_file(record['parser_loc'], cr.dbname, record['id']) or parser
2801+ elif record['parser_state']=='def':
2802+ parser = self.load_from_source("from report import report_sxw\n"+record['parser_def']) or parser
2803+ elif record['parser_state']=='default':
2804+ parser = rml_parse
2805+
2806+ if vals.get('parser_loc', False):
2807+ parser=self.load_from_file(vals['parser_loc'], cr.dbname, record['id']) or parser
2808+ elif vals.get('parser_def', False):
2809+ parser=self.load_from_source("from report import report_sxw\n"+vals['parser_def']) or parser
2810+ if vals.get('report_name', False) and vals['report_name']!=record['report_name']:
2811+ self.delete_report_service(record['report_name'])
2812+ report_name = vals['report_name']
2813+ else:
2814+ self.delete_report_service(record['report_name'])
2815+ report_name = record['report_name']
2816+
2817+ res = super(report_xml, self).write(cr, user, ids, vals, context)
2818+ try:
2819+ self.register_report(cr, report_name, vals.get('model', record['model']), vals.get('report_rml', record['report_rml']), parser)
2820+ except Exception, e:
2821+ raise osv.except_osv(_('Report registration error !'), _('Report was not registered in system !'))
2822+ return res
2823+
2824+ res = super(report_xml, self).write(cr, user, ids, vals, context)
2825+ return res
2826+
2827+ def _get_default_outformat(self, cr, uid, context):
2828+ obj = self.pool.get('report.mimetypes')
2829+ res = obj.search(cr, uid, [('code','=','oo-odt')])
2830+ return res and res[0] or False
2831+
2832+ _defaults = {
2833+ #'report_type' : lambda*a: 'oo-odt',
2834+ 'tml_source': lambda*a: 'database',
2835+ 'in_format' : lambda*a: 'oo-odt',
2836+ 'out_format' : _get_default_outformat,
2837+ 'charset': lambda*a: 'ascii',
2838+ 'styles_mode' : lambda*a: 'default',
2839+ 'preload_mode': lambda*a: 'static',
2840+ 'parser_state': lambda*a: 'default',
2841+ 'parser_def':lambda*a: """class Parser(report_sxw.rml_parse):
2842+ def __init__(self, cr, uid, name, context):
2843+ super(Parser, self).__init__(cr, uid, name, context)
2844+ self.localcontext.update({})"""
2845+ }
2846+
2847+ #def _object_check(self, cr, uid, ids):
2848+ # for r in self.browse(cr, uid, ids, {}):
2849+ # if not self.pool.get('ir.model').search(cr, uid, [('model','=',r.model)]):
2850+ # return False
2851+ # return True
2852+
2853+ #_constraints = [
2854+ # (_object_check, _('Object model is not correct')+' !\n'+_('Please check "Object" field')+' !', ['model'])
2855+ # ]
2856+
2857+report_xml()
2858+
2859+class ir_translation(osv.osv):
2860+ _name = 'ir.translation'
2861+ _inherit = 'ir.translation'
2862+
2863+ def __init__(self, pool, cr):
2864+ super(ir_translation, self).__init__(pool, cr)
2865+ if ('report', 'Report') not in self._columns['type'].selection:
2866+ self._columns['type'].selection.append(
2867+ ('report', 'Report'),
2868+ )
2869+
2870+ir_translation()
2871+
2872
2873=== added directory 'wizard'
2874=== added file 'wizard/__init__.py'
2875--- wizard/__init__.py 1970-01-01 00:00:00 +0000
2876+++ wizard/__init__.py 2012-07-05 12:25:24 +0000
2877@@ -0,0 +1,30 @@
2878+##############################################################################
2879+#
2880+# Copyright (c) 2008-2009 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
2881+# General contacts <info@kndati.lv>
2882+#
2883+# WARNING: This program as such is intended to be used by professional
2884+# programmers who take the whole responsability of assessing all potential
2885+# consequences resulting from its eventual inadequacies and bugs
2886+# End users who are looking for a ready-to-use solution with commercial
2887+# garantees and support are strongly adviced to contract a Free Software
2888+# Service Company
2889+#
2890+# This program is Free Software; you can redistribute it and/or
2891+# modify it under the terms of the GNU General Public License
2892+# as published by the Free Software Foundation; either version 2
2893+# of the License, or (at your option) any later version.
2894+#
2895+# This program is distributed in the hope that it will be useful,
2896+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2897+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2898+# GNU General Public License for more details.
2899+#
2900+# You should have received a copy of the GNU General Public License
2901+# along with this program; if not, write to the Free Software
2902+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2903+#
2904+##############################################################################
2905+
2906+import report_actions
2907+import report_actions_remove
2908
2909=== added file 'wizard/report_actions.py'
2910--- wizard/report_actions.py 1970-01-01 00:00:00 +0000
2911+++ wizard/report_actions.py 2012-07-05 12:25:24 +0000
2912@@ -0,0 +1,118 @@
2913+##############################################################################
2914+#
2915+# Copyright (c) 2008-2010 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
2916+# General contacts <info@kndati.lv>
2917+#
2918+# WARNING: This program as such is intended to be used by professional
2919+# programmers who take the whole responsability of assessing all potential
2920+# consequences resulting from its eventual inadequacies and bugs
2921+# End users who are looking for a ready-to-use solution with commercial
2922+# garantees and support are strongly adviced to contract a Free Software
2923+# Service Company
2924+#
2925+# This program is Free Software; you can redistribute it and/or
2926+# modify it under the terms of the GNU General Public License
2927+# as published by the Free Software Foundation; either version 2
2928+# of the License, or (at your option) any later version.
2929+#
2930+# This program is distributed in the hope that it will be useful,
2931+# but WITHOUT ANY WARRANTY; without even the implied warranty of
2932+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
2933+# GNU General Public License for more details.
2934+#
2935+# You should have received a copy of the GNU General Public License
2936+# along with this program; if not, write to the Free Software
2937+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
2938+#
2939+##############################################################################
2940+
2941+import wizard
2942+import pooler
2943+import ir
2944+from tools.translate import _
2945+
2946+class report_actions_wizard(wizard.interface):
2947+ '''
2948+ Add Print Button
2949+ '''
2950+ form = '''<?xml version="1.0"?>
2951+ <form string="Add Print Button">
2952+ <!--<field name="print_button"/>-->
2953+ <field name="open_action"/>
2954+ </form>'''
2955+
2956+ ex_form = '''<?xml version="1.0"?>
2957+ <form string="Add Print Button">
2958+ <label string="Report Action already exist for this report."/>
2959+ </form>'''
2960+
2961+ done_form = '''<?xml version="1.0"?>
2962+ <form string="Remove print button">
2963+ <label string="The print button is successfully added"/>
2964+ </form>'''
2965+
2966+ fields = {
2967+ #'print_button': {'string': 'Add print button', 'type': 'boolean', 'default': True, 'help':'Add action to menu context in print button.'},
2968+ 'open_action': {'string': 'Open added action', 'type': 'boolean', 'default': False},
2969+ }
2970+
2971+ def _do_action(self, cr, uid, data, context):
2972+ pool = pooler.get_pool(cr.dbname)
2973+ report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
2974+ #if data['form']['print_button']:
2975+ res = ir.ir_set(cr, uid, 'action', 'client_print_multi', report.report_name, [report.model], 'ir.actions.report.xml,%d' % data['id'], isobject=True)
2976+ #else:
2977+ # res = ir.ir_set(cr, uid, 'action', 'client_print_multi', report.report_name, [report.model,0], 'ir.actions.report.xml,%d' % data['id'], isobject=True)
2978+ return {'value_id':res[0]}
2979+
2980+ def _check(self, cr, uid, data, context):
2981+ pool = pooler.get_pool(cr.dbname)
2982+ report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
2983+ ids = pool.get('ir.values').search(cr, uid, [('value','=',report.type+','+str(data['id']))])
2984+ if not ids:
2985+ return 'add'
2986+ else:
2987+ return 'exist'
2988+
2989+ def _action_open_window(self, cr, uid, data, context):
2990+ form=data['form']
2991+ if not form['open_action']:
2992+ return {}
2993+ return {
2994+ 'domain':"[('id','=',%d)]" % (form['value_id']),
2995+ 'name': _('Client Actions Connections'),
2996+ 'view_type': 'form',
2997+ 'view_mode': 'tree,form',
2998+ 'res_model': 'ir.values',
2999+ 'view_id': False,
3000+ 'type': 'ir.actions.act_window',
3001+ }
3002+
3003+ states = {
3004+ 'init': {
3005+ 'actions': [],
3006+ 'result': {'type':'choice','next_state':_check}
3007+ },
3008+ 'add': {
3009+ 'actions': [],
3010+ 'result': {'type': 'form', 'arch': form, 'fields': fields, 'state': (('end', _('_Cancel')), ('process', _('_Ok')))},
3011+ },
3012+ 'exist': {
3013+ 'actions': [],
3014+ 'result': {'type': 'form', 'arch': ex_form, 'fields': {}, 'state': (('end', _('_Close')),)},
3015+ },
3016+ 'process': {
3017+ 'actions': [_do_action],
3018+ 'result': {'type': 'state', 'state': 'done'},
3019+ },
3020+ 'done': {
3021+ 'actions': [],
3022+ 'result': {'type': 'form', 'arch': done_form, 'fields': {}, 'state': (('exit', _('_Close')),)},
3023+ },
3024+ 'exit': {
3025+ 'actions': [],
3026+ 'result': {'type': 'action', 'action': _action_open_window, 'state': 'end'},
3027+ },
3028+ }
3029+report_actions_wizard('aeroo.report_actions')
3030+
3031
3032=== added file 'wizard/report_actions_remove.py'
3033--- wizard/report_actions_remove.py 1970-01-01 00:00:00 +0000
3034+++ wizard/report_actions_remove.py 2012-07-05 12:25:24 +0000
3035@@ -0,0 +1,97 @@
3036+##############################################################################
3037+#
3038+# Copyright (c) 2008-2010 SIA "KN dati". (http://kndati.lv) All Rights Reserved.
3039+# General contacts <info@kndati.lv>
3040+#
3041+# WARNING: This program as such is intended to be used by professional
3042+# programmers who take the whole responsability of assessing all potential
3043+# consequences resulting from its eventual inadequacies and bugs
3044+# End users who are looking for a ready-to-use solution with commercial
3045+# garantees and support are strongly adviced to contract a Free Software
3046+# Service Company
3047+#
3048+# This program is Free Software; you can redistribute it and/or
3049+# modify it under the terms of the GNU General Public License
3050+# as published by the Free Software Foundation; either version 2
3051+# of the License, or (at your option) any later version.
3052+#
3053+# This program is distributed in the hope that it will be useful,
3054+# but WITHOUT ANY WARRANTY; without even the implied warranty of
3055+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
3056+# GNU General Public License for more details.
3057+#
3058+# You should have received a copy of the GNU General Public License
3059+# along with this program; if not, write to the Free Software
3060+# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
3061+#
3062+##############################################################################
3063+
3064+import wizard
3065+import pooler
3066+import ir
3067+from tools.translate import _
3068+
3069+class report_actions_remove_wizard(wizard.interface):
3070+ '''
3071+ Remove print button
3072+ '''
3073+ form = '''<?xml version="1.0"?>
3074+ <form string="Remove print button">
3075+ <label string="Or you want to remove print button for this report?"/>
3076+ </form>'''
3077+
3078+ ex_form = '''<?xml version="1.0"?>
3079+ <form string="Remove print button">
3080+ <label string="No Report Action to delete for this report"/>
3081+ </form>'''
3082+
3083+ done_form = '''<?xml version="1.0"?>
3084+ <form string="Remove print button">
3085+ <label string="The print button is successfully removed"/>
3086+ </form>'''
3087+
3088+ def _do_action(self, cr, uid, data, context):
3089+ pool = pooler.get_pool(cr.dbname)
3090+ report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
3091+ res = ir.ir_get(cr, uid, 'action', 'client_print_multi', [report.model])
3092+ id = res[0][0]
3093+ res = ir.ir_del(cr, uid, id)
3094+ return {}
3095+
3096+ def _check(self, cr, uid, data, context):
3097+ pool = pooler.get_pool(cr.dbname)
3098+ report = pool.get(data['model']).browse(cr, uid, data['id'], context=context)
3099+ ids = pool.get('ir.values').search(cr, uid, [('value','=',report.type+','+str(data['id']))])
3100+ if not ids:
3101+ return 'no_exist'
3102+ else:
3103+ return 'remove'
3104+
3105+ states = {
3106+ 'init': {
3107+ 'actions': [],
3108+ 'result': {'type':'choice','next_state':_check}
3109+ },
3110+ 'remove': {
3111+ 'actions': [],
3112+ 'result': {'type': 'form', 'arch': form, 'fields': {}, 'state': (('end', _('_No')), ('process', _('_Yes')))},
3113+ },
3114+ 'no_exist': {
3115+ 'actions': [],
3116+ 'result': {'type': 'form', 'arch': ex_form, 'fields': {}, 'state': (('end', _('_Close')),)},
3117+ },
3118+ 'process': {
3119+ 'actions': [_do_action],
3120+ 'result': {'type': 'state', 'state': 'done'},
3121+ },
3122+ 'done': {
3123+ 'actions': [],
3124+ 'result': {'type': 'form', 'arch': done_form, 'fields': {}, 'state': (('exit', _('_Close')),)},
3125+ },
3126+ 'exit': {
3127+ 'actions': [],
3128+ 'result': {'type': 'state', 'state': 'end'},
3129+ },
3130+ }
3131+report_actions_remove_wizard('aeroo.report_actions_remove')
3132+

Subscribers

People subscribed via source and target branches