~registry/openerp-swiss-localization/trunk

« back to all changes in this revision

Viewing changes to l10n_ch/report/bvr.py

  • Committer: nicolas.bessi at camptocamp
  • Date: 2010-04-21 15:06:06 UTC
  • Revision ID: nicolas.bessi@camptocamp.com-20100421150606-6tojiagdk4tlzhnk
[IMP]Module preparation for certification  
respect of the coding standards
DTA unicode management
RES Bank view improvement
Various Fixes
complete demo data
OPAE preparation (Broken)

Show diffs side-by-side

added added

removed removed

Lines of Context:
5
5
#
6
6
#  Created by Nicolas Bessi based on Credric Krier contribution
7
7
#
8
 
#  Copyright (c) 2009 CamptoCamp. All rights reserved.
 
8
#  Copyright (c) 2010 CamptoCamp. All rights reserved.
9
9
##############################################################################
10
10
# WARNING: This program as such is intended to be used by professional
11
11
# programmers who take the whole responsability of assessing all potential
29
29
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
30
30
#
31
31
##############################################################################
 
32
"""Report class that Allows to print BVR payement vector"""
32
33
 
33
34
import time
34
35
from report import report_sxw
37
38
import os 
38
39
import sys
39
40
import shutil
40
 
from mx.DateTime import *
 
41
# from mx.DateTime import *
41
42
 
42
 
class account_invoice_bvr(report_sxw.rml_parse):
 
43
class AccountInvoiceBvr(report_sxw.rml_parse):
43
44
    """Report class that Allows to print BVR payement vector"""
44
 
    def __init__(self, cr, uid, name, context):
45
 
        super(account_invoice_bvr, self).__init__(cr, uid, name, context)
 
45
    def __init__(self, cursor, uid, name, context):
 
46
        super(AccountInvoiceBvr, self).__init__(cursor, uid, name, context)
46
47
        self.copyocrbfile('addons/l10n_ch/report/ocrbb.ttf')
47
48
        self.localcontext.update({
48
49
            'time': time,
49
 
            'user':self.pool.get("res.users").browse(cr,uid,uid),
 
50
            'user':self.pool.get("res.users").browse(cursor, uid, uid),
50
51
            'mod10r': mod10r,
51
52
            '_space': self._space,
52
53
            '_get_ref': self._get_ref,
53
54
            'comma_me': self.comma_me,
54
 
            'format_date': self._get_and_change_date_format_for_swiss,
55
55
            'police_absolute_path' : self.police_absolute_path,
56
56
            'copyocrbfile': self.copyocrbfile
57
57
        })
58
 
    def _get_and_change_date_format_for_swiss (self,date_to_format):
59
 
        date_formatted=''
60
 
        print date_to_format
61
 
        if date_to_format:
62
 
            date_formatted = strptime(date_to_format,'%Y-%m-%d').strftime('%d.%m.%Y')
63
 
        return date_formatted
64
58
        
 
59
    #will be fixed in 5.0.10    
65
60
    def police_absolute_path(self, inner_path) :
 
61
        """Will get the ocrb police absolute path"""
66
62
        path = os.path.join(os.path.dirname(sys.argv[0]), inner_path)
67
63
        return  path
68
 
        
69
 
    def copyocrbfile(self,file):
70
 
        src = self.police_absolute_path(file)
71
 
        file = os.path.basename(src)
72
 
        dest = os.path.join('/tmp/',file)
 
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)
73
70
        if not os.path.isfile(dest):
74
71
            try:
75
 
                shutil.copyfile(src,dest)
 
72
                shutil.copyfile(src, dest)
76
73
            except:
77
74
                """print ocrbfile was not copy in /tmp/ please 
78
75
                copy it manually from l10_ch/report"""
79
76
        
80
77
            
81
78
 
82
 
    def comma_me(self,amount):
 
79
    def comma_me(self, amount):
 
80
        """Fast swiss number formatting"""
83
81
        if  type(amount) is float :
84
82
            amount = str('%.2f'%amount)
85
83
        else :
91
89
        else:
92
90
            return self.comma_me(new)
93
91
 
94
 
    def _space(self,nbr, nbrspc=5):
 
92
    def _space(self, nbr, nbrspc=5):
 
93
        """Spaces * 5"""
95
94
        res = ''
96
95
        for i in range(len(nbr)):
97
96
            res = res + nbr[i]
99
98
                res = res + ' '
100
99
        return res
101
100
 
102
 
    def _get_ref(self, o):
 
101
    def _get_ref(self, inv):
 
102
        """Retrieve ESR/BVR reference form invoice in order to print it"""
103
103
        res = ''
104
 
        if o.partner_bank.bvr_adherent_num:
105
 
            res = o.partner_bank.bvr_adherent_num
 
104
        if inv.partner_bank.bvr_adherent_num:
 
105
            res = inv.partner_bank.bvr_adherent_num
106
106
        invoice_number = ''
107
 
        if o.number:
108
 
            invoice_number = re.sub('[^0-9]', '0', o.number)
 
107
        if inv.number:
 
108
            invoice_number = re.sub('[^0-9]', '', inv.number)
109
109
        return mod10r(res + invoice_number.rjust(26-len(res), '0'))
110
110
 
111
111
report_sxw.report_sxw(
112
112
    'report.l10n_ch.bvr',
113
113
    'account.invoice',
114
 
    'addons/l10n_ch/report/bvr.rml',
115
 
    parser=account_invoice_bvr,
 
114
    'addons/l10n_ch/report/bvr_report.rml',
 
115
    parser=AccountInvoiceBvr,
116
116
    header=False)
117
117
 
118
118
report_sxw.report_sxw(
119
119
    'report.l10n_ch.invoice.bvr',
120
120
    'account.invoice',
121
 
    'addons/l10n_ch/report/invoice.rml',
122
 
    parser=account_invoice_bvr,
 
121
    'addons/l10n_ch/report/invoice_report.rml',
 
122
    parser=AccountInvoiceBvr,
123
123
    header=False)
124
124
 
125
125
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4: