26
26
# along with this program. If not, see <http://www.gnu.org/licenses/>.
27
27
##############################################################################
29
from osv import osv,fields
29
from osv import osv, fields
32
32
from tools.translate import _
34
35
class wizard_report(osv.osv_memory):
35
36
_name = "wizard.report"
38
'afr_id': fields.many2one('afr','Custom Report', help='If you have already set a Custom Report, Select it Here.'),
39
'company_id': fields.many2one('res.company','Company',required=True),
39
'afr_id': fields.many2one('afr', 'Custom Report', help='If you have already set a Custom Report, Select it Here.'),
40
'company_id': fields.many2one('res.company', 'Company', required=True),
40
41
'currency_id': fields.many2one('res.currency', 'Currency', help="Currency at which this report will be expressed. If not selected will be used the one set in the company"),
41
'inf_type': fields.selection([('BS','Balance Sheet'),('IS','Income Statement')],'Type',required=True),
42
'columns': fields.selection([('one','End. Balance'),('two','Debit | Credit'), ('four','Initial | Debit | Credit | YTD'), ('five','Initial | Debit | Credit | Period | YTD'),('qtr',"4 QTR's | YTD"),('thirteen','12 Months | YTD')],'Columns',required=True),
43
'display_account': fields.selection([('all','All Accounts'),('bal', 'With Balance'),('mov','With movements'),('bal_mov','With Balance / Movements')],'Display accounts'),
44
'display_account_level': fields.integer('Up to level',help='Display accounts up to this level (0 to show all)'),
46
'account_list': fields.many2many ('account.account','rel_wizard_account','account_list','account_id','Root accounts',required=True),
48
'fiscalyear': fields.many2one('account.fiscalyear','Fiscal year',help='Fiscal Year for this report',required=True),
49
'periods': fields.many2many('account.period','rel_wizard_period','wizard_id','period_id','Periods',help='All periods in the fiscal year if empty'),
42
'inf_type': fields.selection([('BS', 'Balance Sheet'), ('IS', 'Income Statement')], 'Type', required=True),
43
'columns': fields.selection([('one', 'End. Balance'), ('two', 'Debit | Credit'), ('four', 'Initial | Debit | Credit | YTD'), ('five', 'Initial | Debit | Credit | Period | YTD'), ('qtr', "4 QTR's | YTD"), ('thirteen', '12 Months | YTD')], 'Columns', required=True),
44
'display_account': fields.selection([('all', 'All Accounts'), ('bal', 'With Balance'), ('mov', 'With movements'), ('bal_mov', 'With Balance / Movements')], 'Display accounts'),
45
'display_account_level': fields.integer('Up to level', help='Display accounts up to this level (0 to show all)'),
47
'account_list': fields.many2many('account.account', 'rel_wizard_account', 'account_list', 'account_id', 'Root accounts', required=True),
49
'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal year', help='Fiscal Year for this report', required=True),
50
'periods': fields.many2many('account.period', 'rel_wizard_period', 'wizard_id', 'period_id', 'Periods', help='All periods in the fiscal year if empty'),
51
52
'analytic_ledger': fields.boolean('Analytic Ledger', help="Allows to Generate an Analytic Ledger for accounts with moves. Available when Balance Sheet and 'Initial | Debit | Credit | YTD' are selected"),
53
54
'tot_check': fields.boolean('Summarize?', help='Checking will add a new line at the end of the Report which will Summarize Columns in Report'),
54
'lab_str': fields.char('Description', help='Description for the Summary', size= 128),
55
'lab_str': fields.char('Description', help='Description for the Summary', size=128),
56
57
#~ Deprecated fields
57
'filter': fields.selection([('bydate','By Date'),('byperiod','By Period'),('all','By Date and Period'),('none','No Filter')],'Date/Period Filter'),
58
'filter': fields.selection([('bydate', 'By Date'), ('byperiod', 'By Period'), ('all', 'By Date and Period'), ('none', 'No Filter')], 'Date/Period Filter'),
58
59
'date_to': fields.date('End date'),
59
60
'date_from': fields.date('Start date'),
63
64
'date_from': lambda *a: time.strftime('%Y-%m-%d'),
64
65
'date_to': lambda *a: time.strftime('%Y-%m-%d'),
65
'filter': lambda *a:'byperiod',
66
'filter': lambda *a: 'byperiod',
66
67
'display_account_level': lambda *a: 0,
67
'inf_type': lambda *a:'BS',
68
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
68
'inf_type': lambda *a: 'BS',
69
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.invoice', context=c),
69
70
'fiscalyear': lambda self, cr, uid, c: self.pool.get('account.fiscalyear').find(cr, uid),
70
'display_account': lambda *a:'bal_mov',
71
'columns': lambda *a:'five',
71
'display_account': lambda *a: 'bal_mov',
72
'columns': lambda *a: 'five',
74
def onchange_inf_type(self,cr,uid,ids,inf_type,context=None):
75
def onchange_inf_type(self, cr, uid, ids, inf_type, context=None):
75
76
if context is None:
79
80
if inf_type != 'BS':
80
res['value'].update({'analytic_ledger':False})
81
res['value'].update({'analytic_ledger': False})
84
def onchange_columns(self,cr,uid,ids,columns,fiscalyear,periods,context=None):
85
def onchange_columns(self, cr, uid, ids, columns, fiscalyear, periods, context=None):
85
86
if context is None:
89
90
p_obj = self.pool.get("account.period")
90
all_periods = p_obj.search(cr,uid,[('fiscalyear_id','=',fiscalyear),('special','=',False)],context=context)
91
all_periods = p_obj.search(cr, uid, [('fiscalyear_id', '=', fiscalyear), (
92
'special', '=', False)], context=context)
91
93
s = set(periods[0][2])
92
94
t = set(all_periods)
93
95
go = periods[0][2] and s.issubset(t) or False
95
97
if columns != 'four':
96
res['value'].update({'analytic_ledger':False})
98
res['value'].update({'analytic_ledger': False})
98
100
if columns in ('qtr', 'thirteen'):
99
res['value'].update({'periods':all_periods})
101
res['value'].update({'periods': all_periods})
102
res['value'].update({'periods':periods})
104
res['value'].update({'periods': periods})
104
res['value'].update({'periods':[]})
107
def onchange_analytic_ledger(self,cr,uid,ids,company_id,analytic_ledger,context=None):
110
context['company_id']=company_id
112
cur_id = self.pool.get('res.company').browse(cr,uid,company_id,context=context).currency_id.id
113
res['value'].update({'currency_id':cur_id})
116
def onchange_company_id(self,cr,uid,ids,company_id,context=None):
119
context['company_id']=company_id
106
res['value'].update({'periods': []})
109
def onchange_analytic_ledger(self, cr, uid, ids, company_id, analytic_ledger, context=None):
112
context['company_id'] = company_id
114
cur_id = self.pool.get('res.company').browse(
115
cr, uid, company_id, context=context).currency_id.id
116
res['value'].update({'currency_id': cur_id})
119
def onchange_company_id(self, cr, uid, ids, company_id, context=None):
122
context['company_id'] = company_id
122
125
if not company_id:
125
cur_id = self.pool.get('res.company').browse(cr,uid,company_id,context=context).currency_id.id
126
fy_id = self.pool.get('account.fiscalyear').find(cr, uid,context=context)
127
res['value'].update({'fiscalyear':fy_id})
128
res['value'].update({'currency_id':cur_id})
129
res['value'].update({'account_list':[]})
130
res['value'].update({'periods':[]})
131
res['value'].update({'afr_id':None})
128
cur_id = self.pool.get('res.company').browse(
129
cr, uid, company_id, context=context).currency_id.id
130
fy_id = self.pool.get('account.fiscalyear').find(
131
cr, uid, context=context)
132
res['value'].update({'fiscalyear': fy_id})
133
res['value'].update({'currency_id': cur_id})
134
res['value'].update({'account_list': []})
135
res['value'].update({'periods': []})
136
res['value'].update({'afr_id': None})
134
def onchange_afr_id(self,cr,uid,ids,afr_id,context=None):
139
def onchange_afr_id(self, cr, uid, ids, afr_id, context=None):
135
140
if context is None:
138
if not afr_id: return res
139
afr_brw = self.pool.get('afr').browse(cr,uid,afr_id,context=context)
140
res['value'].update({'currency_id':afr_brw.currency_id and afr_brw.currency_id.id or afr_brw.company_id.currency_id.id})
141
res['value'].update({'inf_type':afr_brw.inf_type or 'BS'})
142
res['value'].update({'columns':afr_brw.columns or 'five'})
143
res['value'].update({'display_account':afr_brw.display_account or 'bal_mov'})
144
res['value'].update({'display_account_level':afr_brw.display_account_level or 0})
145
res['value'].update({'fiscalyear':afr_brw.fiscalyear_id and afr_brw.fiscalyear_id.id})
146
res['value'].update({'account_list':[acc.id for acc in afr_brw.account_ids]})
147
res['value'].update({'periods':[p.id for p in afr_brw.period_ids]})
148
res['value'].update({'analytic_ledger':afr_brw.analytic_ledger or False})
149
res['value'].update({'tot_check':afr_brw.tot_check or False})
150
res['value'].update({'lab_str':afr_brw.lab_str or _('Write a Description for your Summary Total')})
145
afr_brw = self.pool.get('afr').browse(cr, uid, afr_id, context=context)
146
res['value'].update({
147
'currency_id': afr_brw.currency_id and afr_brw.currency_id.id or afr_brw.company_id.currency_id.id})
148
res['value'].update({'inf_type': afr_brw.inf_type or 'BS'})
149
res['value'].update({'columns': afr_brw.columns or 'five'})
150
res['value'].update({
151
'display_account': afr_brw.display_account or 'bal_mov'})
152
res['value'].update({
153
'display_account_level': afr_brw.display_account_level or 0})
154
res['value'].update({
155
'fiscalyear': afr_brw.fiscalyear_id and afr_brw.fiscalyear_id.id})
156
res['value'].update({'account_list': [
157
acc.id for acc in afr_brw.account_ids]})
158
res['value'].update({'periods': [p.id for p in afr_brw.period_ids]})
159
res['value'].update({
160
'analytic_ledger': afr_brw.analytic_ledger or False})
161
res['value'].update({'tot_check': afr_brw.tot_check or False})
162
res['value'].update({'lab_str': afr_brw.lab_str or _(
163
'Write a Description for your Summary Total')})
153
166
def _get_defaults(self, cr, uid, data, context=None):
154
167
if context is None:
156
user = pooler.get_pool(cr.dbname).get('res.users').browse(cr, uid, uid, context=context)
169
user = pooler.get_pool(cr.dbname).get(
170
'res.users').browse(cr, uid, uid, context=context)
157
171
if user.company_id:
158
company_id = user.company_id.id
172
company_id = user.company_id.id
160
company_id = pooler.get_pool(cr.dbname).get('res.company').search(cr, uid, [('parent_id', '=', False)])[0]
174
company_id = pooler.get_pool(cr.dbname).get(
175
'res.company').search(cr, uid, [('parent_id', '=', False)])[0]
161
176
data['form']['company_id'] = company_id
162
177
fiscalyear_obj = pooler.get_pool(cr.dbname).get('account.fiscalyear')
163
178
data['form']['fiscalyear'] = fiscalyear_obj.find(cr, uid)
168
183
if context is None:
170
185
if data['form']['filter'] == 'bydate':
171
self._check_date(cr, uid, data, context)
186
self._check_date(cr, uid, data, context)
172
187
return data['form']
174
189
def _check_date(self, cr, uid, data, context=None):
175
190
if context is None:
178
193
if data['form']['date_from'] > data['form']['date_to']:
179
raise osv.except_osv(_('Error !'),('La fecha final debe ser mayor a la inicial'))
194
raise osv.except_osv(_('Error !'), (
195
'La fecha final debe ser mayor a la inicial'))
181
197
sql = """SELECT f.id, f.date_start, f.date_stop
182
198
FROM account_fiscalyear f
183
WHERE '%s' = f.id """%(data['form']['fiscalyear'])
199
WHERE '%s' = f.id """ % (data['form']['fiscalyear'])
185
201
res = cr.dictfetchall()
188
204
if (data['form']['date_to'] > res[0]['date_stop'] or data['form']['date_from'] < res[0]['date_start']):
189
raise osv.except_osv(_('UserError'),'Las fechas deben estar entre %s y %s' % (res[0]['date_start'], res[0]['date_stop']))
205
raise osv.except_osv(_('UserError'), 'Las fechas deben estar entre %s y %s' % (
206
res[0]['date_start'], res[0]['date_stop']))
193
raise osv.except_osv(_('UserError'),'No existe periodo fiscal')
210
raise osv.except_osv(_('UserError'), 'No existe periodo fiscal')
195
212
def period_span(self, cr, uid, ids, fy_id, context=None):
196
213
if context is None:
198
215
ap_obj = self.pool.get('account.period')
199
fy_id = fy_id and type(fy_id) in (list,tuple) and fy_id[0] or fy_id
216
fy_id = fy_id and type(fy_id) in (list, tuple) and fy_id[0] or fy_id
201
218
#~ No hay periodos
202
return ap_obj.search(cr, uid, [('fiscalyear_id','=',fy_id),('special','=',False)],order='date_start asc')
219
return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), ('special', '=', False)], order='date_start asc')
204
221
ap_brws = ap_obj.browse(cr, uid, ids, context=context)
205
222
date_start = min([period.date_start for period in ap_brws])
206
223
date_stop = max([period.date_stop for period in ap_brws])
208
return ap_obj.search(cr, uid, [('fiscalyear_id','=',fy_id),('special','=',False),('date_start','>=',date_start),('date_stop','<=',date_stop)],order='date_start asc')
225
return ap_obj.search(cr, uid, [('fiscalyear_id', '=', fy_id), ('special', '=', False), ('date_start', '>=', date_start), ('date_stop', '<=', date_stop)], order='date_start asc')
210
227
def print_report(self, cr, uid, ids, data, context=None):
211
228
if context is None:
215
232
data['ids'] = context.get('active_ids', [])
216
233
data['model'] = context.get('active_model', 'ir.ui.menu')