[IMP] account_budget: Code cleaning
[FIX] account_payment, account_coda, l10n_ch: lines got wrong value when using invoice with payment terms bzr revid: psi@tinyerp.co.in-20100929125108-pyb29e9hujuk03rw
This commit is contained in:
parent
b1a47eb187
commit
33d62323f1
|
@ -26,9 +26,8 @@
|
|||
'category': 'Generic Modules/Accounting',
|
||||
'description': """This module allows accountants to manage analytic and crossovered budgets.
|
||||
|
||||
Once the Master Budgets and the Budgets are defined (in Financial
|
||||
Management/Budgets/), the Project Managers can set the planned amount on each
|
||||
Analytic Account.
|
||||
Once the Master Budgets and the Budgets are defined (in Accounting/Budgets/),
|
||||
the Project Managers can set the planned amount on each Analytic Account.
|
||||
|
||||
The accountant has the possibility to see the total of amount planned for each
|
||||
Budget and Master Budget in order to ensure the total planned is not
|
||||
|
|
|
@ -49,12 +49,13 @@ class account_budget_post(osv.osv):
|
|||
|
||||
def spread(self, cr, uid, ids, fiscalyear_id=False, amount=0.0):
|
||||
dobj = self.pool.get('account.budget.post.dotation')
|
||||
obj_fiscalyear = self.pool.get('account.fiscalyear')
|
||||
for o in self.browse(cr, uid, ids):
|
||||
# delete dotations for this post
|
||||
dobj.unlink(cr, uid, dobj.search(cr, uid, [('post_id','=',o.id)]))
|
||||
|
||||
# create one dotation per period in the fiscal year, and spread the total amount/quantity over those dotations
|
||||
fy = self.pool.get('account.fiscalyear').browse(cr, uid, [fiscalyear_id])[0]
|
||||
fy = obj_fiscalyear.browse(cr, uid, [fiscalyear_id])[0]
|
||||
num = len(fy.period_ids)
|
||||
for p in fy.period_ids:
|
||||
dobj.create(cr, uid, {'post_id': o.id, 'period_id': p.id, 'amount': amount/num})
|
||||
|
@ -64,26 +65,27 @@ account_budget_post()
|
|||
|
||||
class account_budget_post_dotation(osv.osv):
|
||||
def _tot_planned(self, cr, uid, ids, name, args, context):
|
||||
obj_budget_lines = self.pool.get('crossovered.budget.lines')
|
||||
res = {}
|
||||
for line in self.browse(cr, uid, ids):
|
||||
if line.period_id:
|
||||
obj_period=self.pool.get('account.period').browse(cr, uid, line.period_id.id)
|
||||
obj_period = self.pool.get('account.period').browse(cr, uid, line.period_id.id)
|
||||
|
||||
total_days=strToDate(obj_period.date_stop) - strToDate(obj_period.date_start)
|
||||
budget_id=line.post_id and line.post_id.id or False
|
||||
query="select id from crossovered_budget_lines where \
|
||||
general_budget_id= %s AND (date_from >=%s and date_from <= %s ) \
|
||||
OR (date_to >=%s and date_to <= %s) OR (date_from < %s and date_to > %s)"
|
||||
cr.execute(query,(budget_id,obj_period.date_start,obj_period.date_stop,obj_period.date_start,obj_period.date_stop,obj_period.date_start,obj_period.date_stop,))
|
||||
res1=cr.fetchall()
|
||||
tot_planned=0.00
|
||||
total_days = strToDate(obj_period.date_stop) - strToDate(obj_period.date_start)
|
||||
budget_id = line.post_id and line.post_id.id or False
|
||||
query="SELECT id FROM crossovered_budget_lines WHERE \
|
||||
general_budget_id= %s AND (date_from >=%s AND date_from <= %s ) \
|
||||
OR (date_to >=%s AND date_to <= %s) OR (date_from < %s AND date_to > %s)"
|
||||
cr.execute(query, (budget_id, obj_period.date_start, obj_period.date_stop, obj_period.date_start, obj_period.date_stop, obj_period.date_start, obj_period.date_stop,))
|
||||
res1 = cr.fetchall()
|
||||
tot_planned = 0.00
|
||||
for record in res1:
|
||||
obj_lines = self.pool.get('crossovered.budget.lines').browse(cr, uid, record[0])
|
||||
count_days = min(strToDate(obj_period.date_stop),strToDate(obj_lines.date_to)) - max(strToDate(obj_period.date_start), strToDate(obj_lines.date_from))
|
||||
days_in_period = count_days.days +1
|
||||
obj_lines = obj_budget_lines.browse(cr, uid, record[0])
|
||||
count_days = min(strToDate(obj_period.date_stop), strToDate(obj_lines.date_to)) - max(strToDate(obj_period.date_start), strToDate(obj_lines.date_from))
|
||||
days_in_period = count_days.days + 1
|
||||
count_days = strToDate(obj_lines.date_to) - strToDate(obj_lines.date_from)
|
||||
total_days_of_rec = count_days.days +1
|
||||
tot_planned += obj_lines.planned_amount/total_days_of_rec* days_in_period
|
||||
total_days_of_rec = count_days.days + 1
|
||||
tot_planned += obj_lines.planned_amount / total_days_of_rec * days_in_period
|
||||
res[line.id] = tot_planned
|
||||
else:
|
||||
res[line.id] = 0.00
|
||||
|
@ -96,7 +98,7 @@ class account_budget_post_dotation(osv.osv):
|
|||
'post_id': fields.many2one('account.budget.post', 'Item', select=True),
|
||||
'period_id': fields.many2one('account.period', 'Period'),
|
||||
'amount': fields.float('Amount', digits=(16,2)),
|
||||
'tot_planned':fields.function(_tot_planned, method=True, string='Total Planned Amount', type='float', store=True),
|
||||
'tot_planned': fields.function(_tot_planned, method=True, string='Total Planned Amount', type='float', store=True),
|
||||
}
|
||||
|
||||
account_budget_post_dotation()
|
||||
|
@ -119,38 +121,38 @@ class crossovered_budget(osv.osv):
|
|||
|
||||
_defaults = {
|
||||
'state': 'draft',
|
||||
'creating_user_id': lambda self,cr,uid,context: uid,
|
||||
'company_id': lambda self,cr,uid,c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.budget.post', context=c)
|
||||
'creating_user_id': lambda self, cr, uid, context: uid,
|
||||
'company_id': lambda self, cr, uid, c: self.pool.get('res.company')._company_default_get(cr, uid, 'account.budget.post', context=c)
|
||||
}
|
||||
|
||||
def budget_confirm(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {
|
||||
'state':'confirm'
|
||||
'state': 'confirm'
|
||||
})
|
||||
return True
|
||||
|
||||
def budget_draft(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {
|
||||
'state':'draft'
|
||||
'state': 'draft'
|
||||
})
|
||||
return True
|
||||
|
||||
def budget_validate(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {
|
||||
'state':'validate',
|
||||
'state': 'validate',
|
||||
'validating_user_id': uid,
|
||||
})
|
||||
return True
|
||||
|
||||
def budget_cancel(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {
|
||||
'state':'cancel'
|
||||
'state': 'cancel'
|
||||
})
|
||||
return True
|
||||
|
||||
def budget_done(self, cr, uid, ids, *args):
|
||||
self.write(cr, uid, ids, {
|
||||
'state':'done'
|
||||
'state': 'done'
|
||||
})
|
||||
return True
|
||||
|
||||
|
@ -158,7 +160,7 @@ crossovered_budget()
|
|||
|
||||
class crossovered_budget_lines(osv.osv):
|
||||
|
||||
def _prac_amt(self, cr, uid, ids,context={}):
|
||||
def _prac_amt(self, cr, uid, ids, context={}):
|
||||
res = {}
|
||||
for line in self.browse(cr, uid, ids):
|
||||
acc_ids = [x.id for x in line.general_budget_id.account_ids]
|
||||
|
@ -170,8 +172,8 @@ class crossovered_budget_lines(osv.osv):
|
|||
date_from = context['wizard_date_from']
|
||||
if context.has_key('wizard_date_to'):
|
||||
date_to = context['wizard_date_to']
|
||||
cr.execute("select sum(amount) from account_analytic_line where account_id=%s and (date "
|
||||
"between to_date(%s,'yyyy-mm-dd') and to_date(%s,'yyyy-mm-dd')) and "
|
||||
cr.execute("SELECT SUM(amount) FROM account_analytic_line WHERE account_id=%s AND (date "
|
||||
"between to_date(%s,'yyyy-mm-dd') AND to_date(%s,'yyyy-mm-dd')) AND "
|
||||
"general_account_id=ANY(%s)", (line.analytic_account_id.id, date_from, date_to,acc_ids,))
|
||||
result = cr.fetchone()[0]
|
||||
if result is None:
|
||||
|
@ -182,13 +184,13 @@ class crossovered_budget_lines(osv.osv):
|
|||
def _prac(self, cr, uid, ids, name, args, context):
|
||||
res={}
|
||||
for line in self.browse(cr, uid, ids):
|
||||
res[line.id]=self._prac_amt(cr, uid, [line.id], context=context)[line.id]
|
||||
res[line.id] = self._prac_amt(cr, uid, [line.id], context=context)[line.id]
|
||||
return res
|
||||
|
||||
def _theo_amt(self, cr, uid, ids,context={}):
|
||||
def _theo_amt(self, cr, uid, ids, context={}):
|
||||
res = {}
|
||||
for line in self.browse(cr, uid, ids):
|
||||
today=datetime.datetime.today()
|
||||
today = datetime.datetime.today()
|
||||
date_to = today.strftime("%Y-%m-%d")
|
||||
date_from = line.date_from
|
||||
if context.has_key('wizard_date_from'):
|
||||
|
@ -197,38 +199,37 @@ class crossovered_budget_lines(osv.osv):
|
|||
date_to = context['wizard_date_to']
|
||||
|
||||
if line.paid_date:
|
||||
if strToDate(line.date_to)<=strToDate(line.paid_date):
|
||||
theo_amt=0.00
|
||||
if strToDate(line.date_to) <= strToDate(line.paid_date):
|
||||
theo_amt = 0.00
|
||||
else:
|
||||
theo_amt=line.planned_amount
|
||||
theo_amt = line.planned_amount
|
||||
else:
|
||||
total=strToDate(line.date_to) - strToDate(line.date_from)
|
||||
total = strToDate(line.date_to) - strToDate(line.date_from)
|
||||
elapsed = min(strToDate(line.date_to),strToDate(date_to)) - max(strToDate(line.date_from),strToDate(date_from))
|
||||
if strToDate(date_to) < strToDate(line.date_from):
|
||||
elapsed = strToDate(date_to) - strToDate(date_to)
|
||||
|
||||
if total.days:
|
||||
theo_amt = float(elapsed.days/float(total.days))*line.planned_amount
|
||||
theo_amt = float(elapsed.days / float(total.days)) * line.planned_amount
|
||||
else:
|
||||
theo_amt = line.planned_amount
|
||||
|
||||
res[line.id]=theo_amt
|
||||
res[line.id] = theo_amt
|
||||
return res
|
||||
|
||||
def _theo(self, cr, uid, ids, name, args, context):
|
||||
res={}
|
||||
res = {}
|
||||
for line in self.browse(cr, uid, ids):
|
||||
res[line.id]=self._theo_amt(cr, uid, [line.id], context=context)[line.id]
|
||||
|
||||
res[line.id] = self._theo_amt(cr, uid, [line.id], context=context)[line.id]
|
||||
return res
|
||||
|
||||
def _perc(self, cr, uid, ids, name, args, context):
|
||||
res = {}
|
||||
for line in self.browse(cr, uid, ids):
|
||||
if line.theoritical_amount<>0.00:
|
||||
res[line.id]=float(line.practical_amount or 0.0 / line.theoritical_amount)*100
|
||||
if line.theoritical_amount <> 0.00:
|
||||
res[line.id] = float(line.practical_amount or 0.0 / line.theoritical_amount) * 100
|
||||
else:
|
||||
res[line.id]=0.00
|
||||
res[line.id] = 0.00
|
||||
return res
|
||||
|
||||
_name = "crossovered.budget.lines"
|
||||
|
@ -240,10 +241,10 @@ class crossovered_budget_lines(osv.osv):
|
|||
'date_from': fields.date('Start Date', required=True),
|
||||
'date_to': fields.date('End Date', required=True),
|
||||
'paid_date': fields.date('Paid Date'),
|
||||
'planned_amount':fields.float('Planned Amount', required=True, digits=(16,2)),
|
||||
'practical_amount':fields.function(_prac, method=True, string='Practical Amount', type='float', digits=(16,2)),
|
||||
'theoritical_amount':fields.function(_theo, method=True, string='Theoritical Amount', type='float', digits=(16,2)),
|
||||
'percentage':fields.function(_perc, method=True, string='Percentage', type='float'),
|
||||
'planned_amount': fields.float('Planned Amount', required=True, digits=(16,2)),
|
||||
'practical_amount': fields.function(_prac, method=True, string='Practical Amount', type='float', digits=(16,2)),
|
||||
'theoritical_amount': fields.function(_theo, method=True, string='Theoritical Amount', type='float', digits=(16,2)),
|
||||
'percentage': fields.function(_perc, method=True, string='Percentage', type='float'),
|
||||
'company_id': fields.related('crossovered_budget_id', 'company_id', type='many2one', relation='res.company', string='Company', store=True, readonly=True)
|
||||
}
|
||||
|
||||
|
|
|
@ -33,47 +33,43 @@ class analytic_account_budget_report(report_sxw.rml_parse):
|
|||
'funct_total': self.funct_total,
|
||||
'time': time,
|
||||
})
|
||||
self.context=context
|
||||
|
||||
def funct(self,object,form,ids={}, done=None, level=1):
|
||||
self.context = context
|
||||
|
||||
def funct(self, object, form, ids={}, done=None, level=1):
|
||||
if not ids:
|
||||
ids = self.ids
|
||||
if not done:
|
||||
done={}
|
||||
done = {}
|
||||
|
||||
global tot
|
||||
tot={
|
||||
tot = {
|
||||
'theo':0.00,
|
||||
'pln':0.00,
|
||||
'prac':0.00,
|
||||
'perc':0.00
|
||||
}
|
||||
result=[]
|
||||
result = []
|
||||
accounts = self.pool.get('account.analytic.account').browse(self.cr, self.uid, [object.id], self.context.copy())
|
||||
c_b_lines_obj = self.pool.get('crossovered.budget.lines')
|
||||
obj_c_budget = self.pool.get('crossovered.budget')
|
||||
|
||||
c_b_lines_obj=self.pool.get('crossovered.budget.lines')
|
||||
for account_id in accounts:
|
||||
res={}
|
||||
b_line_ids=[]
|
||||
|
||||
res = {}
|
||||
b_line_ids = []
|
||||
for line in account_id.crossovered_budget_line:
|
||||
b_line_ids.append(line.id)
|
||||
|
||||
if not b_line_ids:
|
||||
return []
|
||||
d_from = form['date_from']
|
||||
d_to = form['date_to']
|
||||
|
||||
d_from=form['date_from']
|
||||
d_to=form['date_to']
|
||||
self.cr.execute('SELECT DISTINCT(crossovered_budget_id) FROM crossovered_budget_lines WHERE id =ANY(%s)',(b_line_ids,))
|
||||
budget_ids = self.cr.fetchall()
|
||||
|
||||
self.cr.execute('select distinct(crossovered_budget_id) from crossovered_budget_lines where id =ANY(%s)',(b_line_ids,))
|
||||
budget_ids=self.cr.fetchall()
|
||||
|
||||
context={'wizard_date_from':d_from,'wizard_date_to':d_to}
|
||||
for i in range(0,len(budget_ids)):
|
||||
|
||||
budget_name=self.pool.get('crossovered.budget').browse(self.cr, self.uid,[budget_ids[i][0]])
|
||||
res={
|
||||
context = {'wizard_date_from':d_from,'wizard_date_to':d_to}
|
||||
for i in range(0, len(budget_ids)):
|
||||
budget_name = obj_c_budget.browse(self.cr, self.uid, [budget_ids[i][0]])
|
||||
res= {
|
||||
'b_id':'-1',
|
||||
'a_id':'-1',
|
||||
'name':budget_name[0].name,
|
||||
|
@ -85,48 +81,42 @@ class analytic_account_budget_report(report_sxw.rml_parse):
|
|||
}
|
||||
result.append(res)
|
||||
|
||||
line_ids = c_b_lines_obj.search(self.cr, self.uid, [('id', 'in', b_line_ids),('crossovered_budget_id','=',budget_ids[i][0])])
|
||||
line_id =c_b_lines_obj.browse(self.cr,self.uid,line_ids)
|
||||
tot_theo=tot_pln=tot_prac=tot_perc=0
|
||||
line_ids = c_b_lines_obj.search(self.cr, self.uid, [('id', 'in', b_line_ids), ('crossovered_budget_id','=',budget_ids[i][0])])
|
||||
line_id = c_b_lines_obj.browse(self.cr, self.uid, line_ids)
|
||||
tot_theo = tot_pln = tot_prac = tot_perc = 0
|
||||
|
||||
done_budget=[]
|
||||
done_budget = []
|
||||
for line in line_id:
|
||||
|
||||
if line.id in b_line_ids:
|
||||
theo=pract=0.00
|
||||
theo=c_b_lines_obj._theo_amt(self.cr, self.uid, [line.id],context)[line.id]
|
||||
pract=c_b_lines_obj._prac_amt(self.cr, self.uid, [line.id],context)[line.id]
|
||||
|
||||
theo = pract = 0.00
|
||||
theo = c_b_lines_obj._theo_amt(self.cr, self.uid, [line.id], context)[line.id]
|
||||
pract = c_b_lines_obj._prac_amt(self.cr, self.uid, [line.id], context)[line.id]
|
||||
if line.general_budget_id.id in done_budget:
|
||||
|
||||
for record in result:
|
||||
if record['b_id']==line.general_budget_id.id and record['a_id']==line.analytic_account_id.id:
|
||||
|
||||
record['theo'] +=theo
|
||||
record['pln'] +=line.planned_amount
|
||||
record['prac'] +=pract
|
||||
record['perc'] +=line.percentage
|
||||
tot_theo +=theo
|
||||
tot_pln +=line.planned_amount
|
||||
tot_prac +=pract
|
||||
tot_perc +=line.percentage
|
||||
if record['b_id'] == line.general_budget_id.id and record['a_id'] == line.analytic_account_id.id:
|
||||
record['theo'] += theo
|
||||
record['pln'] += line.planned_amount
|
||||
record['prac'] += pract
|
||||
record['perc'] += line.percentage
|
||||
tot_theo += theo
|
||||
tot_pln += line.planned_amount
|
||||
tot_prac += pract
|
||||
tot_perc += line.percentage
|
||||
else:
|
||||
|
||||
res1={
|
||||
'b_id':line.general_budget_id.id,
|
||||
'a_id':line.analytic_account_id.id,
|
||||
'name':line.general_budget_id.name,
|
||||
'status':2,
|
||||
'theo':theo,
|
||||
'pln':line.planned_amount,
|
||||
'prac':pract,
|
||||
'perc':line.percentage
|
||||
res1 = {
|
||||
'b_id': line.general_budget_id.id,
|
||||
'a_id': line.analytic_account_id.id,
|
||||
'name': line.general_budget_id.name,
|
||||
'status': 2,
|
||||
'theo': theo,
|
||||
'pln': line.planned_amount,
|
||||
'prac': pract,
|
||||
'perc': line.percentage
|
||||
}
|
||||
|
||||
tot_theo += theo
|
||||
tot_pln +=line.planned_amount
|
||||
tot_prac +=pract
|
||||
tot_perc +=line.percentage
|
||||
tot_pln += line.planned_amount
|
||||
tot_prac += pract
|
||||
tot_perc += line.percentage
|
||||
result.append(res1)
|
||||
done_budget.append(line.general_budget_id.id)
|
||||
else:
|
||||
|
@ -134,50 +124,45 @@ class analytic_account_budget_report(report_sxw.rml_parse):
|
|||
continue
|
||||
else:
|
||||
res1={
|
||||
'b_id':line.general_budget_id.id,
|
||||
'a_id':line.analytic_account_id.id,
|
||||
'name':line.general_budget_id.name,
|
||||
'status':2,
|
||||
'theo':0.00,
|
||||
'pln':0.00,
|
||||
'prac':0.00,
|
||||
'perc':0.00
|
||||
'b_id': line.general_budget_id.id,
|
||||
'a_id': line.analytic_account_id.id,
|
||||
'name': line.general_budget_id.name,
|
||||
'status': 2,
|
||||
'theo': 0.00,
|
||||
'pln': 0.00,
|
||||
'prac': 0.00,
|
||||
'perc': 0.00
|
||||
}
|
||||
|
||||
result.append(res1)
|
||||
done_budget.append(line.general_budget_id.id)
|
||||
|
||||
if tot_theo==0.00:
|
||||
tot_perc=0.00
|
||||
if tot_theo == 0.00:
|
||||
tot_perc = 0.00
|
||||
else:
|
||||
tot_perc=float(tot_prac /tot_theo)*100
|
||||
tot_perc = float(tot_prac / tot_theo) * 100
|
||||
|
||||
result[-(len(done_budget) +1)]['theo']=tot_theo
|
||||
result[-(len(done_budget) +1)]['theo'] = tot_theo
|
||||
tot['theo'] +=tot_theo
|
||||
result[-(len(done_budget) +1)]['pln']=tot_pln
|
||||
result[-(len(done_budget) +1)]['pln'] = tot_pln
|
||||
tot['pln'] +=tot_pln
|
||||
result[-(len(done_budget) +1)]['prac']=tot_prac
|
||||
result[-(len(done_budget) +1)]['prac'] = tot_prac
|
||||
tot['prac'] +=tot_prac
|
||||
result[-(len(done_budget) +1)]['perc']=tot_perc
|
||||
|
||||
if tot['theo']==0.00:
|
||||
tot['perc'] =0.00
|
||||
result[-(len(done_budget) +1)]['perc'] = tot_perc
|
||||
if tot['theo'] == 0.00:
|
||||
tot['perc'] = 0.00
|
||||
else:
|
||||
tot['perc']=float(tot['prac'] /tot['theo'])*100
|
||||
|
||||
tot['perc'] = float(tot['prac'] / tot['theo']) * 100
|
||||
return result
|
||||
|
||||
def funct_total(self,form):
|
||||
result=[]
|
||||
res={}
|
||||
res={
|
||||
'tot_theo':tot['theo'],
|
||||
'tot_pln':tot['pln'],
|
||||
'tot_prac':tot['prac'],
|
||||
'tot_perc':tot['perc']
|
||||
result = []
|
||||
res = {}
|
||||
res = {
|
||||
'tot_theo': tot['theo'],
|
||||
'tot_pln': tot['pln'],
|
||||
'tot_prac': tot['prac'],
|
||||
'tot_perc': tot['perc']
|
||||
}
|
||||
result.append(res)
|
||||
|
||||
return result
|
||||
|
||||
report_sxw.report_sxw('report.account.analytic.account.budget', 'account.analytic.account', 'addons/account_budget/report/analytic_account_budget_report.rml',parser=analytic_account_budget_report,header='internal')
|
||||
|
|
|
@ -38,17 +38,19 @@ class budget_report(report_sxw.rml_parse):
|
|||
def post_total(self, post_obj, date1, date2):
|
||||
def str2date(date_str):
|
||||
return datetime.date.fromtimestamp(time.mktime(time.strptime(date_str, '%Y-%m-%d')))
|
||||
|
||||
def interval(d1str, d2str):
|
||||
return (str2date(d2str) - str2date(d1str) + datetime.timedelta(days=1)).days
|
||||
|
||||
prev = reduce(lambda x,d: x + d.amount, post_obj.dotation_ids, 0.0)
|
||||
period_days = interval(date1, date2)
|
||||
for d in post_obj.dotation_ids:
|
||||
i = interval(d.period_id.date_start, d.period_id.date_stop)
|
||||
total_days = reduce(lambda x,d: x+interval(d.period_id.date_start, d.period_id.date_stop), post_obj.dotation_ids, 0)
|
||||
achievements = reduce(lambda x,l: x+l['achievements'], self.lines(post_obj, date1, date2), 0.0)
|
||||
prev_1=1.00
|
||||
if total_days<>0.00:
|
||||
prev_1=prev * period_days / total_days
|
||||
prev_1 = 1.00
|
||||
if total_days <> 0.00:
|
||||
prev_1 = prev * period_days / total_days
|
||||
return [{'prev': prev, 'prev_period': prev_1, 'achievements': achievements}]
|
||||
|
||||
def budget_total(self, post_obj, date1, date2):
|
||||
|
@ -66,7 +68,7 @@ class budget_report(report_sxw.rml_parse):
|
|||
res.append({'name': a.name, 'code': a.code, 'achievements': achievements})
|
||||
return res
|
||||
|
||||
report_sxw.report_sxw('report.account.budget', 'account.budget.post', 'addons/account_budget/report/budget_report.rml',parser=budget_report, header="internal")
|
||||
report_sxw.report_sxw('report.account.budget', 'account.budget.post', 'addons/account_budget/report/budget_report.rml', parser=budget_report, header="internal")
|
||||
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
|
@ -20,48 +20,46 @@
|
|||
##############################################################################
|
||||
|
||||
import time
|
||||
import datetime
|
||||
|
||||
import pooler
|
||||
from report import report_sxw
|
||||
import datetime
|
||||
import operator
|
||||
import osv
|
||||
|
||||
class budget_report(report_sxw.rml_parse):
|
||||
def __init__(self, cr, uid, name, context):
|
||||
super(budget_report, self).__init__(cr, uid, name, context=context)
|
||||
self.localcontext.update( {
|
||||
self.localcontext.update({
|
||||
'funct': self.funct,
|
||||
'funct_total': self.funct_total,
|
||||
'time': time,
|
||||
})
|
||||
self.context=context
|
||||
self.context = context
|
||||
|
||||
def funct(self, object, form, ids={}, done=None, level=1):
|
||||
|
||||
if not ids:
|
||||
ids = self.ids
|
||||
if not done:
|
||||
done={}
|
||||
|
||||
done = {}
|
||||
global tot
|
||||
tot={
|
||||
tot = {
|
||||
'theo':0.00,
|
||||
'pln':0.00,
|
||||
'prac':0.00,
|
||||
'perc':0.00
|
||||
}
|
||||
result=[]
|
||||
result = []
|
||||
|
||||
budgets = self.pool.get('crossovered.budget').browse(self.cr, self.uid, [object.id], self.context.copy())
|
||||
|
||||
c_b_lines_obj=self.pool.get('crossovered.budget.lines')
|
||||
c_b_lines_obj = self.pool.get('crossovered.budget.lines')
|
||||
acc_analytic_obj = self.pool.get('account.analytic.account')
|
||||
for budget_id in budgets:
|
||||
|
||||
res={}
|
||||
budget_lines=[]
|
||||
budget_ids=[]
|
||||
d_from=form['date_from']
|
||||
d_to=form['date_to']
|
||||
res = {}
|
||||
budget_lines = []
|
||||
budget_ids = []
|
||||
d_from = form['date_from']
|
||||
d_to = form['date_to']
|
||||
|
||||
for line in budget_id.crossovered_budget_line:
|
||||
budget_ids.append(line.id)
|
||||
|
@ -69,78 +67,69 @@ class budget_report(report_sxw.rml_parse):
|
|||
if not budget_ids:
|
||||
return []
|
||||
|
||||
self.cr.execute('select distinct(analytic_account_id) from crossovered_budget_lines where id =ANY(%s)',(budget_ids,))
|
||||
an_ids=self.cr.fetchall()
|
||||
|
||||
context={'wizard_date_from':d_from,'wizard_date_to':d_to}
|
||||
for i in range(0,len(an_ids)):
|
||||
|
||||
analytic_name=self.pool.get('account.analytic.account').browse(self.cr, self.uid, [an_ids[i][0]])
|
||||
self.cr.execute('SELECT DISTINCT(analytic_account_id) FROM crossovered_budget_lines WHERE id = ANY(%s)',(budget_ids,))
|
||||
an_ids = self.cr.fetchall()
|
||||
|
||||
context = {'wizard_date_from': d_from, 'wizard_date_to': d_to}
|
||||
for i in range(0, len(an_ids)):
|
||||
analytic_name = acc_analytic_obj.browse(self.cr, self.uid, [an_ids[i][0]])
|
||||
res={
|
||||
'b_id':'-1',
|
||||
'a_id':'-1',
|
||||
'name':analytic_name[0].name,
|
||||
'status':1,
|
||||
'theo':0.00,
|
||||
'pln':0.00,
|
||||
'prac':0.00,
|
||||
'perc':0.00
|
||||
'b_id': '-1',
|
||||
'a_id': '-1',
|
||||
'name': analytic_name[0].name,
|
||||
'status': 1,
|
||||
'theo': 0.00,
|
||||
'pln': 0.00,
|
||||
'prac': 0.00,
|
||||
'perc': 0.00
|
||||
}
|
||||
result.append(res)
|
||||
|
||||
line_ids = c_b_lines_obj.search(self.cr, self.uid, [('id', 'in', budget_ids),('analytic_account_id','=',an_ids[i][0])])
|
||||
|
||||
line_ids = c_b_lines_obj.search(self.cr, self.uid, [('id', 'in', budget_ids), ('analytic_account_id','=',an_ids[i][0])])
|
||||
line_id = c_b_lines_obj.browse(self.cr, self.uid, line_ids)
|
||||
tot_theo=tot_pln=tot_prac=tot_perc=0.00
|
||||
tot_theo = tot_pln = tot_prac = tot_perc = 0.00
|
||||
|
||||
done_budget=[]
|
||||
done_budget = []
|
||||
for line in line_id:
|
||||
|
||||
if line.id in budget_ids:
|
||||
theo=pract=0.00
|
||||
theo=c_b_lines_obj._theo_amt(self.cr, self.uid, [line.id],context)[line.id]
|
||||
pract=c_b_lines_obj._prac_amt(self.cr, self.uid, [line.id],context)[line.id]
|
||||
|
||||
theo = pract = 0.00
|
||||
theo = c_b_lines_obj._theo_amt(self.cr, self.uid, [line.id], context)[line.id]
|
||||
pract = c_b_lines_obj._prac_amt(self.cr, self.uid, [line.id], context)[line.id]
|
||||
if line.general_budget_id.id in done_budget:
|
||||
|
||||
for record in result:
|
||||
if record['b_id']==line.general_budget_id.id and record['a_id']==line.analytic_account_id.id:
|
||||
|
||||
record['theo'] +=theo
|
||||
record['pln'] +=line.planned_amount
|
||||
record['prac'] +=pract
|
||||
if record['theo']<>0.00:
|
||||
perc=(record['prac']/record['theo'])*100
|
||||
if record['b_id'] == line.general_budget_id.id and record['a_id'] == line.analytic_account_id.id:
|
||||
record['theo'] += theo
|
||||
record['pln'] += line.planned_amount
|
||||
record['prac'] += pract
|
||||
if record['theo'] <> 0.00:
|
||||
perc = (record['prac'] / record['theo']) * 100
|
||||
else:
|
||||
perc=0.00
|
||||
record['perc'] =perc
|
||||
perc = 0.00
|
||||
record['perc'] = perc
|
||||
tot_theo += theo
|
||||
tot_pln +=line.planned_amount
|
||||
tot_prac +=pract
|
||||
tot_perc +=perc
|
||||
|
||||
tot_pln += line.planned_amount
|
||||
tot_prac += pract
|
||||
tot_perc += perc
|
||||
else:
|
||||
|
||||
if theo<>0.00:
|
||||
perc=(pract/theo)*100
|
||||
if theo <> 0.00:
|
||||
perc = (pract / theo) * 100
|
||||
else:
|
||||
perc=0.00
|
||||
res1={
|
||||
'a_id':line.analytic_account_id.id,
|
||||
'b_id':line.general_budget_id.id,
|
||||
'name':line.general_budget_id.name,
|
||||
'status':2,
|
||||
'theo':theo,
|
||||
'pln':line.planned_amount,
|
||||
'prac':pract,
|
||||
'perc':perc,
|
||||
perc = 0.00
|
||||
res1 = {
|
||||
'a_id': line.analytic_account_id.id,
|
||||
'b_id': line.general_budget_id.id,
|
||||
'name': line.general_budget_id.name,
|
||||
'status': 2,
|
||||
'theo': theo,
|
||||
'pln': line.planned_amount,
|
||||
'prac': pract,
|
||||
'perc': perc,
|
||||
}
|
||||
tot_theo += theo
|
||||
tot_pln +=line.planned_amount
|
||||
tot_prac +=pract
|
||||
tot_perc +=perc
|
||||
if form['report']=='analytic-full':
|
||||
tot_pln += line.planned_amount
|
||||
tot_prac += pract
|
||||
tot_perc += perc
|
||||
if form['report'] == 'analytic-full':
|
||||
result.append(res1)
|
||||
done_budget.append(line.general_budget_id.id)
|
||||
else:
|
||||
|
@ -149,61 +138,57 @@ class budget_report(report_sxw.rml_parse):
|
|||
continue
|
||||
else:
|
||||
res1={
|
||||
'a_id':line.analytic_account_id.id,
|
||||
'b_id':line.general_budget_id.id,
|
||||
'name':line.general_budget_id.name,
|
||||
'status':2,
|
||||
'theo':0.00,
|
||||
'pln':0.00,
|
||||
'prac':0.00,
|
||||
'perc':0.00
|
||||
}
|
||||
|
||||
if form['report']=='analytic-full':
|
||||
'a_id': line.analytic_account_id.id,
|
||||
'b_id': line.general_budget_id.id,
|
||||
'name': line.general_budget_id.name,
|
||||
'status': 2,
|
||||
'theo': 0.00,
|
||||
'pln': 0.00,
|
||||
'prac': 0.00,
|
||||
'perc': 0.00
|
||||
}
|
||||
if form['report'] == 'analytic-full':
|
||||
result.append(res1)
|
||||
done_budget.append(line.general_budget_id.id)
|
||||
|
||||
if tot_theo==0.00:
|
||||
tot_perc=0.00
|
||||
if tot_theo == 0.00:
|
||||
tot_perc = 0.00
|
||||
else:
|
||||
tot_perc=float(tot_prac /tot_theo)*100
|
||||
|
||||
if form['report']=='analytic-full':
|
||||
|
||||
result[-(len(done_budget) +1)]['theo']=tot_theo
|
||||
tot['theo'] +=tot_theo
|
||||
result[-(len(done_budget) +1)]['pln']=tot_pln
|
||||
tot['pln'] +=tot_pln
|
||||
result[-(len(done_budget) +1)]['prac']=tot_prac
|
||||
tot['prac'] +=tot_prac
|
||||
result[-(len(done_budget) +1)]['perc']=tot_perc
|
||||
tot_perc = float(tot_prac / tot_theo) * 100
|
||||
if form['report'] == 'analytic-full':
|
||||
result[-(len(done_budget) +1)]['theo'] = tot_theo
|
||||
tot['theo'] += tot_theo
|
||||
result[-(len(done_budget) +1)]['pln'] = tot_pln
|
||||
tot['pln'] += tot_pln
|
||||
result[-(len(done_budget) +1)]['prac'] = tot_prac
|
||||
tot['prac'] += tot_prac
|
||||
result[-(len(done_budget) +1)]['perc'] = tot_perc
|
||||
else:
|
||||
result[-1]['theo']=tot_theo
|
||||
tot['theo'] +=tot_theo
|
||||
result[-1]['pln']=tot_pln
|
||||
tot['pln'] +=tot_pln
|
||||
result[-1]['prac']=tot_prac
|
||||
tot['prac'] +=tot_prac
|
||||
result[-1]['perc']=tot_perc
|
||||
if tot['theo']==0.00:
|
||||
tot['perc'] =0.00
|
||||
result[-1]['theo'] = tot_theo
|
||||
tot['theo'] += tot_theo
|
||||
result[-1]['pln'] = tot_pln
|
||||
tot['pln'] += tot_pln
|
||||
result[-1]['prac'] = tot_prac
|
||||
tot['prac'] += tot_prac
|
||||
result[-1]['perc'] = tot_perc
|
||||
if tot['theo'] == 0.00:
|
||||
tot['perc'] = 0.00
|
||||
else:
|
||||
tot['perc']=float(tot['prac'] /tot['theo'])*100
|
||||
tot['perc'] = float(tot['prac'] / tot['theo']) * 100
|
||||
return result
|
||||
|
||||
def funct_total(self, form):
|
||||
result=[]
|
||||
res={}
|
||||
|
||||
res={
|
||||
'tot_theo':tot['theo'],
|
||||
'tot_pln':tot['pln'],
|
||||
'tot_prac':tot['prac'],
|
||||
'tot_perc':tot['perc']
|
||||
result = []
|
||||
res = {}
|
||||
res = {
|
||||
'tot_theo': tot['theo'],
|
||||
'tot_pln': tot['pln'],
|
||||
'tot_prac': tot['prac'],
|
||||
'tot_perc': tot['perc']
|
||||
}
|
||||
result.append(res)
|
||||
|
||||
return result
|
||||
|
||||
report_sxw.report_sxw('report.crossovered.budget.report', 'crossovered.budget', 'addons/account_budget/report/crossovered_budget_report.rml',parser=budget_report,header='internal')
|
||||
|
||||
# vim:expandtab:smartindent:tabstop=4:softtabstop=4:shiftwidth=4:
|
||||
|
||||
|
|
|
@ -29,11 +29,11 @@ class account_budget_analytic(osv.osv_memory):
|
|||
_columns = {
|
||||
'date_from': fields.date('Start of period', required=True),
|
||||
'date_to': fields.date('End of period', required=True),
|
||||
}
|
||||
}
|
||||
_defaults= {
|
||||
'date_from': time.strftime('%Y-01-01'),
|
||||
'date_to': time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
}
|
||||
|
||||
def check_report(self, cr, uid, ids, context=None):
|
||||
datas = {}
|
||||
|
@ -44,12 +44,12 @@ class account_budget_analytic(osv.osv_memory):
|
|||
'ids': context.get('active_ids',[]),
|
||||
'model': 'account.analytic.account',
|
||||
'form': data
|
||||
}
|
||||
}
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'account.analytic.account.budget',
|
||||
'datas': datas,
|
||||
}
|
||||
}
|
||||
|
||||
account_budget_analytic()
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from osv import fields, osv
|
||||
|
@ -30,11 +29,11 @@ class account_budget_crossvered_report(osv.osv_memory):
|
|||
_columns = {
|
||||
'date_from': fields.date('Start of period', required=True),
|
||||
'date_to': fields.date('End of period', required=True),
|
||||
}
|
||||
}
|
||||
_defaults= {
|
||||
'date_from': time.strftime('%Y-01-01'),
|
||||
'date_to': time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
}
|
||||
|
||||
def check_report(self, cr, uid, ids, context=None):
|
||||
datas = {}
|
||||
|
@ -45,13 +44,13 @@ class account_budget_crossvered_report(osv.osv_memory):
|
|||
'ids': context.get('active_ids',[]),
|
||||
'model': 'crossovered.budget',
|
||||
'form': data
|
||||
}
|
||||
}
|
||||
datas['form']['report']='analytic-full'
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'crossovered.budget.report',
|
||||
'datas': datas,
|
||||
}
|
||||
}
|
||||
|
||||
account_budget_crossvered_report()
|
||||
|
||||
|
|
|
@ -31,11 +31,11 @@ class account_budget_crossvered_summary_report(osv.osv_memory):
|
|||
_columns = {
|
||||
'date_from': fields.date('Start of period', required=True),
|
||||
'date_to': fields.date('End of period', required=True),
|
||||
}
|
||||
}
|
||||
_defaults= {
|
||||
'date_from': time.strftime('%Y-01-01'),
|
||||
'date_to': time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
}
|
||||
|
||||
def check_report(self, cr, uid, ids, context=None):
|
||||
datas = {}
|
||||
|
@ -46,14 +46,13 @@ class account_budget_crossvered_summary_report(osv.osv_memory):
|
|||
'ids': context.get('active_ids',[]),
|
||||
'model': 'crossovered.budge',
|
||||
'form': data
|
||||
}
|
||||
datas['form']['report']='analytic-one'
|
||||
}
|
||||
datas['form']['report'] = 'analytic-one'
|
||||
return {
|
||||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'crossovered.budget.report',
|
||||
'datas': datas,
|
||||
}
|
||||
return {}
|
||||
}
|
||||
|
||||
account_budget_crossvered_summary_report()
|
||||
|
||||
|
|
|
@ -18,7 +18,6 @@
|
|||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
import time
|
||||
|
||||
from osv import fields, osv
|
||||
|
@ -31,11 +30,11 @@ class account_budget_report(osv.osv_memory):
|
|||
_columns = {
|
||||
'date1': fields.date('Start of period', required=True),
|
||||
'date2': fields.date('End of period', required=True),
|
||||
}
|
||||
}
|
||||
_defaults= {
|
||||
'date1': time.strftime('%Y-01-01'),
|
||||
'date2': time.strftime('%Y-%m-%d'),
|
||||
}
|
||||
}
|
||||
|
||||
def check_report(self, cr, uid, ids, context=None):
|
||||
datas = {}
|
||||
|
@ -46,7 +45,7 @@ class account_budget_report(osv.osv_memory):
|
|||
'ids': context.get('active_ids',[]),
|
||||
'model': 'account.budget.post',
|
||||
'form': data
|
||||
}
|
||||
}
|
||||
|
||||
data_model = self.pool.get(datas['model']).browse(cr, uid, context['active_id'])
|
||||
if not data_model.dotation_ids:
|
||||
|
@ -55,7 +54,7 @@ class account_budget_report(osv.osv_memory):
|
|||
'type': 'ir.actions.report.xml',
|
||||
'report_name': 'account.budget',
|
||||
'datas': datas,
|
||||
}
|
||||
}
|
||||
|
||||
account_budget_report()
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@ class account_budget_spread(osv.osv_memory):
|
|||
_columns = {
|
||||
'fiscalyear': fields.many2one('account.fiscalyear', 'Fiscal Year', required=True),
|
||||
'amount': fields.float('Amount', digits_compute=dp.get_precision('Account')),
|
||||
}
|
||||
}
|
||||
|
||||
def check_spread(self, cr, uid, ids, context=None):
|
||||
if context is None:
|
||||
|
|
|
@ -224,24 +224,24 @@ class account_coda_import(osv.osv_memory):
|
|||
'period_id':statement.get('period_id',False) or period,# statement.period_id.id
|
||||
}
|
||||
voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
|
||||
|
||||
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype=(amount < 0 and 'payment' or 'receipt'))
|
||||
context.update({'move_line_ids': [line['id']]})
|
||||
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype=(amount < 0 and 'payment' or 'receipt'), context=context)
|
||||
voucher_line_dict = False
|
||||
if result['value']['line_ids']:
|
||||
for line_dict in result['value']['line_ids']:
|
||||
move_line = line_obj.browse(cr, uid, line_dict['move_line_id'], context)
|
||||
if line.move_id.id == move_line.move_id.id:
|
||||
voucher_line_dict = line_dict
|
||||
|
||||
|
||||
if voucher_line_dict:
|
||||
voucher_line_dict.update({'voucher_id':voucher_id})
|
||||
voucher_line_obj.create(cr, uid, voucher_line_dict, context=context)
|
||||
|
||||
|
||||
# reconcile_id = statement_reconcile_obj.create(cr, uid, {
|
||||
# 'line_ids': [(6, 0, rec_id)]
|
||||
# }, context=context)
|
||||
#
|
||||
|
||||
|
||||
mv = self.pool.get('account.move.line').browse(cr, uid, rec_id[0], context=context)
|
||||
if mv.partner_id:
|
||||
line['partner_id'] = mv.partner_id.id
|
||||
|
|
|
@ -91,7 +91,8 @@ class account_payment_populate_statement(osv.osv_memory):
|
|||
'period_id': statement.period_id.id
|
||||
}
|
||||
voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
|
||||
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype='payment')
|
||||
context.update({'move_line_ids': [line.id]})
|
||||
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype='payment', context=context)
|
||||
voucher_line_dict = False
|
||||
if result['value']['line_ids']:
|
||||
for line_dict in result['value']['line_ids']:
|
||||
|
|
|
@ -214,7 +214,8 @@ def _import(obj, cursor, user, data, context=None):
|
|||
'period_id': statement.period_id.id
|
||||
}
|
||||
voucher_id = voucher_obj.create(cr, uid, voucher_res, context=context)
|
||||
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype='payment')
|
||||
context.update({'move_line_ids': [line.id]})
|
||||
result = voucher_obj.onchange_partner_id(cr, uid, [], partner_id=line.partner_id.id, journal_id=statement.journal_id.id, price=abs(amount), currency_id= statement.currency.id, ttype='payment', context=context)
|
||||
voucher_line_dict = False
|
||||
if result['value']['line_ids']:
|
||||
for line_dict in result['value']['line_ids']:
|
||||
|
|
Loading…
Reference in New Issue