~gs.clearcorp/openerp-ccorp-addons/7.0_project_gdrive

« back to all changes in this revision

Viewing changes to account_report_lib/account_report_base.py

  • Committer: Glen Sojo
  • Date: 2014-01-14 17:23:27 UTC
  • mfrom: (797.1.3 7.0)
  • Revision ID: glen.sojo@clearcorp.co.cr-20140114172327-9qgylioq7v4w0ybi
[MRG] Merged diverged changes

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
##############################################################################
22
22
 
23
23
import time
 
24
import datetime
24
25
import pooler
25
26
from report import report_sxw
26
27
import locale
27
28
from openerp.tools.translate import _
28
29
 
29
 
class accountReportbase(report_sxw.rml_parse):
 
30
#===============================================================================
 
31
# environment variable helper can't be used in odt. Import file where is defined 
 
32
# the function, and create a python heritage. With this, the class Parser
 
33
# can use embed_logo_by_name method.
 
34
#===============================================================================
 
35
from openerp.addons.report_webkit.report_helper import WebKitHelper 
 
36
 
 
37
class accountReportbase(report_sxw.rml_parse, WebKitHelper):
30
38
    
31
39
    """
32
40
        This class is the base for the reports. Contains all the basic functions
33
41
        to extract info that the reports needs
34
42
    """
35
 
    def __init__(self, cr, uid, name, context):
 
43
    def __init__(self, cr, uid, name, context):        
 
44
        self.cr = cr 
 
45
        self.cursor = cr #WebkitHelper use "cursor" instead of "cr"
 
46
        self.pool = pooler.get_pool(self.cr.dbname)
 
47
       
36
48
        super(accountReportbase, self).__init__(cr, uid, name, context=context)
37
49
        self.localcontext.update({
 
50
            'datetime': datetime, #Necessary to print date and time for print the report. 
38
51
            'time': time,
39
52
            'cr' : cr,
40
53
            'uid': uid,
 
54
            'storage':{},
41
55
            'get_start_period': self.get_start_period,
42
56
            'get_end_period':self.get_end_period,
43
57
            'get_fiscal_year':self.get_fiscalyear,
47
61
            'get_date_from': self.get_date_from,
48
62
            'get_date_to': self.get_date_to,
49
63
            'get_accounts_ids': self.get_accounts_ids,
 
64
            'get_journal_ids': self.get_journal_ids,
50
65
            'get_historic_strict': self.get_historic_strict,
51
66
            'get_special_period': self.get_special_period,
52
67
            'display_target_move':self.get_display_target_move,
 
68
            'get_display_sort_selection':self.get_display_sort_selection,
53
69
            'get_signatures_report': self.get_signatures_report,
54
70
            'get_amount_currency':self.get_amount_currency,
55
71
            'get_account_base_report':self.get_account_base_report,
 
72
            'embed_logo_by_name': self.embed_logo_by_name, #return logo (default_logo) 
 
73
            'formatLang': self.formatLang, #return a numeric format for amounts.
 
74
            'set_data_template': self.set_data_template,
 
75
            'get_data_template': self.get_data_template,
 
76
            'get_sort_selection': self.get_sort_selection,
56
77
         })
57
78
    
58
79
    #####################################BASIC FUNCTIONS ##############################
107
128
        
108
129
        return self._get_info(data,'account_ids', 'account.account')
109
130
    
 
131
    def get_journal_ids(self, data):
 
132
        return self._get_info(data, 'journal_ids', 'account.journal')
 
133
    
110
134
    def get_historic_strict (self, data):
111
135
        return self._get_form_param('historic_strict', data)
112
136
    
119
143
    def get_account_base_report(self, data):
120
144
        return self._get_info(data, 'account_base_report', 'account.financial.report')
121
145
    
 
146
    def get_sort_selection(self, data):
 
147
        return self._get_form_param('sort_selection', data)
 
148
    
122
149
    ################################## INFO DISPLAY ###########################
123
150
    
124
151
    def get_display_target_move(self, data):
130
157
        else:
131
158
            return val
132
159
    
 
160
    def get_display_sort_selection(self, data):
 
161
        val = self._get_form_param('sort_selection', data)
 
162
        if val == 'date':
 
163
            return _('Date')
 
164
        elif val == 'name':
 
165
            return _('Name')
 
166
        else:
 
167
            return val
 
168
    
133
169
    ##################### SIGNATURES ############################
134
170
     #Return the users that can sign the report.
135
171
    def get_signatures_report(self, cr, uid, report_name):  
136
172
      report_id = self.pool.get('ir.actions.report.xml').search(cr, uid,[('name','=', report_name)])
137
173
      report_obj = self.pool.get('ir.actions.report.xml').browse(cr, uid, report_id)
138
 
      return report_obj[0].signature_users
 
 
b'\\ No newline at end of file'
 
174
      return report_obj[0].signature_users
 
175
  
 
176
    ################### IMAGE MANIPULATION ######################        
 
177
    #Use get_logo_by_name function from report_helper. Return img, a binary image. 
 
178
    def embed_logo_by_name(self, name):
 
179
        img, type = self.get_logo_by_name(name)
 
180
        
 
181
        return img 
 
182
    
 
183
    #================ SET AND GET DATA INTO A AEROO REPORT TEMPLATE ===========#
 
184
    #===========================================================================
 
185
    # This method will be re-implemented in each report that needs some 
 
186
    # temporary variable in odt/ods templates. set_data_template will include 
 
187
    # in the parsers and it will include values and variables that the report 
 
188
    # needs. 
 
189
    #===========================================================================
 
190
    
 
191
    #===============================================================================
 
192
    #    get_data_template set_data_template and methods are used to create a workarround 
 
193
    #    (not found a way to have temporary variables in a template in aeroo). 
 
194
    #    The set method calls the methods that do the calculations and stores them 
 
195
    #    in a dictionary that is built into the localcontext, called storage. 
 
196
    #    All values ​​are stored in this dictionary.
 
197
    # 
 
198
    #    Then get_data_template method that receives a string, which is the key of the dictionary, 
 
199
    #    pass the value of the key we want and this method returns the value stored in this key.
 
200
    # 
 
201
    #    Set_data_template method is called in the template if odt as follows: 
 
202
    #    <if test="set_data_template(cr, uid, data)"> </if>. 
 
203
    #    In this way, we obtain the values ​​and can work with them directly in the template odt,
 
204
    #     shaped <get_data_template('key')>.
 
205
    #===============================================================================
 
206
    
 
207
    def set_data_template(self, cr, uid, data):        
 
208
        
 
209
        dict_update = {}
 
210
        
 
211
        self.localcontext['storage'].update(dict_update)
 
212
        return False
 
213
    
 
214
    #get data with a specific key
 
215
    """@param key: key is a string. It's comming for the odt template and return the value that match with key in storage dictionary """
 
216
    def get_data_template(self, key):
 
217
        if key in self.localcontext['storage'].keys():
 
218
            return self.localcontext['storage'][key]
 
219
        return False
 
 
b'\\ No newline at end of file'