From f9679d80c7dcfb8afbb69556707c3e867c93dad7 Mon Sep 17 00:00:00 2001 From: Raphael Collet Date: Mon, 28 Sep 2015 10:54:35 +0200 Subject: [PATCH] [FIX] expression: partial implementation for binary fields stored in attachments Implement conditions `('image', '=', False)` and `('image', '!=', False)`. --- openerp/osv/expression.py | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/openerp/osv/expression.py b/openerp/osv/expression.py index 18b4d54abb1..1e9541b1abe 100644 --- a/openerp/osv/expression.py +++ b/openerp/osv/expression.py @@ -1028,6 +1028,23 @@ class expression(object): # right == [] or right == False and all other cases are handled by __leaf_to_sql() push_result(leaf) + # ------------------------------------------------- + # BINARY FIELDS STORED IN ATTACHMENT + # -> check for null only + # ------------------------------------------------- + + elif column._type == 'binary' and column.attachment: + if operator in ('=', '!=') and not right: + inselect_operator = 'inselect' if operator in NEGATIVE_TERM_OPERATORS else 'not inselect' + subselect = "SELECT res_id FROM ir_attachment WHERE res_model=%s AND res_field=%s" + params = (model._name, left) + push(create_substitution_leaf(leaf, ('id', inselect_operator, (subselect, params)), model, internal=True)) + else: + _logger.error("Binary field '%s' stored in attachment: ignore %s %s %s", + column.string, left, operator, right) + leaf.leaf = TRUE_LEAF + push(leaf) + # ------------------------------------------------- # OTHER FIELDS # -> datetime fields: manage time part of the datetime