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
!181
Feature/add constrain to spa
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Feature/add constrain to spa
feature/add-constrain-to-spa
into
dev
Overview
9
Commits
6
Pipelines
7
Changes
1
1 unresolved thread
Hide all comments
Merged
emanuel buzey
requested to merge
feature/add-constrain-to-spa
into
dev
1 year ago
Overview
9
Commits
6
Pipelines
7
Changes
1
1 unresolved thread
Hide all comments
Expand
This is the
link
to the Trello card
Edited
1 year ago
by
emanuel buzey
0
0
Merge request reports
Viewing commit
f7914842
Show latest version
1 file
+
20
−
22
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
f7914842
Revert "Constraints added to the SupplyPointAssignation model"
· f7914842
ebuzeyTra
authored
1 year ago
This reverts commit
1a1f77c1
.
energy_selfconsumption/models/supply_point_assignation.py
+
20
−
22
Options
from
odoo
import
api
,
fields
,
models
,
_
from
odoo
import
fields
,
models
,
api
from
odoo.exceptions
import
ValidationError
class
SupplyPointAssignation
(
models
.
Model
):
_name
=
"
energy_selfconsumption.supply_point_assignation
"
_description
=
"
Supply Point Assignation
"
_name
=
'
energy_selfconsumption.supply_point_assignation
'
_description
=
'
Supply Point Assignation
'
@api.depends
(
"
distribution_table_id
"
)
@api.depends
(
'
distribution_table_id
'
)
def
_compute_supply_point_filtered_ids
(
self
):
'''
List of supply point of partners subscribed to the project and not in the list of the distribution table to
@@ -16,35 +16,33 @@ class SupplyPointAssignation(models.Model):
'''
for
record
in
self
:
record
.
supply_point_filtered_ids
=
\
record
.
distribution_table_id
.
selfconsumption_project_id
.
inscription_ids
.
mapped
(
"
partner_id.supply_ids
"
)
\
.
filtered_domain
([(
"
id
"
,
"
not in
"
,
record
.
distribution_table_id
.
supply_point_assignation_ids
.
mapped
(
"
supply_point_id.id
"
))])
record
.
distribution_table_id
.
selfconsumption_project_id
.
inscription_ids
.
mapped
(
'
partner_id.supply_ids
'
)
\
.
filtered_domain
([(
'
id
'
,
'
not in
'
,
record
.
distribution_table_id
.
supply_point_assignation_ids
.
mapped
(
'
supply_point_id.id
'
))])
distribution_table_id
=
fields
.
Many2one
(
"
energy_selfconsumption.distribution_table
"
,
required
=
True
)
selfconsumption_project_id
=
fields
.
Many2one
(
related
=
"
distribution_table_id.selfconsumption_project_id
"
)
distribution_table_state
=
fields
.
Selection
(
related
=
"
distribution_table_id.state
"
)
distribution_table_create_date
=
fields
.
Datetime
(
related
=
"
distribution_table_id.create_date
"
)
supply_point_id
=
fields
.
Many2one
(
"
energy_selfconsumption.supply_point
"
,
required
=
True
)
coefficient
=
fields
.
Float
(
string
=
"
Distribution coefficient
"
,
digits
=
(
1
,
5
),
required
=
True
,
distribution_table_id
=
fields
.
Many2one
(
'
energy_selfconsumption.distribution_table
'
,
required
=
True
)
selfconsumption_project_id
=
fields
.
Many2one
(
related
=
'
distribution_table_id.selfconsumption_project_id
'
)
distribution_table_state
=
fields
.
Selection
(
related
=
'
distribution_table_id.state
'
)
distribution_table_create_date
=
fields
.
Datetime
(
related
=
'
distribution_table_id.create_date
'
)
supply_point_id
=
fields
.
Many2one
(
'
energy_selfconsumption.supply_point
'
,
required
=
True
)
coefficient
=
fields
.
Float
(
string
=
'
Distribution coefficient
'
,
digits
=
(
1
,
5
),
required
=
True
,
help
=
"
The sum of all the coefficients must result in 1
"
)
owner_id
=
fields
.
Many2one
(
"
res.partner
"
,
related
=
"
supply_point_id.owner_id
"
)
code
=
fields
.
Char
(
related
=
"
supply_point_id.code
"
)
table_coefficient_is_valid
=
fields
.
Boolean
(
related
=
"
distribution_table_id.coefficient_is_valid
"
)
owner_id
=
fields
.
Many2one
(
"
res.partner
"
,
related
=
'
supply_point_id.owner_id
'
)
code
=
fields
.
Char
(
related
=
'
supply_point_id.code
'
)
table_coefficient_is_valid
=
fields
.
Boolean
(
related
=
'
distribution_table_id.coefficient_is_valid
'
)
supply_point_filtered_ids
=
fields
.
One2many
(
"
energy_selfconsumption.supply_point
"
,
supply_point_filtered_ids
=
fields
.
One2many
(
'
energy_selfconsumption.supply_point
'
,
compute
=
_compute_supply_point_filtered_ids
,
readonly
=
True
)
company_id
=
fields
.
Many2one
(
"
res.company
"
,
default
=
lambda
self
:
self
.
env
.
company
,
readonly
=
True
)
@api.constrains
(
"
coefficient
"
,
"
owner_id
"
)
@api.constrains
(
'
coefficient
'
)
def
constraint_coefficient
(
self
):
for
record
in
self
:
if
record
.
owner_id
and
not
record
.
owner_id
.
member
:
raise
ValidationError
(
_
(
"
The selected partner is not a member
"
))
if
record
.
coefficient
<
0
:
raise
ValidationError
(
_
(
"
Coefficient can
'
t be negative.
"
)
)
raise
ValidationError
(
"
Coefficient can
'
t be negative.
"
)
@api.onchange
(
"
coefficient
"
)
@api.onchange
(
'
coefficient
'
)
def
_onchange_coefficient
(
self
):
if
self
.
coefficient
<
0
:
self
.
coefficient
=
-
self
.
coefficient
Loading