Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Converter
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
XCG
Odoo modules
Converter
Commits
0de61891edac
Commit
0de61891edac
authored
1 month ago
by
Vincent Hatakeyama
Browse files
Options
Downloads
Patches
Plain Diff
Add JsonLD_ID converter
parent
e87d2e751c85
No related branches found
No related tags found
1 merge request
!60
Add JsonLD_ID converter
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
NEWS.rst
+5
-0
5 additions, 0 deletions
NEWS.rst
__init__.py
+1
-1
1 addition, 1 deletion
__init__.py
__manifest__.py
+1
-1
1 addition, 1 deletion
__manifest__.py
xref.py
+103
-4
103 additions, 4 deletions
xref.py
with
110 additions
and
6 deletions
NEWS.rst
+
5
−
0
View file @
0de61891
Changelog
Changelog
=========
=========
18.0.4.1.0
----------
Add JsonLD_ID converter.
18.0.4.0.0
18.0.4.0.0
----------
----------
...
...
This diff is collapsed.
Click to expand it.
__init__.py
+
1
−
1
View file @
0de61891
...
@@ -52,4 +52,4 @@
...
@@ -52,4 +52,4 @@
NotInitialized
,
NotInitialized
,
Validator
,
Validator
,
)
)
from
.xref
import
Xref
from
.xref
import
Xref
,
JsonLD_ID
This diff is collapsed.
Click to expand it.
__manifest__.py
+
1
−
1
View file @
0de61891
...
@@ -21,7 +21,7 @@
...
@@ -21,7 +21,7 @@
"
name
"
:
"
Converter
"
,
"
name
"
:
"
Converter
"
,
"
license
"
:
"
AGPL-3
"
,
"
license
"
:
"
AGPL-3
"
,
"
summary
"
:
"
Convert odoo records to/from plain data structures.
"
,
"
summary
"
:
"
Convert odoo records to/from plain data structures.
"
,
"
version
"
:
"
18.0.4.
0
.0
"
,
"
version
"
:
"
18.0.4.
1
.0
"
,
"
category
"
:
"
Hidden
"
,
"
category
"
:
"
Hidden
"
,
"
author
"
:
"
XCG Consulting
"
,
"
author
"
:
"
XCG Consulting
"
,
"
website
"
:
"
https://orbeet.io/
"
,
"
website
"
:
"
https://orbeet.io/
"
,
...
...
This diff is collapsed.
Click to expand it.
xref.py
+
103
−
4
View file @
0de61891
##############################################################################
##############################################################################
#
#
# Converter Odoo module
# Converter Odoo module
# Copyright © 2020 XCG Consulting <https://xcg-consulting.fr>
# Copyright © 2020
, 2025
XCG Consulting <https://xcg-consulting.fr>
#
#
# This program is free software: you can redistribute it and/or modify
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU Affero General Public License as
# it under the terms of the GNU Affero General Public License as
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
#
##############################################################################
##############################################################################
import
logging
import
os
from
typing
import
Any
from
typing
import
Any
...
@@ -21,4 +22,4 @@
...
@@ -21,4 +22,4 @@
from
typing
import
Any
from
typing
import
Any
from
odoo
import
api
,
models
# type: ignore[import-untyped]
from
odoo
import
_
,
api
,
models
# type: ignore[import-untyped]
...
@@ -24,4 +25,11 @@
...
@@ -24,4 +25,11 @@
from
.base
import
Context
,
NewinstanceType
,
PostHookConverter
from
.base
import
(
Context
,
ContextBuilder
,
Converter
,
NewinstanceType
,
PostHookConverter
,
build_context
,
)
from
.models.ir_model_data
import
_XREF_IMD_MODULE
from
.models.ir_model_data
import
_XREF_IMD_MODULE
...
@@ -26,5 +34,7 @@
...
@@ -26,5 +34,7 @@
from
.models.ir_model_data
import
_XREF_IMD_MODULE
from
.models.ir_model_data
import
_XREF_IMD_MODULE
_logger
=
logging
.
getLogger
(
__name__
)
# TODO dans quel cas ça ne pourrait pas être un instance getter???
# TODO dans quel cas ça ne pourrait pas être un instance getter???
class
Xref
(
PostHookConverter
):
class
Xref
(
PostHookConverter
):
...
@@ -65,3 +75,92 @@
...
@@ -65,3 +75,92 @@
@property
@property
def
is_instance_getter
(
self
)
->
bool
:
def
is_instance_getter
(
self
)
->
bool
:
return
self
.
_is_instance_getter
return
self
.
_is_instance_getter
class
JsonLD_ID
(
Xref
):
"""
This converter represents a JsonLD ID , an url made of
a base part defined as ir.config_parameter, an optional breadcrumb
and a unique id part using the standard xmlid.
"""
def
__init__
(
self
,
breadcrumb
:
str
|
Converter
,
module
:
str
|
None
=
_XREF_IMD_MODULE
,
is_instance_getter
:
bool
=
True
,
unique_id_field
:
str
|
None
=
None
,
context
:
ContextBuilder
|
None
=
None
,
has_base_url
:
bool
=
True
,
):
"""
:param breadcrumb: Part of the url describing the entity,
must match the syntax expected by os.path, ie absolute path
begins with a slash. With absolute path the base part is
ignored. Can also be a converter, if so, the result of the
combined converters must be a string.
"""
super
().
__init__
(
module
=
module
,
is_instance_getter
=
is_instance_getter
,
)
self
.
converter
:
Converter
|
None
=
None
self
.
_breadcrumb
=
breadcrumb
if
isinstance
(
breadcrumb
,
str
)
else
None
if
isinstance
(
breadcrumb
,
Converter
):
self
.
converter
=
breadcrumb
self
.
_unique_id_field
=
unique_id_field
self
.
_context
=
context
self
.
_has_base_url
=
has_base_url
def
odoo_to_message
(
self
,
instance
:
models
.
BaseModel
,
ctx
:
Context
=
None
)
->
Any
:
if
not
instance
:
return
""
ctx
=
build_context
(
instance
,
ctx
,
self
.
_context
)
if
self
.
_unique_id_field
is
not
None
:
name
=
getattr
(
instance
,
self
.
_unique_id_field
)
else
:
_module
,
name
=
instance
.
env
[
"
ir.model.data
"
].
object_to_module_and_name
(
instance
,
self
.
_module
)
jsonld_id_base_url
=
(
instance
.
env
[
"
ir.config_parameter
"
]
.
sudo
()
.
get_param
(
"
sync.jsonld_id_base_url
"
)
)
if
self
.
_has_base_url
and
not
jsonld_id_base_url
:
_logger
.
error
(
_
(
"
Missing config parameter:
'
sync.jsonld_id_base_url
'
is not defined
"
)
)
return
""
if
self
.
converter
is
not
None
:
self
.
_breadcrumb
=
self
.
converter
.
odoo_to_message
(
instance
,
ctx
)
xref
=
os
.
path
.
join
(
jsonld_id_base_url
if
self
.
_has_base_url
else
""
,
self
.
_breadcrumb
if
self
.
_breadcrumb
is
not
None
else
""
,
name
,
)
instance
.
env
[
"
ir.model.data
"
].
set_xmlid
(
instance
,
xref
,
module
=
self
.
_module
,
only_when_missing
=
True
)
# In case of jsonld_id, replace the xref generated by
# `object_to_module_and_name` with jsonld format.
if
self
.
_has_base_url
:
# Need sudo as typical user does not have the rights on ir.model.data
imd
=
(
instance
.
env
[
"
ir.model.data
"
]
.
sudo
()
.
search
(
[
(
"
module
"
,
"
=
"
,
self
.
_module
),
(
"
model
"
,
"
=
"
,
instance
.
_name
),
(
"
res_id
"
,
"
=
"
,
instance
.
id
),
]
)
)
imd
.
write
({
"
name
"
:
xref
})
return
xref
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment