From 36040e0f2e58d8165642d93ffaede0ded0fc0bf3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Krier?= Date: Fri, 16 Jul 2010 20:19:30 +0200 Subject: [PATCH] Add CAST on SUM and convert Decimal into str for issue1615 SQLite fails to compare HAVING clause with a Decimal --- invoice.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/invoice.py b/invoice.py index db0d8e2831..e9d8c602e6 100644 --- a/invoice.py +++ b/invoice.py @@ -544,6 +544,8 @@ class Invoice(ModelWorkflow, ModelSQL, ModelView): rule_obj = self.pool.get('ir.rule') line_obj = self.pool.get('account.invoice.line') tax_obj = self.pool.get('account.invoice.tax') + type_name = FIELDS[self.total_amount._type].sql_type( + self.total_amount)[0] invoice_query, invoice_val = rule_obj.domain_get( cursor, user, 'account.invoice', context=context) @@ -568,14 +570,17 @@ class Invoice(ModelWorkflow, ModelSQL, ModelView): 'GROUP BY invoice ' ') AS u ' 'GROUP BY u.invoice ' - 'HAVING (SUM(u.total_amount) ' + clause[1] + ' %s)', - invoice_val + invoice_val + [clause[2]]) + 'HAVING (CAST(SUM(u.total_amount) AS ' + type_name + ') ' + + clause[1] + ' %s)', + invoice_val + invoice_val + [str(clause[2])]) return [('id', 'in', [x[0] for x in cursor.fetchall()])] def search_untaxed_amount(self, cursor, user, name, clause, context=None): rule_obj = self.pool.get('ir.rule') line_obj = self.pool.get('account.invoice.line') tax_obj = self.pool.get('account.invoice.tax') + type_name = FIELDS[self.untaxed_amount._type].sql_type( + self.untaxed_amount)[0] invoice_query, invoice_val = rule_obj.domain_get( cursor, user, 'account.invoice', context=context) @@ -586,15 +591,17 @@ class Invoice(ModelWorkflow, ModelSQL, ModelView): '"' + line_obj._table + '".invoice) ' 'WHERE ' + invoice_query + ' ' 'GROUP BY invoice ' - 'HAVING (COALESCE(SUM(quantity * unit_price), 0) ' + \ - clause[1] + ' %s)', - invoice_val + [clause[2]]) + 'HAVING (CAST(COALESCE(SUM(quantity * unit_price), 0) ' + 'AS ' + type_name + ') ' + clause[1] + ' %s)', + invoice_val + [str(clause[2])]) return [('id', 'in', [x[0] for x in cursor.fetchall()])] def search_tax_amount(self, cursor, user, name, clause, context=None): rule_obj = self.pool.get('ir.rule') line_obj = self.pool.get('account.invoice.line') tax_obj = self.pool.get('account.invoice.tax') + type_name = FIELDS[self.tax_amount._type].sql_type( + self.tax_amount)[0] invoice_query, invoice_val = rule_obj.domain_get( cursor, user, 'account.invoice', context=context) @@ -605,8 +612,9 @@ class Invoice(ModelWorkflow, ModelSQL, ModelView): '"' + tax_obj._table + '".invoice) ' 'WHERE ' + invoice_query + ' ' 'GROUP BY invoice ' - 'HAVING (COALESCE(SUM(amount), 0) ' + clause[1] + ' %s)', - invoice_val + [clause[2]]) + 'HAVING (CAST(COALESCE(SUM(amount), 0) ' + 'AS ' + type_name + ') ' + clause[1] + ' %s)', + invoice_val + [str(clause[2])]) return [('id', 'in', [x[0] for x in cursor.fetchall()])] def button_draft(self, cursor, user, ids, context=None):