Skip to content
Snippets Groups Projects
Commit cf5ba05e authored by Emanuel Buzey's avatar Emanuel Buzey Committed by Daniil Digtyar Vasilieva
Browse files

[REF] energy_selfconsumption: move action to change state to active to wizard

parent 4629e32b
No related branches found
No related tags found
2 merge requests!253[REL] Release 06/11/23,!211[IMP] energy_selfconsumption: invoicing acquired power
......@@ -107,6 +107,24 @@ class Selfconsumption(models.Model):
self.distribution_table_state("validated", "process")
def activate(self):
"""
Activates the energy self-consumption project, performing various validations.
This method checks for the presence of a valid code, CIL, and rated power
for the project. If all validations pass, it opens a wizard for generating
contracts for the project.
Note:
The change of state for the 'self-consumption' and 'distribution_table'
models is performed in the wizard that gets opened. These state changes
are executed only after the contracts have been successfully generated.
Returns:
dict: A dictionary containing the action details for opening the wizard.
Raises:
ValidationError: If the project does not have a valid Code, CIL, or Rated Power.
"""
for record in self:
if not record.code:
raise ValidationError(_("Project must have a valid Code."))
......@@ -124,9 +142,6 @@ class Selfconsumption(models.Model):
"target": "new",
"context": {"default_selfconsumption_id": self.id},
}
# Move state write to contract wizard
# record.write({"state": "active"})
# self.distribution_table_state("process", "active")
def action_selfconsumption_import_wizard(self):
self.ensure_one()
......
......@@ -39,6 +39,8 @@ class ContractGenerationWizard(models.TransientModel):
It first creates a product and a contract formula. It then
aggregates supply point assignations by partner and owner
to generate the contracts.
In the other hand, if the process was successful, the state of self-consumption
and the distribution_table changes to 'active'.
Returns:
bool: Always True, indicating successful execution.
......@@ -134,4 +136,7 @@ class ContractGenerationWizard(models.TransientModel):
}
)
# Update selfconsumption and distribution_table state
self.selfconsumption_id.write({"state": "active"})
self.selfconsumption_id.distribution_table_state("process", "active")
return True
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