Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
C
Coopdevs OCB mirror
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Coopdevs
Odoo
Coopdevs OCB mirror
Commits
eba5bcdc
Commit
eba5bcdc
authored
14 years ago
by
Pankti Parikh
Committed by
Husen Daudi
14 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Improved yml import for recording osv.memory objects
bzr revid: hda@tinyerp.com-20100430141810-pvp1ah28b5j6fsxo
parent
7b6827a6
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
bin/tools/yaml_import.py
+55
-28
55 additions, 28 deletions
bin/tools/yaml_import.py
bin/tools/yaml_tag.py
+18
-21
18 additions, 21 deletions
bin/tools/yaml_tag.py
with
73 additions
and
49 deletions
bin/tools/yaml_import.py
+
55
−
28
View file @
eba5bcdc
...
...
@@ -256,28 +256,41 @@ class YamlInterpreter(object):
b
=
default
return
b
def
create_osv_memory_record
(
self
,
record
,
fields
):
model
=
self
.
get_model
(
record
.
model
)
record_dict
=
self
.
_create_record
(
model
,
fields
)
id_new
=
model
.
create
(
self
.
cr
,
self
.
uid
,
record_dict
,
context
=
self
.
context
)
self
.
id_map
[
record
.
id
]
=
int
(
id_new
)
return
record_dict
def
process_record
(
self
,
node
):
import
osv
record
,
fields
=
node
.
items
()[
0
]
self
.
validate_xml_id
(
record
.
id
)
if
self
.
isnoupdate
(
record
)
and
self
.
mode
!=
'
init
'
:
id
=
self
.
pool
.
get
(
'
ir.model.data
'
).
_update_dummy
(
self
.
cr
,
self
.
uid
,
record
.
model
,
self
.
module
,
record
.
id
)
# check if the resource already existed at the last update
if
id
:
self
.
id_map
[
record
]
=
int
(
id
)
return
None
else
:
if
not
self
.
_coerce_bool
(
record
.
forcecreate
):
return
None
model
=
self
.
get_model
(
record
.
model
)
record_dict
=
self
.
_create_record
(
model
,
fields
)
self
.
logger
.
debug
(
"
RECORD_DICT %s
"
%
record_dict
)
id
=
self
.
pool
.
get
(
'
ir.model.data
'
).
_update
(
self
.
cr
,
self
.
uid
,
record
.
model
,
\
self
.
module
,
record_dict
,
record
.
id
,
noupdate
=
self
.
isnoupdate
(
record
),
mode
=
self
.
mode
)
self
.
id_map
[
record
.
id
]
=
int
(
id
)
if
config
.
get
(
'
import_partial
'
,
False
):
self
.
cr
.
commit
()
model_bases
=
model
.
__class__
.
__bases__
if
osv
.
osv
.
osv_memory
in
model_bases
:
record_dict
=
self
.
create_osv_memory_record
(
record
,
fields
)
else
:
self
.
validate_xml_id
(
record
.
id
)
if
self
.
isnoupdate
(
record
)
and
self
.
mode
!=
'
init
'
:
id
=
self
.
pool
.
get
(
'
ir.model.data
'
).
_update_dummy
(
self
.
cr
,
self
.
uid
,
record
.
model
,
self
.
module
,
record
.
id
)
# check if the resource already existed at the last update
if
id
:
self
.
id_map
[
record
]
=
int
(
id
)
return
None
else
:
if
not
self
.
_coerce_bool
(
record
.
forcecreate
):
return
None
model
=
self
.
get_model
(
record
.
model
)
record_dict
=
self
.
_create_record
(
model
,
fields
)
self
.
logger
.
debug
(
"
RECORD_DICT %s
"
%
record_dict
)
if
not
osv
.
osv
.
osv_memory
in
model_bases
:
id
=
self
.
pool
.
get
(
'
ir.model.data
'
).
_update
(
self
.
cr
,
self
.
uid
,
record
.
model
,
\
self
.
module
,
record_dict
,
record
.
id
,
noupdate
=
self
.
isnoupdate
(
record
),
mode
=
self
.
mode
)
self
.
id_map
[
record
.
id
]
=
int
(
id
)
if
config
.
get
(
'
import_partial
'
,
False
):
self
.
cr
.
commit
()
def
_create_record
(
self
,
model
,
fields
):
record_dict
=
{}
...
...
@@ -390,6 +403,10 @@ class YamlInterpreter(object):
uid
=
workflow
.
uid
else
:
uid
=
self
.
uid
self
.
cr
.
execute
(
'
select distinct signal from wkf_transition
'
)
signals
=
[
x
[
'
signal
'
]
for
x
in
self
.
cr
.
dictfetchall
()]
if
workflow
.
action
not
in
signals
:
raise
YamlImportException
(
'
Incorrect action %s. No such action defined
'
%
workflow
.
action
)
wf_service
=
netsvc
.
LocalService
(
"
workflow
"
)
wf_service
.
trg_validate
(
uid
,
workflow
.
model
,
id
,
workflow
.
action
,
self
.
cr
)
...
...
@@ -528,15 +545,19 @@ class YamlInterpreter(object):
'
tree_but_open
'
,
'
Menuitem
'
,
[(
'
ir.ui.menu
'
,
int
(
parent_id
))],
action
,
True
,
True
,
xml_id
=
node
.
id
)
def
process_act_window
(
self
,
node
):
assert
getattr
(
node
,
'
id
'
),
"
Attribute %s of act_window is empty !
"
%
(
'
id
'
,)
assert
getattr
(
node
,
'
name
'
),
"
Attribute %s of act_window is empty !
"
%
(
'
name
'
,)
assert
getattr
(
node
,
'
res_model
'
),
"
Attribute %s of act_window is empty !
"
%
(
'
res_model
'
,)
self
.
validate_xml_id
(
node
.
id
)
view_id
=
False
if
node
.
view
:
view_id
=
self
.
get_id
(
node
.
view
)
context
=
eval
(
node
.
context
,
self
.
eval_context
)
if
not
node
.
context
:
node
.
context
=
{}
context
=
eval
(
str
(
node
.
context
),
self
.
eval_context
)
values
=
{
'
name
'
:
node
.
name
,
'
type
'
:
type
or
'
ir.actions.act_window
'
,
'
type
'
:
node
.
type
or
'
ir.actions.act_window
'
,
'
view_id
'
:
view_id
,
'
domain
'
:
node
.
domain
,
'
context
'
:
context
,
...
...
@@ -566,13 +587,17 @@ class YamlInterpreter(object):
# TODO add remove ir.model.data
def
process_delete
(
self
,
node
):
if
len
(
node
.
search
):
ids
=
self
.
pool
.
get
(
node
.
model
).
search
(
self
.
cr
,
self
.
uid
,
eval
(
node
.
search
,
self
.
eval_context
))
assert
getattr
(
node
,
'
model
'
),
"
Attribute %s of delete tag is empty !
"
%
(
'
model
'
,)
if
self
.
pool
.
get
(
node
.
model
):
if
len
(
node
.
search
):
ids
=
self
.
pool
.
get
(
node
.
model
).
search
(
self
.
cr
,
self
.
uid
,
eval
(
node
.
search
,
self
.
eval_context
))
else
:
ids
=
[
self
.
get_id
(
node
.
id
)]
if
len
(
ids
):
self
.
pool
.
get
(
node
.
model
).
unlink
(
self
.
cr
,
self
.
uid
,
ids
)
self
.
pool
.
get
(
'
ir.model.data
'
).
_unlink
(
self
.
cr
,
self
.
uid
,
node
.
model
,
ids
)
else
:
ids
=
[
self
.
get_id
(
node
.
id
)]
if
len
(
ids
):
self
.
pool
.
get
(
node
.
model
).
unlink
(
self
.
cr
,
self
.
uid
,
ids
)
self
.
pool
.
get
(
'
ir.model.data
'
).
_unlink
(
self
.
cr
,
self
.
uid
,
node
.
model
,
ids
)
self
.
logger
.
log
(
logging
.
TEST
,
"
Record not deleted.
"
)
def
process_url
(
self
,
node
):
self
.
validate_xml_id
(
node
.
id
)
...
...
@@ -649,6 +674,8 @@ class YamlInterpreter(object):
"""
Processes a Yaml string. Custom tags are interpreted by
'
process_
'
instance methods.
"""
yaml_tag
.
add_constructors
()
is_preceded_by_comment
=
False
for
node
in
yaml
.
load
(
yaml_string
):
is_preceded_by_comment
=
self
.
_log
(
node
,
is_preceded_by_comment
)
...
...
This diff is collapsed.
Click to expand it.
bin/tools/yaml_tag.py
+
18
−
21
View file @
eba5bcdc
...
...
@@ -48,9 +48,7 @@ class Workflow(YamlTag):
super
(
Workflow
,
self
).
__init__
(
**
kwargs
)
class
ActWindow
(
YamlTag
):
def
__init__
(
self
,
model
,
action
,
**
kwargs
):
self
.
model
=
model
self
.
action
=
action
def
__init__
(
self
,
**
kwargs
):
super
(
ActWindow
,
self
).
__init__
(
**
kwargs
)
class
Function
(
YamlTag
):
...
...
@@ -67,10 +65,7 @@ class Report(YamlTag):
super
(
Report
,
self
).
__init__
(
**
kwargs
)
class
Delete
(
YamlTag
):
def
__init__
(
self
,
model
,
id
,
search
,
**
kwargs
):
self
.
model
=
model
self
.
id
=
id
self
.
search
=
search
def
__init__
(
self
,
**
kwargs
):
super
(
Delete
,
self
).
__init__
(
**
kwargs
)
class
Context
(
YamlTag
):
...
...
@@ -156,17 +151,19 @@ def ir_set_constructor(loader, node):
# Registers constructors for custom tags.
# Constructors are actually defined globally: do not redefined them in another
# class/file/package. This means that module recorder need import this file.
yaml
.
add_constructor
(
u
"
!assert
"
,
assert_constructor
)
yaml
.
add_constructor
(
u
"
!record
"
,
record_constructor
)
yaml
.
add_constructor
(
u
"
!python
"
,
python_constructor
)
yaml
.
add_constructor
(
u
"
!menuitem
"
,
menuitem_constructor
)
yaml
.
add_constructor
(
u
"
!workflow
"
,
workflow_constructor
)
yaml
.
add_constructor
(
u
"
!act_window
"
,
act_window_constructor
)
yaml
.
add_constructor
(
u
"
!function
"
,
function_constructor
)
yaml
.
add_constructor
(
u
"
!report
"
,
report_constructor
)
yaml
.
add_constructor
(
u
"
!context
"
,
context_constructor
)
yaml
.
add_constructor
(
u
"
!delete
"
,
delete_constructor
)
yaml
.
add_constructor
(
u
"
!url
"
,
url_constructor
)
yaml
.
add_constructor
(
u
"
!eval
"
,
eval_constructor
)
yaml
.
add_multi_constructor
(
u
"
!ref
"
,
ref_constructor
)
yaml
.
add_constructor
(
u
"
!ir_set
"
,
ir_set_constructor
)
def
add_constructors
():
yaml
.
add_constructor
(
u
"
!assert
"
,
assert_constructor
)
yaml
.
add_constructor
(
u
"
!record
"
,
record_constructor
)
yaml
.
add_constructor
(
u
"
!python
"
,
python_constructor
)
yaml
.
add_constructor
(
u
"
!menuitem
"
,
menuitem_constructor
)
yaml
.
add_constructor
(
u
"
!workflow
"
,
workflow_constructor
)
yaml
.
add_constructor
(
u
"
!act_window
"
,
act_window_constructor
)
yaml
.
add_constructor
(
u
"
!function
"
,
function_constructor
)
yaml
.
add_constructor
(
u
"
!report
"
,
report_constructor
)
yaml
.
add_constructor
(
u
"
!context
"
,
context_constructor
)
yaml
.
add_constructor
(
u
"
!delete
"
,
delete_constructor
)
yaml
.
add_constructor
(
u
"
!url
"
,
url_constructor
)
yaml
.
add_constructor
(
u
"
!eval
"
,
eval_constructor
)
yaml
.
add_multi_constructor
(
u
"
!ref
"
,
ref_constructor
)
yaml
.
add_constructor
(
u
"
!ir_set
"
,
ir_set_constructor
)
add_constructors
()
\ No newline at end of file
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