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
9becded7
Commit
9becded7
authored
10 years ago
by
Houzefa Abbasbhay
Browse files
Options
Downloads
Patches
Plain Diff
Analytic codes can be blacklisted per company
parent
d15ef62b
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
MetaAnalytic.py
+2
-1
2 additions, 1 deletion
MetaAnalytic.py
README
+16
-0
16 additions, 0 deletions
README
analytic_code.py
+91
-2
91 additions, 2 deletions
analytic_code.py
analytic_structure.py
+1
-1
1 addition, 1 deletion
analytic_structure.py
analytic_views.xml
+26
-11
26 additions, 11 deletions
analytic_views.xml
with
136 additions
and
15 deletions
MetaAnalytic.py
+
2
−
1
View file @
9becded7
...
@@ -102,7 +102,8 @@
...
@@ -102,7 +102,8 @@
"
Generated Analytic Field
"
,
"
Generated Analytic Field
"
,
domain
=
[
domain
=
[
(
domain_field
,
'
=
'
,
model_name
),
(
domain_field
,
'
=
'
,
model_name
),
(
'
usable
'
,
'
=
'
,
True
)
(
'
usable
'
,
'
=
'
,
True
),
(
'
usable_per_company
'
,
'
=
'
,
True
),
],
],
track_visibility
=
'
onchange
'
,
track_visibility
=
'
onchange
'
,
)
)
...
...
This diff is collapsed.
Click to expand it.
README
+
16
−
0
View file @
9becded7
...
@@ -166,3 +166,19 @@
...
@@ -166,3 +166,19 @@
name_get and name_search, using those of analytic code.
name_get and name_search, using those of analytic code.
This allows the analytic code's description to be displayed (and searched)
This allows the analytic code's description to be displayed (and searched)
along with the entry's name in many2one fields targeting the model.
along with the entry's name in many2one fields targeting the model.
=== Active / Usable / Usable in my company ===
Differences between the various "active" fields:
- Active: Controls whether the code is in the referential; when inactive, a
code is invisible.
- Usable: Controls whether the code can be selected; unlike "active", it is
still in the referential.
- Usable per company: Controls whether the code can be selected by users in the
company of the current user; unlike "active", it is still in the referential.
This diff is collapsed.
Click to expand it.
analytic_code.py
+
91
−
2
View file @
9becded7
...
@@ -31,6 +31,77 @@
...
@@ -31,6 +31,77 @@
_parent_order
=
'
name
'
_parent_order
=
'
name
'
_order
=
'
parent_left
'
_order
=
'
parent_left
'
def
_read_usable_per_company
(
self
,
cr
,
uid
,
ids
,
field_name
,
arg
,
context
):
"""
Mark the code as usable when it is not in the blacklist (depending
on the current user
'
s company).
"""
anc_obj
=
self
.
pool
[
'
analytic.code
'
]
user_obj
=
self
.
pool
[
'
res.users
'
]
company_id
=
user_obj
.
read
(
cr
,
uid
,
[
uid
],
[
'
company_id
'
],
context
=
context
)[
0
][
'
company_id
'
][
0
]
ret
=
{}
for
anc
in
anc_obj
.
browse
(
cr
,
uid
,
ids
,
context
=
context
):
blacklist
=
(
company
.
id
for
company
in
anc
.
blacklist_ids
)
ret
[
anc
.
id
]
=
company_id
not
in
blacklist
return
ret
def
_write_usable_per_company
(
self
,
cr
,
uid
,
anc_id
,
field_name
,
field_value
,
arg
,
context
):
"""
Update the blacklist depending on the current user
'
s company.
"""
anc_obj
=
self
.
pool
[
'
analytic.code
'
]
user_obj
=
self
.
pool
[
'
res.users
'
]
company_id
=
user_obj
.
read
(
cr
,
uid
,
[
uid
],
[
'
company_id
'
],
context
=
context
)[
0
][
'
company_id
'
][
0
]
anc
=
anc_obj
.
browse
(
cr
,
uid
,
anc_id
,
context
=
context
)
blacklist
=
(
company
.
id
for
company
in
anc
.
blacklist_ids
)
to_write
=
None
if
field_value
and
company_id
in
blacklist
:
to_write
=
[(
3
,
company_id
)]
# Unlink.
elif
not
field_value
and
company_id
not
in
blacklist
:
to_write
=
[(
4
,
company_id
)]
# Link.
if
to_write
:
anc_obj
.
write
(
cr
,
uid
,
[
anc_id
],
{
'
blacklist_ids
'
:
to_write
},
context
=
context
)
return
True
def
_search_usable_per_company
(
self
,
cr
,
uid
,
model_again
,
field_name
,
criterion
,
context
):
"""
Update the domain to take the blacklist into account (depending on
the current user
'
s company).
"""
user_obj
=
self
.
pool
[
'
res.users
'
]
company_id
=
user_obj
.
read
(
cr
,
uid
,
[
uid
],
[
'
company_id
'
],
context
=
context
)[
0
][
'
company_id
'
][
0
]
# We assume the criterion was "usable_per_company = True".
return
[
'
|
'
,
(
'
blacklist_ids
'
,
'
=
'
,
False
),
(
'
blacklist_ids.id
'
,
'
!=
'
,
company_id
),
]
_columns
=
{
_columns
=
{
'
name
'
:
fields
.
char
(
'
name
'
:
fields
.
char
(
u
"
Name
"
,
u
"
Name
"
,
...
@@ -46,6 +117,23 @@
...
@@ -46,6 +117,23 @@
),
),
'
active
'
:
fields
.
boolean
(
u
"
Active
"
),
'
active
'
:
fields
.
boolean
(
u
"
Active
"
),
'
usable
'
:
fields
.
boolean
(
u
"
Usable
"
),
'
usable
'
:
fields
.
boolean
(
u
"
Usable
"
),
'
blacklist_ids
'
:
fields
.
many2many
(
'
res.company
'
,
'
analytic_code_company_rel
'
,
'
code_id
'
,
'
company_id
'
,
u
"
Blacklist
"
,
help
=
u
"
Companies the code is hidden in.
"
,
),
'
usable_per_company
'
:
fields
.
function
(
_read_usable_per_company
,
fnct_inv
=
_write_usable_per_company
,
fnct_search
=
_search_usable_per_company
,
method
=
True
,
type
=
'
boolean
'
,
store
=
False
,
# Not persistent as it dpeends on the company.
string
=
u
"
Usable in my company
"
,
),
'
nd_name
'
:
fields
.
related
(
'
nd_name
'
:
fields
.
related
(
'
nd_id
'
,
'
nd_id
'
,
'
name
'
,
'
name
'
,
...
@@ -74,8 +162,9 @@
...
@@ -74,8 +162,9 @@
}
}
_defaults
=
{
_defaults
=
{
'
active
'
:
1
,
'
active
'
:
lambda
*
a
:
True
,
'
usable
'
:
1
,
'
usable
'
:
lambda
*
a
:
True
,
'
usable_per_company
'
:
lambda
*
a
:
True
,
}
}
_constraints
=
[
_constraints
=
[
...
...
This diff is collapsed.
Click to expand it.
analytic_structure.py
+
1
−
1
View file @
9becded7
...
@@ -82,7 +82,7 @@
...
@@ -82,7 +82,7 @@
}
}
_defaults
=
{
_defaults
=
{
'
company_id
'
:
False
,
'
company_id
'
:
lambda
*
a
:
False
,
}
}
_constraints
=
[
_constraints
=
[
...
...
This diff is collapsed.
Click to expand it.
analytic_views.xml
+
26
−
11
View file @
9becded7
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
<field
name=
"model"
>
analytic.code
</field>
<field
name=
"model"
>
analytic.code
</field>
<field
name=
"arch"
type=
"xml"
>
<field
name=
"arch"
type=
"xml"
>
<tree
string=
"Analytic Codes"
version=
"7.0"
editable=
"bottom"
>
<tree
string=
"Analytic Codes"
version=
"7.0"
>
<field
name=
"id"
invisible=
"1"
/>
<field
name=
"id"
invisible=
"1"
/>
<field
name=
"active"
/>
<field
name=
"active"
/>
<field
name=
"usable"
/>
<field
name=
"usable"
/>
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
<field
name=
"id"
invisible=
"1"
/>
<field
name=
"id"
invisible=
"1"
/>
<field
name=
"active"
/>
<field
name=
"active"
/>
<field
name=
"usable"
/>
<field
name=
"usable"
/>
<field
name=
"usable_per_company"
/>
<field
name=
"name"
/>
<field
name=
"name"
/>
<field
name=
"description"
/>
<field
name=
"description"
/>
<field
name=
"nd_id"
<field
name=
"nd_id"
...
@@ -52,16 +53,30 @@
...
@@ -52,16 +53,30 @@
<field
name=
"model"
>
analytic.code
</field>
<field
name=
"model"
>
analytic.code
</field>
<field
name=
"arch"
type=
"xml"
>
<field
name=
"arch"
type=
"xml"
>
<form
string=
"Analytic Code"
>
<form
string=
"Analytic Code"
>
<field
name=
"id"
invisible=
"1"
/>
<group>
<field
name=
"active"
/>
<field
name=
"id"
invisible=
"1"
/>
<field
name=
"usable"
/>
<field
name=
"name"
/>
<group>
<field
name=
"description"
/>
<field
name=
"name"
/>
<field
name=
"nd_id"
<field
name=
"description"
/>
invisible=
"context.get('default_nd_id', None) is not None"
<field
name=
"nd_id"
required=
"context.get('default_nd_id', None) is not False"
/>
invisible=
"context.get('default_nd_id', None) is not None"
<field
name=
"code_parent_id"
attrs=
"{'readonly': [('nd_id', '=', False)]}"
required=
"context.get('default_nd_id', None) is not False"
/>
domain=
"[('id', '!=', id), ('nd_id', '=', nd_id)]"
/>
<field
name=
"code_parent_id"
attrs=
"{'readonly': [('nd_id', '=', False)]}"
domain=
"[('id', '!=', id), ('nd_id', '=', nd_id)]"
/>
</group>
<group>
<field
name=
"active"
/>
<field
name=
"usable"
/>
<field
name=
"usable_per_company"
/>
</group>
<group
colspan=
"2"
>
<field
name=
"blacklist_ids"
groups=
"base.group_multi_company"
/>
</group>
</group>
</form>
</form>
</field>
</field>
</record>
</record>
...
...
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