[IMP] account_report:-code cleaning

bzr revid: mtr@mtr-20101012050527-f8gupk33laaaer3f
This commit is contained in:
mtr
2010-10-12 10:35:27 +05:30
parent 21cb64c24b
commit 95ebd8826d
+46 -46
View File
@@ -32,18 +32,18 @@ class account_report(osv.osv):
_description = "Account Reporting"
def _amount_get(self, cr, uid, ids, field_name, arg, context={}):
obj_fy=self.pool.get('account.fiscalyear')
obj_period=self.pool.get('account.period')
obj_fy = self.pool.get('account.fiscalyear')
obj_period = self.pool.get('account.period')
def _calc_context(key,obj):
if key==0:
def _calc_context(key, obj):
if key == 0:
return obj.find(cr, uid, exception=False)
else:
obj_key=obj.browse(cr, uid, obj.find(cr, uid, exception=False))
if isinstance(obj_key,list):
obj_key=obj_key[0]
key_ids=obj.search(cr,uid,[('date_stop','<',obj_key.date_start)])
if len(key_ids)<abs(key):
obj_key = obj.browse(cr, uid, obj.find(cr, uid, exception=False))
if isinstance(obj_key, list):
obj_key = obj_key[0]
key_ids = obj.search(cr, uid, [('date_stop','<',obj_key.date_start)])
if len(key_ids) < abs(key):
return False
return key_ids[key]
@@ -53,18 +53,18 @@ class account_report(osv.osv):
del context['fiscalyear']
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.credit+y, acc.browse(cr, uid, acc_id, context),0.0)
return reduce(lambda y, x=0: x.credit+y, acc.browse(cr, uid, acc_id, context),0.0)
def _calc_debit(code,year=0):
context['fiscalyear']=_calc_context(year, obj_fy)
def _calc_debit(code, year=0):
context['fiscalyear'] = _calc_context(year, obj_fy)
if not context['fiscalyear']:
del context['fiscalyear']
acc = self.pool.get('account.account')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.debit+y, acc.browse(cr, uid, acc_id, context),0.0)
return reduce(lambda y, x=0: x.debit+y, acc.browse(cr, uid, acc_id, context), 0.0)
def _calc_balance(code,year=0):
context['fiscalyear']=_calc_context(year, obj_fy)
def _calc_balance(code, year=0):
context['fiscalyear'] = _calc_context(year, obj_fy)
if not context['fiscalyear']:
del context['fiscalyear']
acc = self.pool.get('account.account')
@@ -72,21 +72,21 @@ class account_report(osv.osv):
for c in code:
for i in c.split('-'):
account_ids += acc.search(cr, uid, [('code', 'ilike', i)])
return reduce(lambda y,x=0: x.balance+y, acc.browse(cr, uid, account_ids, context),0.0)
return reduce(lambda y, x=0: x.balance+y, acc.browse(cr, uid, account_ids, context), 0.0)
def _calc_report(*code):
acc = self.pool.get('account.report.report')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.amount+y, acc.browse(cr, uid, acc_id, context),0.0)
acc_id = acc.search(cr, uid, [('code', 'in', code)])
return reduce(lambda y, x=0: x.amount+y, acc.browse(cr, uid, acc_id, context),0.0)
def _calc_tax_code(code,period=0):
context['period_id']=_calc_context(period, obj_period)
def _calc_tax_code(code, period=0):
context['period_id'] = _calc_context(period, obj_period)
if not context['period_id']:
return 0.00
context['period_id']=context['period_id'][0]
context['period_id'] = context['period_id'][0]
acc = self.pool.get('account.tax.code')
acc_id = acc.search(cr, uid, [('code','in',code)])
return reduce(lambda y,x=0: x.sum_period+y, acc.browse(cr, uid, acc_id, context),0.0)
acc_id = acc.search(cr, uid, [('code', 'in', code)])
return reduce(lambda y, x=0: x.sum_period+y, acc.browse(cr, uid, acc_id, context), 0.0)
result = {}
for rep in self.browse(cr, uid, ids, context):
objdict = {
@@ -97,18 +97,18 @@ class account_report(osv.osv):
'tax_code': _calc_tax_code,
}
try:
val = eval(getattr(rep,'expression'), objdict)
val = eval(getattr(rep, 'expression'), objdict)
except:
val = 0.0
if field_name=='status':
if val<rep.badness_limit:
if field_name == 'status':
if val < rep.badness_limit:
result[rep.id] = 'very bad'
elif val==rep.badness_limit:
elif val == rep.badness_limit:
result[rep.id] = 'bad'
elif val<rep.goodness_limit:
result[rep.id] = 'normal'
elif val==rep.goodness_limit:
elif val == rep.goodness_limit:
result[rep.id] = 'good'
else:
result[rep.id] = 'very good'
@@ -117,10 +117,10 @@ class account_report(osv.osv):
return result
def onchange_parent_id(self, cr, uid, ids, parent_id):
v={}
v = {}
if parent_id:
acc=self.pool.get('account.report.report').browse(cr, uid, parent_id)
v['type']=acc.type
acc = self.pool.get('account.report.report').browse(cr, uid, parent_id)
v['type'] = acc.type
return {'value': v}
_columns = {
@@ -135,8 +135,8 @@ class account_report(osv.osv):
('other','Others')],
'Type', required=True),
'expression': fields.char('Expression', size=240, required=True),
'badness_limit' :fields.float('Badness Indicator Limit', digits=(16,2), help='This Value sets the limit of badness.'),
'goodness_limit' :fields.float('Goodness Indicator Limit', digits=(16,2), help='This Value sets the limit of goodness.'),
'badness_limit': fields.float('Badness Indicator Limit', digits=(16,2), help='This Value sets the limit of badness.'),
'goodness_limit': fields.float('Goodness Indicator Limit', digits=(16,2), help='This Value sets the limit of goodness.'),
'parent_id': fields.many2one('account.report.report', 'Parent'),
'child_ids': fields.one2many('account.report.report', 'parent_id', 'Children'),
'note': fields.text('Note'),
@@ -152,8 +152,8 @@ class account_report(osv.osv):
('very good', 'Very Good')
],
string='Status'),
'disp_tree':fields.boolean('Display Tree', help='When the indicators are printed, if one indicator is set with this field to True, then it will display one more graphs with all its children in tree'),
'disp_graph':fields.boolean('Display As Graph', help='If the field is set to True, information will be printed as a Graph, otherwise as an array.'),
'disp_tree': fields.boolean('Display Tree', help='When the indicators are printed, if one indicator is set with this field to True, then it will display one more graphs with all its children in tree'),
'disp_graph': fields.boolean('Display As Graph', help='If the field is set to True, information will be printed as a Graph, otherwise as an array.'),
}
_defaults = {
'active': lambda *args: True,
@@ -162,9 +162,9 @@ class account_report(osv.osv):
def name_search(self, cr, user, name, args=None, operator='ilike', context=None, limit=100):
if not args:
args=[]
args = []
if not context:
context={}
context = {}
ids = []
if name:
ids = self.search(cr, user, [('code','=',name)]+ args, limit=limit, context=context)
@@ -183,12 +183,12 @@ account_report()
class account_report_history(osv.osv):
def _calc_value(self, cr, uid, ids, name, args, context):
acc_report_id=self.read(cr, uid, ids, ['tmp','period_id'])
tmp_ids={}
acc_report_id = self.read(cr, uid, ids, ['tmp','period_id'])
tmp_ids = {}
for a in acc_report_id:
period_val=pooler.get_pool(cr.dbname).get('account.period').read(cr, uid, [a['period_id'][0]])[0]
period_id=pooler.get_pool(cr.dbname).get('account.period').search(cr, uid, [('date_start','<=',period_val['date_start']),('fiscalyear_id','=',period_val['fiscalyear_id'][0])])
tmp_ids[a['id']] = pooler.get_pool(cr.dbname).get('account.report.report').read(cr, uid, [a['tmp']], context={'periods':period_id})[0]['amount']
period_val = pooler.get_pool(cr.dbname).get('account.period').read(cr, uid, [a['period_id'][0]])[0]
period_id = pooler.get_pool(cr.dbname).get('account.period').search(cr, uid, [('date_start', '<=', period_val['date_start']),('fiscalyear_id', '=', period_val['fiscalyear_id'][0])])
tmp_ids[a['id']] = pooler.get_pool(cr.dbname).get('account.report.report').read(cr, uid, [a['tmp']], context={'periods': period_id})[0]['amount']
return tmp_ids
_name = "account.report.history"
@@ -197,11 +197,11 @@ class account_report_history(osv.osv):
_auto = False
_order='name'
_columns = {
'period_id': fields.many2one('account.period','Period', readonly=True, select=True),
'fiscalyear_id': fields.many2one('account.fiscalyear','Fiscal Year', readonly=True, select=True),
'name': fields.many2one('account.report.report','Indicator', readonly=True, select=True),
'period_id': fields.many2one('account.period', 'Period', readonly=True, select=True),
'fiscalyear_id': fields.many2one('account.fiscalyear', 'Fiscal Year', readonly=True, select=True),
'name': fields.many2one('account.report.report', 'Indicator', readonly=True, select=True),
'val': fields.function(_calc_value, method=True, string='Value', readonly=True),
'tmp' : fields.integer(string='temp',readonly=True)
'tmp' : fields.integer(string='temp', readonly=True)
}
def init(self, cr):