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