From 70c7326aca81100cd51e76d528bb7502e1d994ca Mon Sep 17 00:00:00 2001 From: ntsystemwork <40502705+ntsystemwork@users.noreply.github.com> Date: Mon, 6 May 2024 17:32:15 -0300 Subject: [PATCH 1/4] Update product.py arreglo error de variantes --- models/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/product.py b/models/product.py index 46d2886d..5e6d3fa7 100644 --- a/models/product.py +++ b/models/product.py @@ -1634,7 +1634,7 @@ def product_meli_get_product( self, context=None, meli_id=None ): } posting = self.env['mercadolibre.posting'].search([('meli_id','=',rjson['id'])]) - posting_id = posting.id + posting_id = posting[0].id if not posting_id: posting = self.env['mercadolibre.posting'].create((posting_fields)) From 9cfe030090336bde2fc62196606623ecc4e66b9f Mon Sep 17 00:00:00 2001 From: faf1997 Date: Tue, 7 Jan 2025 13:40:54 -0300 Subject: [PATCH 2/4] =?UTF-8?q?[FIX]=20casteo=20de=20string=20a=20float,?= =?UTF-8?q?=20nuevo=20m=C3=A9todo=20def=20string=5Fto=5Ffloat(self,=20numb?= =?UTF-8?q?er=5Fstr)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- models/product.py | 26 +++++++++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/models/product.py b/models/product.py index 27a26683..37714b10 100644 --- a/models/product.py +++ b/models/product.py @@ -649,6 +649,25 @@ def _meli_set_product_price( self, product_template, meli_price, force_variant=F _logger.info("_meli_set_product_price lst_price<1.0: "+str(ml_price_converted)) product_template.write({'lst_price': ml_price_converted}) + + def string_to_float(self, number_str): + """ + Convierte un número en formato string con separadores de miles y coma decimal + (ej. "100.234.999,9") a un float (ej. 100234999.9). + """ + if not isinstance(number_str, str): + raise ValueError("El valor debe ser una cadena (str).") + + # Elimina los separadores de miles (puntos) y reemplaza la coma decimal por un punto + normalized_number = number_str.replace('.', '').replace(',', '.') + + try: + return float(normalized_number) + except ValueError: + raise ValueError(f"No se pudo convertir el valor '{number_str}' a un número flotante.") + + + def set_meli_price( self, meli=None, config=None, plist=None ): company = self.env.user.company_id config = config or company @@ -664,7 +683,8 @@ def set_meli_price( self, meli=None, config=None, plist=None ): # NEW OR NULL # > Set template meli price if ( product_tmpl.meli_price==False - or ( product_tmpl.meli_price and int(float(product_tmpl.meli_price))==0 ) ): + # or ( product_tmpl.meli_price and int(float(product_tmpl.meli_price))==0 ) ): + or ( product_tmpl.meli_price and int(self.string_to_float(product_tmpl.meli_price))==0 ) ): product_tmpl.meli_price = product_tmpl.list_price # UPDATE @@ -684,7 +704,7 @@ def set_meli_price( self, meli=None, config=None, plist=None ): else: #_logger.info( "new_price: " +str(new_price)) if ( product.meli_price_fixed and product.meli_price): - new_price = int(float(product.meli_price)) or int(float(product_tmpl_id.meli_price)) or 0 + new_price = int(self.string_to_float(product.meli_price)) or int(self.string_to_float(product_tmpl_id.meli_price)) or 0 else: if ( product.lst_price ): new_price = product.lst_price @@ -715,7 +735,7 @@ def set_meli_price( self, meli=None, config=None, plist=None ): new_price = str( int( int( math.floor(int(new_price) / 100 ) * 100 + 90 ) ) ) else: new_price = math.ceil(new_price) - new_price = str(int(float(new_price))) + new_price = str(int(self.string_to_float(new_price))) product_tmpl.meli_price = new_price product.meli_price = product_tmpl.meli_price From 2d80ed1bdfa41b2780ea464a01bfc79c974c6f4a Mon Sep 17 00:00:00 2001 From: faf1997 Date: Tue, 7 Jan 2025 16:43:38 -0300 Subject: [PATCH 3/4] [FIX] valor inesperado en set_meli_price --- models/product.py | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/models/product.py b/models/product.py index 37714b10..836fd295 100644 --- a/models/product.py +++ b/models/product.py @@ -655,17 +655,19 @@ def string_to_float(self, number_str): Convierte un número en formato string con separadores de miles y coma decimal (ej. "100.234.999,9") a un float (ej. 100234999.9). """ - if not isinstance(number_str, str): - raise ValueError("El valor debe ser una cadena (str).") + if isinstance(number_str, str): + # raise ValueError("El valor debe ser una cadena (str).") # Elimina los separadores de miles (puntos) y reemplaza la coma decimal por un punto - normalized_number = number_str.replace('.', '').replace(',', '.') - - try: - return float(normalized_number) - except ValueError: - raise ValueError(f"No se pudo convertir el valor '{number_str}' a un número flotante.") - + normalized_number = number_str.replace('.', '').replace(',', '.') + + try: + return float(normalized_number) + except ValueError: + raise ValueError(f"No se pudo convertir el valor '{number_str}' a un número flotante.") + else: + _logger.warning(f'El valor de number_str "{number_str}" no es una cadena (str).') + return float(number_str or 0) def set_meli_price( self, meli=None, config=None, plist=None ): From d0c92342f92db32ad5c68cdcdcaab72b90d5cb79 Mon Sep 17 00:00:00 2001 From: faf1997 Date: Tue, 7 Jan 2025 16:48:54 -0300 Subject: [PATCH 4/4] [FIX] valor inesperado en set_meli_price --- models/product.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/models/product.py b/models/product.py index 836fd295..4c0c9f58 100644 --- a/models/product.py +++ b/models/product.py @@ -667,7 +667,7 @@ def string_to_float(self, number_str): raise ValueError(f"No se pudo convertir el valor '{number_str}' a un número flotante.") else: _logger.warning(f'El valor de number_str "{number_str}" no es una cadena (str).') - return float(number_str or 0) + return float(number_str) def set_meli_price( self, meli=None, config=None, plist=None ):