[IMP] account: improved the query_get of account_move_line to put the logic of initial balance computing + fixes on general ledger report
bzr revid: qdp-launchpad@tinyerp.com-20101001113241-ojddhmvr3q3zppzj
This commit is contained in:
parent
b7ae669a1e
commit
45e78ba71e
|
@ -36,10 +36,16 @@ class account_move_line(osv.osv):
|
||||||
fiscalperiod_obj = self.pool.get('account.period')
|
fiscalperiod_obj = self.pool.get('account.period')
|
||||||
fiscalyear_ids = []
|
fiscalyear_ids = []
|
||||||
fiscalperiod_ids = []
|
fiscalperiod_ids = []
|
||||||
if not context.get('fiscalyear', False) and not context.get('empty_fy_allow', False):
|
initial_bal = context.get('initial_bal', False)
|
||||||
|
company_clause = ""
|
||||||
|
if context.get('company_id', False):
|
||||||
|
company_clause = " AND " +obj+".company_id = %s" % context.get('company_id', False)
|
||||||
|
if not context.get('fiscalyear', False):
|
||||||
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
|
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('state', '=', 'draft')])
|
||||||
elif context.get('empty_fy_allow', False):
|
else:
|
||||||
fiscalyear_ids = context['fiscalyear']
|
if initial_bal:
|
||||||
|
fiscalyear_date_start = fiscalyear_obj.read(cr, uid, context['fiscalyear'], ['date_start'])['date_start']
|
||||||
|
fiscalyear_ids = fiscalyear_obj.search(cr, uid, [('date_stop', '<', fiscalyear_date_start), ('state', '=', 'draft')], context=context)
|
||||||
else:
|
else:
|
||||||
fiscalyear_ids = [context['fiscalyear']]
|
fiscalyear_ids = [context['fiscalyear']]
|
||||||
|
|
||||||
|
@ -50,12 +56,23 @@ class account_move_line(osv.osv):
|
||||||
where_move_lines_by_date = ''
|
where_move_lines_by_date = ''
|
||||||
|
|
||||||
if context.get('date_from', False) and context.get('date_to', False):
|
if context.get('date_from', False) and context.get('date_to', False):
|
||||||
|
if initital_bal:
|
||||||
|
where_move_lines_by_date = " AND " +obj+".move_id in ( select id from account_move where date < '"+context['date_from']+"')"
|
||||||
|
else:
|
||||||
where_move_lines_by_date = " AND " +obj+".move_id in ( select id from account_move where date >= '" +context['date_from']+"' AND date <= '"+context['date_to']+"')"
|
where_move_lines_by_date = " AND " +obj+".move_id in ( select id from account_move where date >= '" +context['date_from']+"' AND date <= '"+context['date_to']+"')"
|
||||||
|
|
||||||
if state:
|
if state:
|
||||||
if state.lower() not in ['all']:
|
if state.lower() not in ['all']:
|
||||||
where_move_state= " AND "+obj+".move_id in (select id from account_move where account_move.state = '"+state+"')"
|
where_move_state= " AND "+obj+".move_id in (select id from account_move where account_move.state = '"+state+"')"
|
||||||
|
|
||||||
|
if context.get('period_from', False) and context.get('periof_from', False) and not context.get('periods', False):
|
||||||
|
if initial_bal:
|
||||||
|
period_company_id = period_obj.browse(cr, uid, data['form']['period_from'], context=context).company_id.id
|
||||||
|
first_period = self.pool.get('account.period').search(cr, uid, [('company_id', '=', period_company_id)], order='date_start', limit=1)[0]
|
||||||
|
context['periods'] = period_obj.build_ctx_periods(cr, uid, first_period, data['form']['period_from'])
|
||||||
|
else:
|
||||||
|
context['periods'] = period_obj.build_ctx_periods(cr, uid, data['form']['period_from'], data['form']['period_to'])
|
||||||
|
|
||||||
if context.get('periods', False):
|
if context.get('periods', False):
|
||||||
ids = ','.join([str(x) for x in context['periods']])
|
ids = ','.join([str(x) for x in context['periods']])
|
||||||
query = obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s)) %s %s" % (fiscalyear_clause, ids, where_move_state, where_move_lines_by_date)
|
query = obj+".state<>'draft' AND "+obj+".period_id in (SELECT id from account_period WHERE fiscalyear_id in (%s) AND id in (%s)) %s %s" % (fiscalyear_clause, ids, where_move_state, where_move_lines_by_date)
|
||||||
|
@ -69,6 +86,8 @@ class account_move_line(osv.osv):
|
||||||
child_ids = self.pool.get('account.account')._get_children_and_consol(cr, uid, [context['chart_account_id']], context=context)
|
child_ids = self.pool.get('account.account')._get_children_and_consol(cr, uid, [context['chart_account_id']], context=context)
|
||||||
query += ' AND '+obj+'.account_id in (%s)' % ','.join(map(str, child_ids))
|
query += ' AND '+obj+'.account_id in (%s)' % ','.join(map(str, child_ids))
|
||||||
|
|
||||||
|
query += company_clause
|
||||||
|
|
||||||
if context.get('period_manner','') == 'created':
|
if context.get('period_manner','') == 'created':
|
||||||
#the query have to be build with no reference to periods but thanks to the creation date
|
#the query have to be build with no reference to periods but thanks to the creation date
|
||||||
if context.get('periods',False):
|
if context.get('periods',False):
|
||||||
|
|
|
@ -41,7 +41,9 @@ class general_ledger(rml_parse.rml_parse, common_report_header):
|
||||||
obj_move = self.pool.get('account.move.line')
|
obj_move = self.pool.get('account.move.line')
|
||||||
self.sortby = data['form'].get('sortby', 'sort_date')
|
self.sortby = data['form'].get('sortby', 'sort_date')
|
||||||
self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context',{}))
|
self.query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context',{}))
|
||||||
self.init_query = obj_move._query_get(self.cr, self.uid, obj='l', context=data['form'].get('used_context_initial_bal', {}))
|
ctx2 = data['form'].get('used_context',{}).copy()
|
||||||
|
ctx2.update({'initial_bal': True})
|
||||||
|
self.init_query = obj_move._query_get(self.cr, self.uid, obj='l', context=ctx2)
|
||||||
self.init_balance = data['form']['initial_balance']
|
self.init_balance = data['form']['initial_balance']
|
||||||
self.display_account = data['form']['display_account']
|
self.display_account = data['form']['display_account']
|
||||||
self.target_move = data['form'].get('target_move', 'all')
|
self.target_move = data['form'].get('target_move', 'all')
|
||||||
|
|
|
@ -112,29 +112,16 @@ class account_common_report(osv.osv_memory):
|
||||||
result['fiscalyear'] = 'fiscalyear_id' in data['form'] and data['form']['fiscalyear_id'] or False
|
result['fiscalyear'] = 'fiscalyear_id' in data['form'] and data['form']['fiscalyear_id'] or False
|
||||||
result['journal_ids'] = 'journal_ids' in data['form'] and data['form']['journal_ids'] or False
|
result['journal_ids'] = 'journal_ids' in data['form'] and data['form']['journal_ids'] or False
|
||||||
result['chart_account_id'] = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] or False
|
result['chart_account_id'] = 'chart_account_id' in data['form'] and data['form']['chart_account_id'] or False
|
||||||
result_initial_bal = result.copy()
|
|
||||||
if data['form']['filter'] == 'filter_date':
|
if data['form']['filter'] == 'filter_date':
|
||||||
result['date_from'] = data['form']['date_from']
|
result['date_from'] = data['form']['date_from']
|
||||||
result['date_to'] = data['form']['date_to']
|
result['date_to'] = data['form']['date_to']
|
||||||
result_initial_bal['date_from'] = '0001-01-01'
|
|
||||||
result_initial_bal['date_to'] = (datetime.datetime.strptime(data['form']['date_from'], "%Y-%m-%d") + timedelta(days=-1)).strftime('%Y-%m-%d')
|
|
||||||
elif data['form']['filter'] == 'filter_period':
|
elif data['form']['filter'] == 'filter_period':
|
||||||
if not data['form']['period_from'] or not data['form']['period_to']:
|
if not data['form']['period_from'] or not data['form']['period_to']:
|
||||||
raise osv.except_osv(_('Error'),_('Select a starting and an ending period'))
|
raise osv.except_osv(_('Error'),_('Select a starting and an ending period'))
|
||||||
company_id = period_obj.browse(cr, uid, data['form']['period_from'], context=context).company_id.id
|
|
||||||
result['periods'] = period_obj.build_ctx_periods(cr, uid, data['form']['period_from'], data['form']['period_to'])
|
result['periods'] = period_obj.build_ctx_periods(cr, uid, data['form']['period_from'], data['form']['period_to'])
|
||||||
first_period = self.pool.get('account.period').search(cr, uid, [('company_id', '=', company_id)], order='date_start', limit=1)[0]
|
return result
|
||||||
result_initial_bal['periods'] = period_obj.build_ctx_periods(cr, uid, first_period, data['form']['period_from'])
|
|
||||||
else:
|
|
||||||
if data['form']['fiscalyear_id']:
|
|
||||||
fiscal_date_start = fiscal_obj.browse(cr, uid, [data['form']['fiscalyear_id']], context=context)[0].date_start
|
|
||||||
result_initial_bal['empty_fy_allow'] = True #Improve me => there should be something generic in account.move.line -> query get
|
|
||||||
result_initial_bal['fiscalyear'] = fiscal_obj.search(cr, uid, [('date_stop', '<', fiscal_date_start), ('state', '=', 'draft')], context=context)
|
|
||||||
result_initial_bal['date_from'] = '0001-01-01'
|
|
||||||
result_initial_bal['date_to'] = (datetime.datetime.strptime(fiscal_date_start, "%Y-%m-%d") + timedelta(days=-1)).strftime('%Y-%m-%d')
|
|
||||||
return result, result_initial_bal
|
|
||||||
|
|
||||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
def _print_report(self, cr, uid, ids, data, context=None):
|
||||||
raise (_('Error'), _('not implemented'))
|
raise (_('Error'), _('not implemented'))
|
||||||
|
|
||||||
def check_report(self, cr, uid, ids, context=None):
|
def check_report(self, cr, uid, ids, context=None):
|
||||||
|
@ -145,12 +132,10 @@ class account_common_report(osv.osv_memory):
|
||||||
data['ids'] = context.get('active_ids', [])
|
data['ids'] = context.get('active_ids', [])
|
||||||
data['model'] = context.get('active_model', 'ir.ui.menu')
|
data['model'] = context.get('active_model', 'ir.ui.menu')
|
||||||
data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'fiscalyear_id', 'journal_ids', 'period_from', 'period_to', 'filter', 'chart_account_id'])[0]
|
data['form'] = self.read(cr, uid, ids, ['date_from', 'date_to', 'fiscalyear_id', 'journal_ids', 'period_from', 'period_to', 'filter', 'chart_account_id'])[0]
|
||||||
used_context, used_context_initial_bal = self._build_contexts(cr, uid, ids, data, context=context)
|
used_context = self._build_contexts(cr, uid, ids, data, context=context)
|
||||||
query_line = obj_move._query_get(cr, uid, obj='l', context=used_context)
|
|
||||||
data['form']['periods'] = used_context.get('periods', False) and used_context['periods'] or []
|
data['form']['periods'] = used_context.get('periods', False) and used_context['periods'] or []
|
||||||
data['form']['used_context'] = used_context
|
data['form']['used_context'] = used_context
|
||||||
data['form']['used_context_initial_bal'] = used_context_initial_bal
|
return self._print_report(cr, uid, ids, data, context=context)
|
||||||
return self._print_report(cr, uid, ids, data, query_line, context=context)
|
|
||||||
|
|
||||||
account_common_report()
|
account_common_report()
|
||||||
|
|
||||||
|
|
|
@ -35,7 +35,7 @@ class account_common_account_report(osv.osv_memory):
|
||||||
'display_account': 'bal_all',
|
'display_account': 'bal_all',
|
||||||
}
|
}
|
||||||
|
|
||||||
def pre_print_report(self, cr, uid, ids, data, query_line, context=None):
|
def pre_print_report(self, cr, uid, ids, data, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
data['form'].update(self.read(cr, uid, ids, ['display_account'])[0])
|
data['form'].update(self.read(cr, uid, ids, ['display_account'])[0])
|
||||||
|
|
|
@ -49,10 +49,10 @@ class account_report_general_ledger(osv.osv_memory):
|
||||||
res['value'] = {'initial_balance': False}
|
res['value'] = {'initial_balance': False}
|
||||||
return res
|
return res
|
||||||
|
|
||||||
def _print_report(self, cr, uid, ids, data, query_line, context=None):
|
def _print_report(self, cr, uid, ids, data, context=None):
|
||||||
if context is None:
|
if context is None:
|
||||||
context = {}
|
context = {}
|
||||||
data = self.pre_print_report(cr, uid, ids, data, query_line, context=context)
|
data = self.pre_print_report(cr, uid, ids, data, context=context)
|
||||||
data['form'].update(self.read(cr, uid, ids, ['landscape', 'initial_balance', 'amount_currency', 'sortby', 'target_move'])[0])
|
data['form'].update(self.read(cr, uid, ids, ['landscape', 'initial_balance', 'amount_currency', 'sortby', 'target_move'])[0])
|
||||||
if not data['form']['fiscalyear_id']:# GTK client problem onchange does not consider in save record
|
if not data['form']['fiscalyear_id']:# GTK client problem onchange does not consider in save record
|
||||||
data['form'].update({'initial_balance': False})
|
data['form'].update({'initial_balance': False})
|
||||||
|
|
Loading…
Reference in New Issue