From 3d2ace97bd6fd2508e8471bd230463a8091fbfbd Mon Sep 17 00:00:00 2001 From: Daniil Digtyar Vasilieva <daniildigtyar@gmail.com> Date: Thu, 2 Nov 2023 14:12:47 +0100 Subject: [PATCH] [IMP] energy_selfconsumption: validate selected contract are the correct invoicing mode --- .../wizards/invoicing_wizard.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/energy_selfconsumption/wizards/invoicing_wizard.py b/energy_selfconsumption/wizards/invoicing_wizard.py index 046f70621..35b5f6988 100644 --- a/energy_selfconsumption/wizards/invoicing_wizard.py +++ b/energy_selfconsumption/wizards/invoicing_wizard.py @@ -12,6 +12,25 @@ class InvoicingWizard(models.TransientModel): def constraint_contract_ids(self): for record in self: contract_list = record.contract_ids + + valid_invoicing_mode = ["energy_delivered"] + + all_invoicing_mode = all( + element.project_id.selfconsumption_id.invoicing_mode + in valid_invoicing_mode + for element in contract_list + ) + if not all_invoicing_mode: + raise ValidationError( + _( + """ +Some of the contract selected are not defined as energy delivered self-consumption projects. + +Please make sure that you are invoicing the correct self-consumption project. +""" + ) + ) + all_equal_period = all( element.next_period_date_start == contract_list[0].next_period_date_start -- GitLab