1 # -*- encoding: utf-8 -*-
6 # Created by Nicolas Bessi based on Credric Krier contribution
8 # Copyright (c) 2010 CamptoCamp. All rights reserved.
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
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.
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.
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.
31 ##############################################################################
32 """Report class that Allows to print BVR payement vector"""
35 from report import report_sxw
36 from tools import mod10r
41 # from mx.DateTime import *
43 class AccountInvoiceBvr(report_sxw.rml_parse):
44 """Report class that Allows to print BVR payement vector"""
45 def __init__(self, cursor, uid, name, context):
46 super(AccountInvoiceBvr, self).__init__(cursor, uid, name, context)
47 self.copyocrbfile('addons/l10n_ch/report/ocrbb.ttf')
48 self.localcontext.update({
50 'user':self.pool.get("res.users").browse(cursor, uid, uid),
52 '_space': self._space,
53 '_get_ref': self._get_ref,
54 'comma_me': self.comma_me,
55 'police_absolute_path' : self.police_absolute_path,
56 'copyocrbfile': self.copyocrbfile
59 #will be fixed in 5.0.10
60 def police_absolute_path(self, inner_path) :
61 """Will get the ocrb police absolute path"""
62 path = os.path.join(os.path.dirname(sys.argv[0]), inner_path)
64 # will be fix in 5.0.10
65 def copyocrbfile(self, ttffile):
67 src = self.police_absolute_path(ttffile)
68 basefile = os.path.basename(src)
69 dest = os.path.join('/tmp/', basefile)
70 if not os.path.isfile(dest):
72 shutil.copyfile(src, dest)
74 """print ocrbfile was not copy in /tmp/ please
75 copy it manually from l10_ch/report"""
79 def comma_me(self, amount):
80 """Fast swiss number formatting"""
81 if type(amount) is float :
82 amount = str('%.2f'%amount)
86 new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
90 return self.comma_me(new)
92 def _space(self, nbr, nbrspc=5):
95 for i in range(len(nbr)):
97 if not (i-1) % nbrspc:
101 def _get_ref(self, inv):
102 """Retrieve ESR/BVR reference form invoice in order to print it"""
104 if inv.partner_bank.bvr_adherent_num:
105 res = inv.partner_bank.bvr_adherent_num
108 invoice_number = re.sub('[^0-9]', '', inv.number)
109 return mod10r(res + invoice_number.rjust(26-len(res), '0'))
111 report_sxw.report_sxw(
112 'report.l10n_ch.bvr',
114 'addons/l10n_ch/report/bvr_report.rml',
115 parser=AccountInvoiceBvr,
118 report_sxw.report_sxw(
119 'report.l10n_ch.invoice.bvr',
121 'addons/l10n_ch/report/invoice_report.rml',
122 parser=AccountInvoiceBvr,
125 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: