From b07f6be6db37e6e70d85515d8193b48b7e9ccc4f Mon Sep 17 00:00:00 2001
From: Emanuel Buzey <buzeyemanuel@gmail.com>
Date: Thu, 26 Oct 2023 12:38:21 +0200
Subject: [PATCH] [FIX] energy_selfconsumption: set name field correctly

---
 .../wizards/contract_generation_wizard.py                  | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/energy_selfconsumption/wizards/contract_generation_wizard.py b/energy_selfconsumption/wizards/contract_generation_wizard.py
index bb8933a70..476967c1f 100644
--- a/energy_selfconsumption/wizards/contract_generation_wizard.py
+++ b/energy_selfconsumption/wizards/contract_generation_wizard.py
@@ -64,7 +64,14 @@ class ContractGenerationWizard(models.TransientModel):
                     "contract_template_id": self.selfconsumption_id.product_id.contract_template_id.id,
                 }
             )
+            # We use the next method from the contract model to update the contract fields with contract template
             contract._onchange_contract_template_id()
+            # Now, we need to update the name field using the code and display_name fields
+            name = _("""CUPS: %s\nOwner: %s\nInvoicing period: #START# - #END#""") % (
+                supply_point_assignation.supply_point_id.code,
+                supply_point_assignation.supply_point_id.owner_id.display_name,
+            )
+            contract.contract_line_ids.name = name
         # Update selfconsumption and distribution_table state
         self.selfconsumption_id.write({"state": "active"})
         self.selfconsumption_id.distribution_table_state("process", "active")
-- 
GitLab