From 5bebd204b83275adc470cfe0c2a616ca7b2f64fd Mon Sep 17 00:00:00 2001 From: "P. Christeas" Date: Thu, 28 Oct 2010 16:03:49 +0300 Subject: [PATCH] l10n_fr: Fix reports, yaml code for them Main issue was that 'fiscalyear_id' was not defined in the data['form'] dictionary, so it triggered the wrong fiscal year to be used (wonder how it really didn't raise an error on trunk). bzr revid: p_christ@hol.gr-20101028130349-bpophiuieeee3e5t --- addons/l10n_fr/report/base_report.py | 35 ++++++++++++++++---------- addons/l10n_fr/test/l10n_fr_report.yml | 5 ++++ 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/addons/l10n_fr/report/base_report.py b/addons/l10n_fr/report/base_report.py index f1b00896159..2c44b062f45 100644 --- a/addons/l10n_fr/report/base_report.py +++ b/addons/l10n_fr/report/base_report.py @@ -42,18 +42,22 @@ class base_report(report_sxw.rml_parse): self.context = context def _load(self, name, form): - fiscalyear = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear']) - period_query_cond=self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id', '=', form['fiscalyear'])]) + fiscalyear = self.pool.get('account.fiscalyear').browse(self.cr, self.uid, form['fiscalyear_id']) + period_ids=self.pool.get('account.period').search(self.cr, self.uid, [('fiscalyear_id', '=', form['fiscalyear_id'])]) - self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id IN %s", (tuple(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']) + if period_ids: + self.cr.execute("SELECT MIN(date_start) AS date_start, MAX(date_stop) AS date_stop FROM account_period WHERE id = ANY(%s)", (period_ids,)) + dates = self.cr.dictfetchall() + else: + dates = False + if dates: + self._set_variable('date_start', dates[0]['date_start']) + self._set_variable('date_stop', dates[0]['date_stop']) 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: - self._load_accounts(form,line['code'],eval(line['definition']),fiscalyear,period_query_cond) + self._load_accounts(form,line['code'],eval(line['definition']),fiscalyear,period_ids) def _set_variable(self, variable, valeur): self.localcontext.update({variable: valeur}) @@ -61,30 +65,35 @@ class base_report(report_sxw.rml_parse): def _get_variable(self, variable): return self.localcontext[variable] - def _load_accounts(self,form,code,definition,fiscalyear,period_query_cond): + def _load_accounts(self, form, code, definition, fiscalyear, period_ids): accounts = {} for x in definition['load']: p = x.split(":") accounts[p[1]] = [p[0],p[2]] sum = 0.0 if fiscalyear.state != 'done' or not code.startswith('bpcheck'): + query_params = [] query_cond = "(" for account in accounts: - query_cond += "aa.code LIKE '" + account + "%' OR " + query_cond += "aa.code LIKE '" + account + "%%' OR " query_cond = query_cond[:-4]+")" if len(definition['except']) > 0: query_cond = query_cond+" and (" for account in definition['except']: - query_cond += "aa.code NOT LIKE '"+account+"%' AND " + query_cond += "aa.code NOT LIKE '"+account+"%%' AND " query_cond = query_cond[:-5]+")" 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(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'))" + closed_cond=" AND (aml.move_id NOT IN (SELECT account_move.id as move_id FROM account_move WHERE period_id = ANY(%s) 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_params.append(list(period_ids)) - 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) + 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 = ANY(%s) GROUP BY code" + query_params.append(list(period_ids)) + self.cr.execute(query, query_params) lines =self.cr.dictfetchall() for line in lines: diff --git a/addons/l10n_fr/test/l10n_fr_report.yml b/addons/l10n_fr/test/l10n_fr_report.yml index ddc95595175..7cf9b161223 100644 --- a/addons/l10n_fr/test/l10n_fr_report.yml +++ b/addons/l10n_fr/test/l10n_fr_report.yml @@ -7,6 +7,11 @@ date_start: '2012-01-01' date_stop: '2012-12-31' name: Fiscal Year 2012 +- + I create the fiscal periods +- + !python {model: account.fiscalyear}: + self.create_period(cr, uid, [ref('account_fiscalyear_01'),]) - In order to test the PDF reports defined on a l10n_fr, we will print an Account Move Line Report for l10n_fr -