[FIX] Schedule jobs even if their next time has passed.
[odoo/odoo.git] / addons / l10n_ch / report / bvr.py
1 # -*- encoding: utf-8 -*-
2 #
3 #  bvr.py
4 #  l10n_ch
5 #
6 #  Created by Nicolas Bessi based on Credric Krier contribution
7 #
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
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 """Report class that Allows to print BVR payement vector"""
33
34 import time
35 from report import report_sxw
36 from tools import mod10r
37 import re
38 import os 
39 import sys
40 import shutil
41 # from mx.DateTime import *
42
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({
49             'time': time,
50             'user':self.pool.get("res.users").browse(cursor, uid, uid),
51             'mod10r': mod10r,
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
57         })
58         
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)
63         return  path
64     # will be fix in 5.0.10   
65     def copyocrbfile(self, ttffile):
66         """Copy ocrb file"""
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):
71             try:
72                 shutil.copyfile(src, dest)
73             except:
74                 """print ocrbfile was not copy in /tmp/ please 
75                 copy it manually from l10_ch/report"""
76         
77             
78
79     def comma_me(self, amount):
80         """Fast swiss number formatting"""
81         if  type(amount) is float :
82             amount = str('%.2f'%amount)
83         else :
84             amount = str(amount)
85         orig = amount
86         new = re.sub("^(-?\d+)(\d{3})", "\g<1>'\g<2>", amount)
87         if orig == new:
88             return new
89         else:
90             return self.comma_me(new)
91
92     def _space(self, nbr, nbrspc=5):
93         """Spaces * 5"""
94         res = ''
95         for i in range(len(nbr)):
96             res = res + nbr[i]
97             if not (i-1) % nbrspc:
98                 res = res + ' '
99         return res
100
101     def _get_ref(self, inv):
102         """Retrieve ESR/BVR reference form invoice in order to print it"""
103         res = ''
104         if inv.partner_bank.bvr_adherent_num:
105             res = inv.partner_bank.bvr_adherent_num
106         invoice_number = ''
107         if inv.number:
108             invoice_number = re.sub('[^0-9]', '', inv.number)
109         return mod10r(res + invoice_number.rjust(26-len(res), '0'))
110
111 report_sxw.report_sxw(
112     'report.l10n_ch.bvr',
113     'account.invoice',
114     'addons/l10n_ch/report/bvr_report.rml',
115     parser=AccountInvoiceBvr,
116     header=False)
117
118 report_sxw.report_sxw(
119     'report.l10n_ch.invoice.bvr',
120     'account.invoice',
121     'addons/l10n_ch/report/invoice_report.rml',
122     parser=AccountInvoiceBvr,
123     header=False)
124
125 # vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: