Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
A
Analytic Structure
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
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
Analytic Structure
Commits
901393ca6efe
Commit
901393ca6efe
authored
9 years ago
by
Brendan Masson
Browse files
Options
Downloads
Patches
Plain Diff
Add delete restrictions on analytic objects to maintain coherence
parent
5ab4da6db72d
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
MetaAnalytic.py
+70
-2
70 additions, 2 deletions
MetaAnalytic.py
with
70 additions
and
2 deletions
MetaAnalytic.py
+
70
−
2
View file @
901393ca
...
...
@@ -110,6 +110,7 @@
(
'
view_type
'
,
'
=
'
,
False
),
(
'
disabled_per_company
'
,
'
=
'
,
False
),
],
ondelete
=
'
restrict
'
,
track_visibility
=
'
onchange
'
,
index
=
True
,
)
...
...
@@ -180,6 +181,48 @@
return
res
@AddMethod
(
superclass
)
@api.cr_uid_context
def
unlink
(
self
,
cr
,
uid
,
ids
,
context
=
None
):
"""
When removing this object, remove all associated analytic
codes referenced by this object.
Note: the method will fail if the code is referenced by any other
object due to the RESTRICT constraint. That is the intended
behavior.
"""
analytic_obj
=
self
.
pool
[
'
analytic.structure
'
]
code_obj
=
self
.
pool
[
'
analytic.code
'
]
# Gather analytic values
analytic_values
=
[]
for
record
in
self
.
browse
(
cr
,
uid
,
ids
,
context
=
context
):
for
prefix
,
struct
in
analytic
.
iteritems
():
values
=
analytic_obj
.
extract_values
(
cr
,
uid
,
record
,
struct
,
prefix
=
prefix
,
context
=
context
)
analytic_values
.
append
(
values
)
# Find all related codes
code_ids
=
[]
for
values
in
analytic_values
:
filtered_code_ids
=
filter
(
None
,
values
.
values
())
code_ids
.
extend
(
filtered_code_ids
)
# Set analytic fields to null
if
analytic_values
:
# The keys are all the same
fields
=
analytic_values
[
0
].
keys
()
vals
=
{
field
:
False
for
field
in
fields
}
self
.
write
(
cr
,
uid
,
ids
,
vals
)
code_obj
.
unlink
(
cr
,
uid
,
code_ids
,
context
=
context
)
res
=
super
(
superclass
,
self
).
unlink
(
cr
,
uid
,
ids
,
context
=
context
)
return
res
return
(
superclass
,)
@classmethod
...
...
@@ -300,6 +343,7 @@
related
=
"
.
"
.
join
([
column
,
code_col
]),
relation
=
"
analytic.code
"
,
required
=
req
,
ondelete
=
'
restrict
'
,
store
=
True
)
if
model_col
not
in
defaults
:
...
...
@@ -417,8 +461,6 @@
self
.
_generate_code_ref_id
(
cr
,
uid
,
res
,
context
=
context
)
if
new_code_id
:
from
pprint
import
pprint
pprint
(
'
{},{}
'
.
format
(
self
.
_name
,
res
))
code_osv
.
write
(
cr
,
uid
,
new_code_id
,
{
'
origin_id
'
:
'
{},{}
'
.
format
(
self
.
_name
,
res
),
})
...
...
@@ -488,6 +530,32 @@
return
res
@AddMethod
(
superclass
)
@api.cr_uid_ids_context
def
unlink
(
self
,
cr
,
uid
,
ids
,
context
=
None
):
"""
When removing this object, remove all associated analytic
codes referenced by this object.
Note: the method will fail if the code is referenced by any other
object due to the RESTRICT constraint. That is the intended
behavior.
"""
code_obj
=
self
.
pool
[
'
analytic.code
'
]
# Find all related codes
code_ids
=
[
record
[
column
].
id
for
record
in
self
.
browse
(
cr
,
uid
,
ids
,
context
=
context
)
]
res
=
super
(
superclass
,
self
).
unlink
(
cr
,
uid
,
ids
,
context
=
context
)
# self.write(cr, uid, ids, {column: False}, context=context)
code_obj
.
unlink
(
cr
,
uid
,
code_ids
,
context
=
context
)
return
res
@AddMethod
(
superclass
)
def
_force_code
(
self
,
cr
,
uid
,
force_code_id
,
code_vals
,
context
=
None
):
code_osv
=
self
.
pool
[
'
analytic.code
'
]
...
...
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