From 91c77aba0baad01f6d9072308f382b7ea99ee0f3 Mon Sep 17 00:00:00 2001
From: Daniil Digtyar Vasilieva <daniildigtyar@gmail.com>
Date: Thu, 3 Aug 2023 15:39:07 +0200
Subject: [PATCH] [FIX]energy_selfconsumption: not search if vat is not
 assigned

---
 .../wizards/selfconsumption_import_wizard.py  | 43 ++++++++++---------
 1 file changed, 23 insertions(+), 20 deletions(-)

diff --git a/energy_selfconsumption/wizards/selfconsumption_import_wizard.py b/energy_selfconsumption/wizards/selfconsumption_import_wizard.py
index 8fa77c39f..cf40d3f18 100644
--- a/energy_selfconsumption/wizards/selfconsumption_import_wizard.py
+++ b/energy_selfconsumption/wizards/selfconsumption_import_wizard.py
@@ -173,26 +173,29 @@ class SelfconsumptionImportWizard(models.TransientModel):
         return True, False
 
     def create_supply_point(self, line_dict, partner):
-        owner = self.env["res.partner"].search(
-            [
-                "|",
-                ("vat", "=", line_dict["owner_vat"]),
-                ("vat", "=ilike", line_dict["owner_vat"]),
-            ],
-            limit=1,
-        )
-        if not owner:
-            try:
-                owner = self.env["res.partner"].create(
-                    {
-                        "vat": line_dict["owner_vat"],
-                        "firstname": line_dict["owner_firstname"],
-                        "lastname": line_dict["owner_lastname"],
-                        "company_type": "person",
-                    }
-                )
-            except Exception as e:
-                return False, _("Owner could not be created: {error}").format(error=e)
+        if line_dict["owner_vat"]:
+            owner = self.env["res.partner"].search(
+                [
+                    "|",
+                    ("vat", "=", line_dict["owner_vat"]),
+                    ("vat", "=ilike", line_dict["owner_vat"]),
+                ],
+                limit=1,
+            )
+            if not owner:
+                try:
+                    owner = self.env["res.partner"].create(
+                        {
+                            "vat": line_dict["owner_vat"],
+                            "firstname": line_dict["owner_firstname"],
+                            "lastname": line_dict["owner_lastname"],
+                            "company_type": "person",
+                        }
+                    )
+                except Exception as e:
+                    return False, _("Owner could not be created: {error}").format(error=e)
+        else:
+            owner = partner
         country = self.env["res.country"].search([("code", "=", line_dict["country"])])
         if not country:
             return False, _("Country code was not found: {country}").format(
-- 
GitLab