From 6e063188282e3594178c9ae367fa939ea890c9f9 Mon Sep 17 00:00:00 2001 From: Goffin Simon Date: Sat, 16 May 2015 22:21:06 +0200 Subject: [PATCH] [FIX] base: value = 0 for record ir_property When a record is created with a field property of type integer or float equal to 0, there is no record created in ir_property for this field. Then for a search of a record with this type of field equal to 0, it must match all the records that have no corresponding property in the table "ir.property" for this field. ps: in 7.0, the function search_multi doesn't exist and the bug linked to cost price doesn't happen because it's a float field. opw:639746 --- openerp/addons/base/res/ir_property.py | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) diff --git a/openerp/addons/base/res/ir_property.py b/openerp/addons/base/res/ir_property.py index 382f7ae2b95..b90d18233a3 100644 --- a/openerp/addons/base/res/ir_property.py +++ b/openerp/addons/base/res/ir_property.py @@ -260,6 +260,7 @@ class ir_property(osv.osv): def search_multi(self, name, model, operator, value): """ Return a domain for the records that match the given condition. """ default_matches = False + include_zero = False field = self.env[model]._fields[name] if field.type == 'many2one': @@ -281,6 +282,27 @@ class ir_property(osv.osv): target_names = target.name_search(value, operator=operator, limit=None) target_ids = map(itemgetter(0), target_names) operator, value = 'in', map(makeref, target_ids) + elif field.type in ('integer', 'float'): + # No record is created in ir.property if the field's type is float or integer with a value + # equal to 0. Then to match with the records that are linked to a property field equal to 0, + # the negation of the operator must be taken to compute the goods and the domain returned + # to match the searched records is just the opposite. + if value == 0 and operator == '=': + operator = '!=' + include_zero = True + elif value <= 0 and operator == '>=': + operator = '<' + include_zero = True + elif value <= 0 and operator == '>': + operator = '<=' + include_zero = True + elif value >= 0 and operator == '<=': + operator = '>' + include_zero = True + elif value >= 0 and operator == '<': + operator = '>=' + include_zero = True + # retrieve the properties that match the condition domain = self._get_domain(name, model) @@ -297,7 +319,9 @@ class ir_property(osv.osv): else: default_matches = True - if default_matches: + if include_zero: + return [('id', 'not in', good_ids)] + elif default_matches: # exclude all records with a property that does not match all_ids = [] props = self.search(domain + [('res_id', '!=', False)])