[IMP]:l10n_fr sql queries to parameterized query

bzr revid: nch@tinyerp.com-20091125113207-1557k1ysnvp5z52n
This commit is contained in:
nch@tinyerp.com
2009-11-25 17:02:07 +05:30
parent 8354496c6d
commit c80cbcd371
+7 -10
View File
@@ -43,19 +43,16 @@ class base_report(report_sxw.rml_parse):
def _load(self,name,form):
fiscalyear=self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear'])
periods=self.pool.get('account.period').search(self.cr, self.uid,[('fiscalyear_id','=',form['fiscalyear'])])
period_query_cond=str(tuple(periods))
period_query_cond=self.pool.get('account.period').search(self.cr, self.uid,[('fiscalyear_id','=',form['fiscalyear'])])
query = "SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id IN "+str(period_query_cond)
self.cr.execute(query)
self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id =ANY(%s)",(period_query_cond,))
dates =self.cr.dictfetchall()
self._set_variable('date_start', dates[0]['date_start'])
self._set_variable('date_stop', dates[0]['date_stop'])
query = "SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code='"+name+"'"
self.cr.execute(query)
self.cr.execute("SELECT l10n_fr_line.code,definition FROM l10n_fr_line LEFT JOIN l10n_fr_report ON l10n_fr_report.id=report_id WHERE l10n_fr_report.code=%s",(name,))
datas =self.cr.dictfetchall()
for line in datas:
for line in datas:
self._load_accounts(form,line['code'],eval(line['definition']),fiscalyear,period_query_cond)
def _set_variable(self,variable,valeur):
@@ -86,9 +83,9 @@ class base_report(report_sxw.rml_parse):
closed_cond=""
if fiscalyear.state=='done':
closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(period_query_cond)+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))"
closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id IN "+str(tuple(period_query_cond))+" AND journal_id=(SELECT res_id FROM ir_model_data WHERE name='closing_journal' AND module='l10n_fr')) OR (aa.type != 'income' AND aa.type !='expense'))"
query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(period_query_cond)+" GROUP BY code"
query = "SELECT aa.code AS code, SUM(debit) as debit, SUM(credit) as credit FROM account_move_line aml LEFT JOIN account_account aa ON aa.id=aml.account_id WHERE "+query_cond+closed_cond+" AND aml.state='valid' AND aml.period_id IN "+str(tuple(period_query_cond))+" GROUP BY code"
self.cr.execute(query)
lines =self.cr.dictfetchall()
@@ -102,7 +99,7 @@ class base_report(report_sxw.rml_parse):
value=line["debit"]-line["credit"]
elif(type=="D"):
value=line["debit"]-line["credit"]
if(value<0.001): value=0.0
if(value<0.001): value=0.0
elif(type=="C"):
value=line["credit"]-line["debit"]
if(value<0.001): value=0.0