Skip to content
Snippets Groups Projects

Feature/variable hourly dist table

Closed emanuel buzey requested to merge feature/variable_hourly_dist_table into dev
1 file
+ 17
9
Compare changes
  • Side-by-side
  • Inline
from odoo import _, api, fields, models
from odoo.exceptions import ValidationError
STATE_VALUES = [
("draft", _("Draft")),
("validated", _("Validated")),
@@ -9,7 +8,10 @@ STATE_VALUES = [
("active", _("Active")),
]
TYPE_VALUES = [("fixed", _("Fixed"))]
TYPE_VALUES = [
("fixed", _("Fixed")),
("variable_schedule", _("Variable schedule")),
]
class DistributionTable(models.Model):
@@ -49,16 +51,22 @@ class DistributionTable(models.Model):
@api.model
def create(self, vals):
vals['name'] = self.env.ref('energy_selfconsumption.distribution_table_sequence', False).next_by_id()
return super(DistributionTable, self).create(vals)
vals["name"] = self.env.ref(
"energy_selfconsumption.distribution_table_sequence", False
).next_by_id()
return super().create(vals)
@api.constrains('supply_point_assignation_ids')
@api.constrains("supply_point_assignation_ids")
def _supply_point_constrain(self):
for record in self:
if record.state in ('validated', 'process', 'active'):
raise ValidationError(_("The supply point can't be removed because the distribution table state is {table_state}").format(table_state=record.state))
@api.onchange('selfconsumption_project_id')
if record.state in ("validated", "process", "active"):
raise ValidationError(
_(
"The supply point can't be removed because the distribution table state is {table_state}"
).format(table_state=record.state)
)
@api.onchange("selfconsumption_project_id")
def _onchange_selfconsumption_project_id(self):
self.supply_point_assignation_ids = False
Loading