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
Merged
emanuel buzey
requested to merge
feature/add-constrain-to-spa
into
dev
1 year ago
Overview
7
Commits
6
Pipelines
7
Changes
1
Expand
This is the
link
to the Trello card
Edited
1 year ago
by
emanuel buzey
0
0
Merge request reports
Viewing commit
eb55eff9
Show latest version
1 file
+
6
−
4
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
eb55eff9
The search by inscribed partner is fixed
· eb55eff9
ebuzeyTra
authored
1 year ago
energy_selfconsumption/models/supply_point_assignation.py
+
11
−
2
Options
from
odoo
import
fields
,
models
,
api
from
odoo
import
fields
,
models
,
api
,
_
from
odoo.exceptions
import
ValidationError
@@ -41,16 +41,25 @@ class SupplyPointAssignation(models.Model):
related
=
"
distribution_table_id.coefficient_is_valid
"
)
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
'
)
def
constraint_coefficient
(
self
):
for
record
in
self
:
if
record
.
coefficient
<
0
:
raise
ValidationError
(
"
Coefficient can
'
t be negative.
"
)
raise
ValidationError
(
_
(
"
Coefficient can
'
t be negative.
"
))
@api.constrains
(
"
supply_point_id
"
)
def
constraint_supply_point_id
(
self
):
for
record
in
self
:
supply_points
=
record
.
distribution_table_id
.
selfconsumption_project_id
.
inscription_ids
.
mapped
(
'
partner_id.supply_ids
'
)
if
record
.
supply_point_id
.
id
not
in
supply_points
.
ids
:
raise
ValidationError
(
_
(
"
The partner of the supply point is not subscribed to the project
"
))
@api.onchange
(
'
coefficient
'
)
def
_onchange_coefficient
(
self
):
Loading