From b1709302b04cd097f5e3f122e3d6bbaf55588d83 Mon Sep 17 00:00:00 2001
From: bakeable <robin@bakeable.nl>
Date: Thu, 30 May 2024 18:14:11 +0200
Subject: [PATCH] Added with fallback to get_formatted_value

---
 akeneo_connector/akeneo_product.py | 14 +++++++-------
 akeneo_connector/akeneo_units.py   |  5 ++++-
 2 files changed, 11 insertions(+), 8 deletions(-)

diff --git a/akeneo_connector/akeneo_product.py b/akeneo_connector/akeneo_product.py
index 5b6000d..ed8d9be 100644
--- a/akeneo_connector/akeneo_product.py
+++ b/akeneo_connector/akeneo_product.py
@@ -120,7 +120,7 @@ def get_values(self, attribute: str) -> list[Value]:
         """
         return self.values.get(attribute, [])
     
-    def get_value(self, attribute: str, locale: str | None = None, scope: str | None = None) -> any:
+    def get_value(self, attribute: str, locale: str | None = None, scope: str | None = None, with_fallback = False) -> any:
         """
         Gets the value for the given attribute.
 
@@ -142,13 +142,13 @@ def get_value(self, attribute: str, locale: str | None = None, scope: str | None
                 return value.get('data')
 
         # Return first value if locale is None and scope is None
-        if locale is None and scope is None:
+        if locale is None and scope is None or with_fallback:
             return self.values[attribute][0].get('data')
-        
+
         # Return None if locale and scope are not found
         return None
     
-    def get_linked_data(self, attribute: str, locale: str | None = None, scope: str | None = None) -> dict | None:
+    def get_linked_data(self, attribute: str, locale: str | None = None, scope: str | None = None, with_fallback = False) -> dict | None:
         """
         Gets the linked data for the given attribute.
 
@@ -170,7 +170,7 @@ def get_linked_data(self, attribute: str, locale: str | None = None, scope: str
                 return value.get('linked_data', None)
 
         # Return first value if locale is None and scope is None
-        if locale is None and scope is None:
+        if locale is None and scope is None or with_fallback:
             return self.values[attribute][0].get('linked_data', None)
         
         # Return None if locale and scope are not found
@@ -189,10 +189,10 @@ def get_formatted_value(self, attribute: str, locale: str | None = None, scope:
             str: The value of the attribute. "N/A" if not found.
         """
         # Get value
-        value = self.get_value(attribute, locale, scope)
+        value = self.get_value(attribute, locale, scope, with_fallback=True)
 
         # Get linked data
-        linked_data = self.get_linked_data(attribute, locale, scope)
+        linked_data = self.get_linked_data(attribute, locale, scope, with_fallback=True)
 
         # Return formatted value
         return format_value(value, locale, linked_data)
diff --git a/akeneo_connector/akeneo_units.py b/akeneo_connector/akeneo_units.py
index 2b2bea1..86bdd2d 100644
--- a/akeneo_connector/akeneo_units.py
+++ b/akeneo_connector/akeneo_units.py
@@ -202,7 +202,10 @@ def format_number(number: int | float, locale_name: str | None = None) -> str:
     
     # Format the number
     if isinstance(number, int):
-        formatted_number = locale.format_string("%d", number, grouping=True)
+        if number > 1000000000: # Prevent barcodes from being formatted wrong
+            formatted_number = str(number)
+        else:
+            formatted_number = locale.format_string("%d", number, grouping=True)
     else:
         formatted_number = locale.format_string("%f", number, grouping=True)