Skip to content

Commit 5d35f55

Browse files
committed
MPT-12552 RQLQuery add operations all and any
1 parent c2704a7 commit 5d35f55

File tree

4 files changed

+39
-2
lines changed

4 files changed

+39
-2
lines changed

mpt_api_client/mpt.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ def __init__(
1313
registry: Registry | None = None,
1414
mpt_client: MPTClient | None = None,
1515
):
16-
1716
self.mpt_client = mpt_client or MPTClient(base_url=base_url, api_token=api_key)
1817
self.registry: Registry = registry or Registry()
1918

mpt_api_client/rql/query_builder.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,8 @@ class RQLQuery: # noqa: WPS214
144144

145145
AND = "and" # noqa: WPS115
146146
OR = "or" # noqa: WPS115
147+
ANY = "any" # noqa: WPS115
148+
ALL = "all" # noqa: WPS115
147149
EXPRESSION = "expr" # noqa: WPS115
148150

149151
def __init__( # noqa: WPS211
@@ -250,6 +252,29 @@ def __getattr__(self, name: str) -> Self:
250252
def __str__(self) -> str:
251253
return self._to_string(self)
252254

255+
def any(self) -> Self:
256+
"""Any nested objects have to match the filter condition.
257+
258+
Returns:
259+
RQLQuery: RQLQuery with new condition
260+
261+
Examples:
262+
RQLQuery(saleDetails__orderQty__gt=11).any()
263+
will result: any(saleDetails,orderQty=11)
264+
"""
265+
return self.new(op=self.ANY, children=[self])
266+
267+
def all(self) -> Self:
268+
"""All nested objects have to match the filter condition.
269+
270+
Returns:
271+
RQLQuery: RQLQuery with new condition
272+
273+
Example:
274+
RQLQuery(saleDetails__orderQty__gt=1).all()
275+
"""
276+
return self.new(op=self.ALL, children=[self])
277+
253278
def n(self, name: str) -> Self: # noqa: WPS111
254279
"""Set the current field for this `RQLQuery` object.
255280

tests/modules/test_order.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
from mpt_api_client.modules.order import Order, OrderCollectionClient
32

43

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
from mpt_api_client.rql import RQLQuery
2+
3+
4+
def test_all():
5+
query = RQLQuery(saleDetails__orderQty__gt=1).all()
6+
7+
rql = str(query)
8+
assert rql == "all(gt(saleDetails.orderQty,1))"
9+
10+
11+
def test_any():
12+
query = RQLQuery(saleDetails__orderQty__gt=1).any()
13+
rql = str(query)
14+
assert rql == "any(gt(saleDetails.orderQty,1))"

0 commit comments

Comments
 (0)