Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Odoo CE
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
Comunitats Energètiques
Odoo CE
Merge requests
!185
constrain added and unlink method extended
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
constrain added and unlink method extended
feature/unsubscribe-project-partner
into
dev
Overview
16
Commits
10
Pipelines
10
Changes
4
Merged
emanuel buzey
requested to merge
feature/unsubscribe-project-partner
into
dev
1 year ago
Overview
10
Commits
10
Pipelines
10
Changes
4
Expand
This the
link
to the Trello card
Edited
1 year ago
by
emanuel buzey
0
0
Merge request reports
Compare
dev
version 9
27f3ebee
1 year ago
version 8
58d1b181
1 year ago
version 7
3933a447
1 year ago
version 6
5956fd9d
1 year ago
version 5
fe14d73c
1 year ago
version 4
a77c2d0d
1 year ago
version 3
4ceb6225
1 year ago
version 2
fb9de273
1 year ago
version 1
7266ab79
1 year ago
dev (base)
and
latest version
latest version
a082ec36
10 commits,
1 year ago
version 9
27f3ebee
9 commits,
1 year ago
version 8
58d1b181
8 commits,
1 year ago
version 7
3933a447
7 commits,
1 year ago
version 6
5956fd9d
6 commits,
1 year ago
version 5
fe14d73c
5 commits,
1 year ago
version 4
a77c2d0d
4 commits,
1 year ago
version 3
4ceb6225
3 commits,
1 year ago
version 2
fb9de273
2 commits,
1 year ago
version 1
7266ab79
1 commit,
1 year ago
4 files
+
49
−
6
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
4
Search (e.g. *.vue) (Ctrl+P)
energy_project/models/inscription.py
+
29
−
1
Options
from
odoo
import
_
,
fields
,
models
from
odoo
import
_
,
api
,
fields
,
models
from
odoo.exceptions
import
ValidationError
class
Inscription
(
models
.
Model
):
@@ -30,3 +31,30 @@ class Inscription(models.Model):
string
=
"
Partner
"
,
)
effective_date
=
fields
.
Date
(
required
=
True
)
def
has_matching_supply_assignations
(
self
):
matching_tables
=
self
.
project_id
.
selfconsumption_id
.
distribution_table_ids
.
filtered
(
lambda
table
:
table
.
state
in
(
'
validated
'
,
'
process
'
,
'
active
'
)
)
matching_assignations
=
matching_tables
.
mapped
(
'
supply_point_assignation_ids
'
).
filtered
(
lambda
assignation
:
assignation
.
supply_point_id
.
partner_id
==
self
.
partner_id
)
return
matching_assignations
def
get_matching_supply_assignations_to_remove
(
self
):
supply_point_assignations
=
self
.
env
[
'
energy_selfconsumption.supply_point_assignation
'
].
search
([
(
'
supply_point_id.partner_id
'
,
'
=
'
,
self
.
partner_id
.
id
),
(
'
selfconsumption_project_id
'
,
'
=
'
,
self
.
project_id
.
id
),
(
'
distribution_table_id.state
'
,
'
=
'
,
'
draft
'
)
])
return
supply_point_assignations
def
unlink
(
self
):
matching_assignations
=
self
.
has_matching_supply_assignations
()
if
len
(
matching_assignations
)
>
0
:
table_states
=
'
,
'
.
join
(
matching_assignations
.
distribution_table_id
.
mapped
(
'
state
'
))
raise
ValidationError
(
_
(
"
The inscription cannot be deleted. It is related to a distribution table with state: {table_state}
"
).
format
(
table_state
=
table_states
))
supply_point_assignations
=
self
.
get_matching_supply_assignations_to_remove
()
if
supply_point_assignations
:
supply_point_assignations
.
unlink
()
return
super
(
Inscription
,
self
).
unlink
()
Loading