Skip to content
Snippets Groups Projects
Commit b31cbfd3 authored by Juliana's avatar Juliana
Browse files

[ADD]Add unicity constraint id PRM

parent 02f9ebd0
No related branches found
No related tags found
No related merge requests found
......@@ -3,6 +3,8 @@
from odoo import api, fields, models
from odoo.exceptions import ValidationError
class AccCounter(models.Model):
_name = "acc.counter"
......@@ -12,7 +14,7 @@ class AccCounter(models.Model):
# Fields declaration
# ------------------------------------------------------
# General Info
name = fields.Char("ID PRM", required=True)
name = fields.Char("ID PRM", required=True, index=True)
acc_operation_id = fields.Many2one("acc.operation", string="Opération liée")
date_start_contract = fields.Date("Date de début", default=fields.Datetime.now)
date_end_contract = fields.Date("Date de fin", default=fields.Datetime.now)
......@@ -26,6 +28,7 @@ class AccCounter(models.Model):
domain="['|', ('is_consumer', '=', True), ('is_producer', '=', True)]",
)
test = fields.Char("test")
# Info Soutirage counter
is_delivery = fields.Boolean("Est un point de soutirage")
power_delivery = fields.Float("Puissance soutirage (en kW)")
......@@ -44,10 +47,20 @@ class AccCounter(models.Model):
string="Acheteur de surplus",
domain="[('is_buyer_surplus', '=', True)]",
)
# ------------------------------------------------------
# SQL Constraints
# ------------------------------------------------------
_sql_constraints = [("name", "unique(name)", "L'ID PRM exite déjà !")]
@api.constrains('name')
def _check_name(self):
for record in self:
if record.name:
prm_ids = self.search_count(
[('name', '=', record.name)])
if prm_ids > 0:
raise ValidationError("L'ID PRM exite déjà !")
# ------------------------------------------------------
# Default methods
# ------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment