[REF] account: some code refactoring + fix for multi company
bzr revid: qdp-launchpad@tinyerp.com-20100928090638-smdqvhifn7upcz9r
This commit is contained in:
parent
c98b0949e5
commit
43a242a083
|
@ -931,6 +931,19 @@ class account_period(osv.osv):
|
|||
raise osv.except_osv(_('Warning !'), _('You cannot modify company of this period as its related record exist in Entry Lines'))
|
||||
return super(account_period, self).write(cr, uid, ids, vals, context=context)
|
||||
|
||||
def build_ctx_periods(self, cr, uid, period_from_id, period_to_id):
|
||||
period_from = self.browse(cr, uid, period_from_id)
|
||||
period_date_start = period_from.date_start
|
||||
company1_id = period_from.company_id.id
|
||||
period_to = self.browse(cr, uid, period_to_id)
|
||||
period_date_stop = period_to.date_stop
|
||||
company2_id = period_to.company_id.id
|
||||
if company1_id != company2_id:
|
||||
raise osv.except_osv(_('Error'), _('You should have chosen periods that belongs to the same company'))
|
||||
if period_date_start > period_date_stop:
|
||||
raise osv.except_osv(_('Error'), _('Start period should be smaller then End period'))
|
||||
return self.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop), ('company_id', '=', company1_id)])
|
||||
|
||||
account_period()
|
||||
|
||||
class account_journal_period(osv.osv):
|
||||
|
|
|
@ -44,14 +44,6 @@ class account_chart(osv.osv_memory):
|
|||
fiscalyears = self.pool.get('account.fiscalyear').search(cr, uid, [('date_start', '<', now), ('date_stop', '>', now)], limit=1 )
|
||||
return fiscalyears and fiscalyears[0] or False
|
||||
|
||||
def _build_periods(self, cr, uid, period_from, period_to):
|
||||
period_obj = self.pool.get('account.period')
|
||||
period_date_start = period_obj.read(cr, uid, period_from, ['date_start'])['date_start']
|
||||
period_date_stop = period_obj.read(cr, uid, period_to, ['date_stop'])['date_stop']
|
||||
if period_date_start > period_date_stop:
|
||||
raise osv.except_osv(_('Error'),_('Start period should be smaller then End period'))
|
||||
return period_obj.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop)])
|
||||
|
||||
def onchange_fiscalyear(self, cr, uid, ids, fiscalyear_id=False, context=None):
|
||||
res = {}
|
||||
res['value'] = {}
|
||||
|
@ -95,9 +87,9 @@ class account_chart(osv.osv_memory):
|
|||
result = mod_obj._get_id(cr, uid, 'account', 'action_account_tree')
|
||||
id = mod_obj.read(cr, uid, [result], ['res_id'], context=context)[0]['res_id']
|
||||
result = act_obj.read(cr, uid, [id], context=context)[0]
|
||||
result['periods'] = []
|
||||
result['periods'] = []
|
||||
if data['period_from'] and data['period_to']:
|
||||
result['periods'] = self._build_periods(cr, uid, data['period_from'], data['period_to'])
|
||||
result['periods'] = self.pool.get('account.period').build_ctx_periods(cr, uid, data['period_from'], data['period_to'])
|
||||
result['context'] = str({'fiscalyear': data['fiscalyear'], 'periods': result['periods'], \
|
||||
'state': data['target_move']})
|
||||
if data['fiscalyear']:
|
||||
|
@ -111,4 +103,4 @@ class account_chart(osv.osv_memory):
|
|||
|
||||
account_chart()
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
|
|
@ -103,14 +103,6 @@ class account_common_report(osv.osv_memory):
|
|||
'chart_account_id': _get_account,
|
||||
}
|
||||
|
||||
def _build_periods(self, cr, uid, period_from, period_to):
|
||||
period_obj = self.pool.get('account.period')
|
||||
period_date_start = period_obj.read(cr, uid, period_from, ['date_start'])['date_start']
|
||||
period_date_stop = period_obj.read(cr, uid, period_to, ['date_stop'])['date_stop']
|
||||
if period_date_start > period_date_stop:
|
||||
raise osv.except_osv(_('Error'),_('Start period should be smaller then End period'))
|
||||
return period_obj.search(cr, uid, [('date_start', '>=', period_date_start), ('date_stop', '<=', period_date_stop)])
|
||||
|
||||
def _build_contexts(self, cr, uid, ids, data, context=None):
|
||||
if context is None:
|
||||
context = {}
|
||||
|
@ -129,9 +121,10 @@ class account_common_report(osv.osv_memory):
|
|||
elif data['form']['filter'] == 'filter_period':
|
||||
if not data['form']['period_from'] or not data['form']['period_to']:
|
||||
raise osv.except_osv(_('Error'),_('Select a starting and an ending period'))
|
||||
result['periods'] = self._build_periods(cr, uid, data['form']['period_from'], data['form']['period_to'])
|
||||
first_period = self.pool.get('account.period').search(cr, uid, [], order='date_start', limit=1)[0]
|
||||
result_initial_bal['periods'] = self._build_periods(cr, uid, first_period, data['form']['period_from'])
|
||||
company_id = period_obj.browse(cr, uid, data['form']['period_from'], context=context).company_id
|
||||
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]
|
||||
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
|
||||
|
|
Loading…
Reference in New Issue