Skip to content

Commit 56f46ba

Browse files
authored
Merge pull request #827 from Som-Energia/FIX_validation_3043
Arreglar la funció search quan l'operador no és ilike
2 parents 51bf6cc + ed503d1 commit 56f46ba

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

giscedata_facturacio_som/giscedata_facturacio.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,13 @@ def search(self, cr, user, args, offset=0, limit=None, order=None, context=None,
3434
for idx, arg in enumerate(args):
3535
if len(arg) == 3:
3636
field, operator, match = arg
37-
if exact_number and field == "number" and isinstance(match, (unicode, str)): # noqa: E501, F821
38-
if "%" not in match:
39-
operator = "="
37+
if (exact_number and field == "number" and operator == "ilike"
38+
and isinstance(match, (unicode, str)) and "%" not in match):
39+
operator = "="
4040
args[idx] = (field, operator, match)
41-
if exact_origin and field == "origin" and isinstance(match, (unicode, str)): # noqa: E501, F821
42-
if "%" not in match:
43-
operator = "="
41+
if (exact_origin and field == "origin" and operator == "ilike"
42+
and isinstance(match, (unicode, str)) and "%" not in match):
43+
operator = "="
4444
args[idx] = (field, operator, match)
4545
return super(GiscedataFacturacio, self).search(
4646
cr, user, args, offset, limit, order, context, count

giscedata_facturacio_som/tests/tests_giscedata_facturacio_som.py

+18
Original file line numberDiff line numberDiff line change
@@ -112,3 +112,21 @@ def test_search_exactNotExist_disabled(self): # noqa: F811
112112
gff_ids = self.gff_obj.search(self.cursor, self.uid, [("origin", "ilike", "sample_origin")])
113113

114114
self.assertGreater(len(gff_ids), 1)
115+
116+
def test_search_nonequal_operator_active(self):
117+
self.set_invoice_origin_cerca_exacte(self.cursor, self.uid, "1")
118+
119+
gff_ids = self.gff_obj.search(
120+
self.cursor, self.uid, [("origin", "!=", "sample_origin1")]
121+
)
122+
123+
self.assertEqual(len(gff_ids), 3)
124+
125+
def test_search_equal_operator_active(self):
126+
self.set_invoice_origin_cerca_exacte(self.cursor, self.uid, "1")
127+
128+
gff_ids = self.gff_obj.search(
129+
self.cursor, self.uid, [("origin", "=", "sample_origin1")]
130+
)
131+
132+
self.assertEqual(len(gff_ids), 1)

0 commit comments

Comments
 (0)