Skip to content

Added tests and handling for empty Date/Datetime fields to 15.0 #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: 15.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,4 @@ cython_debug/


# IDE
.vscode
.vscode
49 changes: 49 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
default_language_version:
python: python3.9
repos:
- repo: https://github.com/pre-commit/pre-commit-hooks
rev: v4.5.0
hooks:
- id: trailing-whitespace
- id: check-docstring-first
- id: check-added-large-files
- id: check-yaml
- id: debug-statements
- id: check-merge-conflict
- id: end-of-file-fixer

# This should be before auto-providers to ensure that the yaml file is correct
# - repo: https://github.com/adrienverge/yamllint.git
# rev: v1.34.0
# hooks:
# - id: yamllint
# pass_filenames: false
# args: [--strict, -f, colored, -c, .yamllint.yml, .]

- repo: https://github.com/astral-sh/ruff-pre-commit
# Ruff version.
rev: v0.5.0
hooks:
# Run the linter.
- id: ruff
args: [ --fix ]
# args: [odoo_graphql, --fix]
# Run the formatter.
- id: ruff-format
# Do not use cache to prevent conflict on pipeline
# https://github.com/python-poetry/poetry/issues/8189
# - repo: https://github.com/python-poetry/poetry
# rev: '1.6.0' # add version here
# hooks:
# - id: poetry-check
# args: [--no-cache]
# language_version: python3.9
# - id: poetry-lock
# args: [--no-cache]
# language_version: python3.9

# - repo: https://github.com/python-poetry/poetry-plugin-export
# rev: '1.6.0' # add version here
# hooks:
# - id: poetry-export
# args: ["--no-cache", "-f", "requirements.txt", "-o", "requirements.txt"]
1 change: 0 additions & 1 deletion COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,3 @@ When that is not the case, the files contain a prominent
notice stating the original copyright and applicable
license, or come with their own dedicated COPYRIGHT
and/or LICENSE file.

7 changes: 1 addition & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This module takes into account any installed modules and use the Odoo permission

```javascript
query Tickets {
HelpdeskTicket(domain: $domain, limit: $limit) {
HelpdeskTicket(domain: $domain, limit: $limit) {
name
description
user: user_id @include(if: $user_info) {
Expand Down Expand Up @@ -117,8 +117,3 @@ odoo.graphql(
```

Nb: Those works using the defaults routes of Odoo. If you have changed them using your proxy, you will need to make your own _odoo_builder_. To help you, the __odoo_utils_ structure is made for you.





