21
21
##############################################################################
25
26
from report import report_sxw
27
28
from openerp.tools.translate import _
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
37
class accountReportbase(report_sxw.rml_parse, WebKitHelper):
32
40
This class is the base for the reports. Contains all the basic functions
33
41
to extract info that the reports needs
35
def __init__(self, cr, uid, name, context):
43
def __init__(self, cr, uid, name, context):
45
self.cursor = cr #WebkitHelper use "cursor" instead of "cr"
46
self.pool = pooler.get_pool(self.cr.dbname)
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.
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,
58
79
#####################################BASIC FUNCTIONS ##############################
108
129
return self._get_info(data,'account_ids', 'account.account')
131
def get_journal_ids(self, data):
132
return self._get_info(data, 'journal_ids', 'account.journal')
110
134
def get_historic_strict (self, data):
111
135
return self._get_form_param('historic_strict', data)
119
143
def get_account_base_report(self, data):
120
144
return self._get_info(data, 'account_base_report', 'account.financial.report')
146
def get_sort_selection(self, data):
147
return self._get_form_param('sort_selection', data)
122
149
################################## INFO DISPLAY ###########################
124
151
def get_display_target_move(self, data):
160
def get_display_sort_selection(self, data):
161
val = self._get_form_param('sort_selection', data)
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
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)
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
189
#===========================================================================
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.
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.
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
#===============================================================================
207
def set_data_template(self, cr, uid, data):
211
self.localcontext['storage'].update(dict_update)
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]
b'\\ No newline at end of file'