From 9b2507a97219453e0856c8e82ef9acff72611667 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Garc=C3=ADa?= <alvarogruiz8@gmail.com> Date: Wed, 19 Feb 2025 16:15:18 +0100 Subject: [PATCH 1/4] =?UTF-8?q?[FIX]=20=F0=9F=90=9B=20Now=20it=20is=20chec?= =?UTF-8?q?ked=20if=20two=20mandatory=20fields=20in=20the=20import=20are?= =?UTF-8?q?=20filled=20in=20and=20the=20appropriate=20error=20notification?= =?UTF-8?q?=20is=20displayed.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: Alvaro Garcia <alvaro.garcia@somit.coop> --- .../wizards/selfconsumption_import_wizard.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/energy_selfconsumption/wizards/selfconsumption_import_wizard.py b/energy_selfconsumption/wizards/selfconsumption_import_wizard.py index 95d062b15..796e0fb41 100644 --- a/energy_selfconsumption/wizards/selfconsumption_import_wizard.py +++ b/energy_selfconsumption/wizards/selfconsumption_import_wizard.py @@ -75,7 +75,7 @@ class SelfconsumptionImportWizard(models.TransientModel): for index, line in enumerate(parsing_data): error, import_dict = self.get_line_dict(line) if error: - error_string_list += "".join( + error_string_list = "".join( [ error_string_list, _("<li>Line {line}: {error}</li>\n").format( @@ -85,7 +85,7 @@ class SelfconsumptionImportWizard(models.TransientModel): ) result = self.import_line(import_dict, project) if result[0]: - error_string_list += "".join( + error_string_list = "".join( [ error_string_list, _("<li>Line {line}: {error}</li>\n").format( @@ -158,7 +158,7 @@ class SelfconsumptionImportWizard(models.TransientModel): "effective_date": line.get(header[1], False), "supplypoint_cups": line.get(header[2], False), "supplypoint_contracted_power": float( - str(line.get(header[3], 0.0)).replace(",", ".") + str(line.get(header[3], 0.0) if line.get(header[3],0.0)!='' else 0.0).replace(",", ".") ), "tariff": line.get(header[4], False), "supplypoint_street": line.get(header[5], False), @@ -190,10 +190,10 @@ class SelfconsumptionImportWizard(models.TransientModel): header[24], False ), # New "inscriptionselfconsumption_annual_electricity_use": float( - str(line.get(header[25], 0.0)).replace(",", ".") + str(line.get(header[25], 0.0) if line.get(header[25],0.0)!='' else 0.0).replace(",", ".") ), # New "inscriptionselfconsumption_participation": float( - str(line.get(header[26], 0.0)).replace(",", ".") + str(line.get(header[26], 0.0) if line.get(header[26],0.0)!='' else 0.0).replace(",", ".") ), # New "inscriptionselfconsumption_accept": line.get(header[27], False), # New } -- GitLab From 88a0edc33b4fbbc2e902ad55cddc3c13380bdc7a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Garc=C3=ADa?= <alvarogruiz8@gmail.com> Date: Wed, 19 Feb 2025 17:02:39 +0100 Subject: [PATCH 2/4] =?UTF-8?q?[FIX]=20=F0=9F=90=9B=20Added=20control=20th?= =?UTF-8?q?at=20the=20date=20of=20birth=20may=20not=20be=20filled=20in=20a?= =?UTF-8?q?nd=20the=20holder=20is=20searched=20for=20with=20the=20company?= =?UTF-8?q?=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: Alvaro Garcia <alvaro.garcia@somit.coop> --- energy_selfconsumption/models/create_inscription.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/energy_selfconsumption/models/create_inscription.py b/energy_selfconsumption/models/create_inscription.py index c6282b9a0..f2734ce64 100644 --- a/energy_selfconsumption/models/create_inscription.py +++ b/energy_selfconsumption/models/create_inscription.py @@ -353,7 +353,7 @@ class CreateInscription(models.AbstractModel): state = self._get_state(values, project, country) lang = self._get_language(values) formatted_birthdate = self._get_formatted_birthdate(values) - owner = self._get_existing_contact_owner(values) + owner = self._get_existing_contact_owner(values, project) if not owner: return self._create_new_owner( @@ -400,23 +400,24 @@ class CreateInscription(models.AbstractModel): def _get_formatted_birthdate(self, values): """Gets the formatted date of birth.""" - if "supplypoint_owner_id_birthdate_date" in values: + if "supplypoint_owner_id_birthdate_date" in values and values["supplypoint_owner_id_birthdate_date"] != '': birthdate_obj = datetime.strptime( values["supplypoint_owner_id_birthdate_date"], "%d/%m/%Y" ) return birthdate_obj.strftime("%Y-%m-%d") return None - def _get_existing_contact_owner(self, values): + def _get_existing_contact_owner(self, values, project): """Search for an existing VAT-based owner.""" return ( self.env["res.partner"] .sudo() .search( [ + ("company_ids", "in", (project.company_id.id)), ("vat", "=", values["supplypoint_owner_id_vat"]), ("type", "=", "contact"), - ] + ], limit=1 ) ) -- GitLab From ea17b8e0831740669cf90da71b17eb7133131bfc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Garc=C3=ADa?= <alvarogruiz8@gmail.com> Date: Wed, 19 Feb 2025 17:05:39 +0100 Subject: [PATCH 3/4] =?UTF-8?q?[FIX]=20=F0=9F=90=9B=20the=20holder=20is=20?= =?UTF-8?q?searched=20for=20with=20the=20company=20condition?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: Alvaro Garcia <alvaro.garcia@somit.coop> --- energy_selfconsumption/models/create_inscription.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/energy_selfconsumption/models/create_inscription.py b/energy_selfconsumption/models/create_inscription.py index f2734ce64..788bd459c 100644 --- a/energy_selfconsumption/models/create_inscription.py +++ b/energy_selfconsumption/models/create_inscription.py @@ -421,7 +421,7 @@ class CreateInscription(models.AbstractModel): ) ) - def _get_existing_owner_self_consumption_owner(self, values): + def _get_existing_owner_self_consumption_owner(self, values, project): """Search for an existing VAT-based owner.""" return ( self.env["res.partner"] @@ -430,7 +430,8 @@ class CreateInscription(models.AbstractModel): [ ("vat", "=", values["supplypoint_owner_id_vat"]), ("type", "=", "owner_self-consumption"), - ] + ("company_ids", "in", (project.company_id.id)), + ], limit=1 ) ) @@ -470,7 +471,7 @@ class CreateInscription(models.AbstractModel): def _update_owner_address(self, project, owner, values, country, state): """Update the address of an existing owner.""" - exists = self._get_existing_owner_self_consumption_owner(values) + exists = self._get_existing_owner_self_consumption_owner(values, project) if exists: vals = { "name": values["supplypoint_owner_id_name"], -- GitLab From ff89042ada688dd8708d2edbae7f4fe095fc9101 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81lvaro=20Garc=C3=ADa?= <alvarogruiz8@gmail.com> Date: Mon, 24 Feb 2025 13:30:14 +0100 Subject: [PATCH 4/4] =?UTF-8?q?[FIX]=20=F0=9F=90=9B=20more=20control=20err?= =?UTF-8?q?ors?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Author: Alvaro Garcia <alvaro.garcia@somit.coop> --- .../models/create_inscription.py | 75 +++++++++++-------- energy_selfconsumption/models/supply_point.py | 2 +- 2 files changed, 46 insertions(+), 31 deletions(-) diff --git a/energy_selfconsumption/models/create_inscription.py b/energy_selfconsumption/models/create_inscription.py index 788bd459c..82889af45 100644 --- a/energy_selfconsumption/models/create_inscription.py +++ b/energy_selfconsumption/models/create_inscription.py @@ -51,9 +51,10 @@ class CreateInscription(models.AbstractModel): "cadastral_reference": values["supplypoint_cadastral_reference"], } if project.conf_used_in_selfconsumption: - vals["used_in_selfconsumption"] = values.get( - "supplypoint_used_in_selfconsumption", None - ) + if values.get("supplypoint_used_in_selfconsumption", False) and values.get("supplypoint_used_in_selfconsumption", False) != "": + vals["used_in_selfconsumption"] = values.get( + "supplypoint_used_in_selfconsumption", None + ) supply_point = ( self.env["energy_selfconsumption.supply_point"].sudo().create(vals) ) @@ -340,11 +341,12 @@ class CreateInscription(models.AbstractModel): """Obtains or creates the owner of the supply.""" if values.get("supplypoint_owner_id_same", "no") == "yes": if project.conf_vulnerability_situation: - partner.sudo().write( - { - "vulnerability_situation": values.get( - "supplypoint_owner_id_vulnerability_situation", None - ) + if values.get("supplypoint_owner_id_vulnerability_situation", False) and values.get("supplypoint_owner_id_vulnerability_situation", False) != "": + partner.sudo().write( + { + "vulnerability_situation": values.get( + "supplypoint_owner_id_vulnerability_situation", None + ) } ) return partner @@ -464,9 +466,10 @@ class CreateInscription(models.AbstractModel): "zip": values["supplypoint_zip"], } if project.conf_vulnerability_situation: - vals["vulnerability_situation"] = values.get( - "supplypoint_owner_id_vulnerability_situation", None - ) + if values.get("supplypoint_owner_id_vulnerability_situation", False) and values.get("supplypoint_owner_id_vulnerability_situation", False) != "": + vals["vulnerability_situation"] = values.get( + "supplypoint_owner_id_vulnerability_situation", None + ) return self.env["res.partner"].sudo().create(vals) def _update_owner_address(self, project, owner, values, country, state): @@ -474,30 +477,41 @@ class CreateInscription(models.AbstractModel): exists = self._get_existing_owner_self_consumption_owner(values, project) if exists: vals = { - "name": values["supplypoint_owner_id_name"], - "lastname": values["supplypoint_owner_id_lastname"], - "gender": values.get("supplypoint_owner_id_gender"), - "birthdate_date": self._get_formatted_birthdate(values), - "phone": values.get("supplypoint_owner_id_phone"), - "lang": self._get_language(values).code - if self._get_language(values) - else None, - "email": values.get("supplypoint_owner_id_email"), - "vat": values["supplypoint_owner_id_vat"], "type": "owner_self-consumption", "company_id": project.company_id.id, "company_type": "person", "parent_id": owner.id, "country_id": country.id, "state_id": state.id, - "street": values["supplypoint_street"], - "city": values["supplypoint_city"], - "zip": values["supplypoint_zip"], } + if values.get("supplypoint_owner_id_name", False) and values.get("supplypoint_owner_id_name", False) != "": + vals["name"] = values["supplypoint_owner_id_name"] + if values.get("supplypoint_owner_id_lastname", False) and values.get("supplypoint_owner_id_lastname", False) != "": + vals["lastname"] = values["supplypoint_owner_id_lastname"] + if values.get("supplypoint_owner_id_gender", False) and values.get("supplypoint_owner_id_gender", False) != "": + vals["gender"] = values.get("supplypoint_owner_id_gender") + if values.get("supplypoint_owner_id_birthdate_date", False) and values.get("supplypoint_owner_id_birthdate_date", False) != "": + vals["birthdate_date"] = self._get_formatted_birthdate(values) + if values.get("supplypoint_owner_id_phone", False) and values.get("supplypoint_owner_id_phone", False) != "": + vals["phone"] = values.get("supplypoint_owner_id_phone") + if values.get("supplypoint_owner_id_lang", False) and values.get("supplypoint_owner_id_lang", False) != "": + vals["lang"] = self._get_language(values).code + if values.get("supplypoint_owner_id_email", False) and values.get("supplypoint_owner_id_email", False) != "": + vals["email"] = values.get("supplypoint_owner_id_email") + if values.get("supplypoint_owner_id_vat", False) and values.get("supplypoint_owner_id_vat", False) != "": + vals["vat"] = values.get("supplypoint_owner_id_vat") + if values.get("supplypoint_street", False) and values.get("supplypoint_street", False) != "": + vals["street"] = values.get("supplypoint_street") + if values.get("supplypoint_city", False) and values.get("supplypoint_city", False) != "": + vals["city"] = values.get("supplypoint_city") + if values.get("supplypoint_zip", False) and values.get("supplypoint_zip", False) != "": + vals["zip"] = values.get("supplypoint_zip") + if project.conf_vulnerability_situation: - vals["vulnerability_situation"] = values.get( - "supplypoint_owner_id_vulnerability_situation", None - ) + if values.get("supplypoint_owner_id_vulnerability_situation", False) and values.get("supplypoint_owner_id_vulnerability_situation", False) != "": + vals["vulnerability_situation"] = values.get( + "supplypoint_owner_id_vulnerability_situation", None + ) exists.sudo().write(vals) return exists @@ -523,7 +537,8 @@ class CreateInscription(models.AbstractModel): "zip": values["supplypoint_zip"], } if project.conf_vulnerability_situation: - vals["vulnerability_situation"] = values.get( - "supplypoint_owner_id_vulnerability_situation", None - ) + if values.get("supplypoint_owner_id_vulnerability_situation", False) and values.get("supplypoint_owner_id_vulnerability_situation", False) != "": + vals["vulnerability_situation"] = values.get( + "supplypoint_owner_id_vulnerability_situation", None + ) return self.env["res.partner"].sudo().create(vals) diff --git a/energy_selfconsumption/models/supply_point.py b/energy_selfconsumption/models/supply_point.py index e690a7322..8c8a45f1c 100644 --- a/energy_selfconsumption/models/supply_point.py +++ b/energy_selfconsumption/models/supply_point.py @@ -96,7 +96,7 @@ class SupplyPoint(models.Model): def _compute_supply_point_name(self): for record in self: if record.partner_id and record.street: - record.name = f"{record.partner_id.name} - {record.street}" + record.name = f"{record.street}" else: record.name = _("New Supply Point") -- GitLab