2 changes: 1 addition & 1 deletion TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
* Use the correct [response format](https://spec.graphql.org/June2018/#sec-Response-Format) (OK?)
* [Subscription](https://dgraph.io/docs/graphql/subscriptions/) => Odoo does not support websocket currently

*
*
2 changes: 1 addition & 1 deletion copy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ done

rm "$DEST/__manifest__.pyc"
rm -r "$DEST/tests"
cp "__manifest__.py" "README.md" "COPYRIGHT" "LICENSE" "$DEST"
cp "__manifest__.py" "README.md" "COPYRIGHT" "LICENSE" "$DEST"
4 changes: 2 additions & 2 deletions make_compile.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ done
for pyc in $(find $MODULE -name '*cpython*.pyc');
do
NEW_NAME="$(echo $pyc | sed 's/cpython.*\.//g')"
echo "$pyc -> $NEW_NAME"
echo "$pyc -> $NEW_NAME"
mv "$pyc" $NEW_NAME
done


rm "$MODULE/__manifest__.pyc" "$MODULE/copy.sh" "$MODULE/make_compile.sh"
rm -r "$MODULE/tests"
rm -r "$MODULE/tests"
1 change: 0 additions & 1 deletion odoo_graphql/COPYRIGHT
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ All files are

and published under the Odoo Proprietary License v1.0,
as described in the LICENSE file.

2 changes: 1 addition & 1 deletion odoo_graphql/LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ It is forbidden to publish, distribute, sublicense, or sell copies of the Softwa

The above copyright notice and this permission notice must be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
THE SOFTWARE IS PROVIDED « AS IS », WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
9 changes: 2 additions & 7 deletions odoo_graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ This module takes into account any installed modules and use the Odoo permission

```javascript
query Tickets {
HelpdeskTicket(domain: $domain, limit: $limit) {
HelpdeskTicket(domain: $domain, limit: $limit) {
name
description
user: user_id @include(if: $user_info) {
Expand All @@ -33,7 +33,7 @@ To use the query:
```python
requests.get("https://myodoo.com/graphql",
# Header not required currently but recommended
headers={"Content-type": "application/graphql"},
headers={"Content-type": "application/graphql"},
data={
"query": myquery,
"variables": {}, # Optional
Expand Down Expand Up @@ -143,8 +143,3 @@ odoo.graphql(
```

Nb: Those works using the defaults routes of Odoo. If you have changed them using your proxy, you will need to make your own _odoo_builder_. To help you, the __odoo_utils_ structure is made for you.





5 changes: 1 addition & 4 deletions odoo_graphql/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
# -*- coding: utf-8 -*-

from . import controllers
from . import models
from . import controllers, models
2 changes: 0 additions & 2 deletions odoo_graphql/__manifest__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
# -*- coding: utf-8 -*-

{
"name": "Odoo GraphQL",
"version": "2.0",
Expand Down
4 changes: 1 addition & 3 deletions odoo_graphql/controllers/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
# -*- coding: utf-8 -*-

from . import graphql
from . import graphql
22 changes: 12 additions & 10 deletions odoo_graphql/controllers/graphql.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
from odoo import http
from odoo.http import request, content_disposition
from odoo.exceptions import ValidationError
import werkzeug
import json

import logging

import werkzeug
from odoo import http
from odoo.http import request

_logger = logging.getLogger(__name__)


class GraphQL(http.Controller):
@http.route(
"/graphql", auth="public", type="http", website=True, sitemap=False, csrf=False,
"/graphql",
auth="public",
type="http",
website=True,
sitemap=False,
csrf=False,
)
def graphql(self):
# https://spec.graphql.org/June2018/#sec-Response-Format
Expand All @@ -20,12 +24,10 @@ def graphql(self):
payload = json.dumps(response, indent=4)
return payload

@http.route(
"/graphiql", type="http", website=True, sitemap=False
)
@http.route("/graphiql", type="http", website=True, sitemap=False)
def graphiql(self):
introspection = request.env["graphql.handler"].has_introspection()
if not introspection:
raise werkzeug.exceptions.NotFound()
# raise ValidationError("Introspection is not allowed")
return request.render("odoo_graphql.graphiql")
return request.render("odoo_graphql.graphiql")
14 changes: 7 additions & 7 deletions odoo_graphql/examples/frontend_alpines.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
></script>
</head>
<body>
<script src="libs/graphql.js"></script>
<script src="libs/graphql.js"></script>
<script>
const url = "http://192.168.1.113:8100";
const odoo = odoo_builder(url, "graphql");

async function getTickets(variables) {
let data = await odoo.graphql(`
query Tickets {
HelpdeskTicket(domain: $domain, limit: $limit) {
HelpdeskTicket(domain: $domain, limit: $limit) {
name
description
user: user_id @include(if: $user_info) {
Expand Down Expand Up @@ -110,7 +110,7 @@
async function test2(parameters) {
let data = await odoo.graphql(`
query Test {
SaleOrder(domain: $domain, limit: $limit) {
SaleOrder(domain: $domain, limit: $limit) {
name
state
partner_id @include(if: $partner_id) {
Expand Down Expand Up @@ -146,7 +146,7 @@
};
/*
let ticket = (await test3({"name": "test", description: "hello world"}))["tickets"][0] // Create a new ticket
await test3({domain: [["id", "=", ticket.id]], "name": "name changed", description: "hello world2"}) // Update the
await test3({domain: [["id", "=", ticket.id]], "name": "name changed", description: "hello world2"}) // Update the
*/

async function odoo_login(login, password) {
Expand All @@ -164,7 +164,7 @@
<button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon"></span>
</button>

<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav mr-auto">
<li class="nav-item active">
Expand Down Expand Up @@ -261,7 +261,7 @@ <h5 x-text="ticket.name" class="card-title">Card title</h5>
</template>
</div>
</div>


</body>
<script>
Expand All @@ -277,4 +277,4 @@ <h5 x-text="ticket.name" class="card-title">Card title</h5>
Alpine.store("user", data || {});
})
</script>
</html>
</html>
2 changes: 1 addition & 1 deletion odoo_graphql/examples/libs/graphql.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,4 +114,4 @@ function odoo_builder(url, database) {
graphql: _odoo_utils.graphqlbuilder(url + '/graphql'),
session: () => {return _odoo_utils.odoo_session(url + '/web/session/get_session_info')},
}
}
}
2 changes: 1 addition & 1 deletion odoo_graphql/examples/libs/graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,4 @@ def graphql(self, query, variables={}, operationName=None):
},
data=json.dumps(body)
)
return res
return res
4 changes: 2 additions & 2 deletions odoo_graphql/examples/test_graphql.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
print(res.content.decode())

query2 = """query Tickets {
HelpdeskTicket(domain: $domain, limit: $limit) {
HelpdeskTicket(domain: $domain, limit: $limit) {
name
description
user: user_id @include(if: $user_info) {
Expand All @@ -74,7 +74,7 @@
res = graphql.graphql(query2, {
"domain": [],
"user_info": True,
"partner_id": True,
"partner_id": True,
"limit": 100
})
print(json.dumps(json.loads(res.content.decode()), indent=4))
11 changes: 6 additions & 5 deletions odoo_graphql/examples/test_graphql2.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import requests
import json

"""
Use graphql query by providing credentials in the query (instead of using cookies)
"""
import requests
import json


query = """query Tickets {
HelpdeskTicket(domain: $domain, limit: $limit) {
HelpdeskTicket(domain: $domain, limit: $limit) {
name
description
user: user_id @include(if: $user_info) {
Expand Down Expand Up @@ -34,7 +35,7 @@
"variables": {
"domain": [],
"user_info": True,
"partner_id": True,
"partner_id": True,
"limit": 100
},
"auth": {
Expand All @@ -43,4 +44,4 @@
}
})
)
print(json.dumps(json.loads(res.content.decode()), indent=4))
print(json.dumps(json.loads(res.content.decode()), indent=4))
2 changes: 1 addition & 1 deletion odoo_graphql/examples/test_introspection.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ def pn(node):
name
}
}""").definitions[0]
t_field = t_insp.selection_set.selections[0]
t_field = t_insp.selection_set.selections[0]
Empty file.
Loading