Skip to content
Snippets Groups Projects
Commit 85f856fa authored by ebuzeyTra's avatar ebuzeyTra
Browse files

Revert "Constraints added to the SupplyPointAssignation model"

This reverts commit 1a1f77c1.
parent ebb579e0
No related branches found
No related tags found
2 merge requests!195[REL] 14.0.2.0.0,!181Feature/add constrain to spa
This commit is part of merge request !181. Comments created here will be created in the context of that merge request.
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,10 +16,9 @@ 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
......@@ -43,20 +42,18 @@ class SupplyPointAssignation(models.Model):
)
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
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment