Skip to content
Open
7 changes: 7 additions & 0 deletions models/orders.py
Original file line number Diff line number Diff line change
Expand Up @@ -1290,8 +1290,10 @@ def orders_update_order_json( self, data, context=None, config=None, meli=None )
meli_buyer_fields['l10n_latam_identification_type_id'] = (doc_type_id and doc_type_id.id)

if (company.country_id.code == "AR" and 'l10n_ar.afip.responsibility.type' in self.env):

afipid = self.env['l10n_ar.afip.responsibility.type'].search([('code','=',5)]).id
meli_buyer_fields["l10n_ar_afip_responsibility_type_id"] = afipid

if ('TAXPAYER_TYPE_ID' in Buyer['billing_info'] and Buyer['billing_info']['TAXPAYER_TYPE_ID'] and Buyer['billing_info']['TAXPAYER_TYPE_ID']=="IVA Responsable Inscripto"):
afipid = self.env['l10n_ar.afip.responsibility.type'].search([('code','=',1)]).id
meli_buyer_fields["l10n_ar_afip_responsibility_type_id"] = afipid
Expand All @@ -1301,6 +1303,11 @@ def orders_update_order_json( self, data, context=None, config=None, meli=None )
if ('TAXPAYER_TYPE_ID' in Buyer['billing_info'] and Buyer['billing_info']['TAXPAYER_TYPE_ID'] and Buyer['billing_info']['TAXPAYER_TYPE_ID']=="Responsable Monotributo"):
afipid = self.env['l10n_ar.afip.responsibility.type'].search([('code','=',6)]).id
meli_buyer_fields["l10n_ar_afip_responsibility_type_id"] = afipid

if ('TAXPAYER_TYPE_ID' in Buyer['billing_info'] and Buyer['billing_info']['TAXPAYER_TYPE_ID'] and Buyer['billing_info']['TAXPAYER_TYPE_ID']=="Monotributo"):
afipid = self.env['l10n_ar.afip.responsibility.type'].search([('code','=',6)]).id
meli_buyer_fields["l10n_ar_afip_responsibility_type_id"] = afipid


meli_buyer_fields['vat'] = Buyer['billing_info']['doc_number']

Expand Down
30 changes: 26 additions & 4 deletions models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,27 @@ 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 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.")
else:
_logger.warning(f'El valor de number_str "{number_str}" no es una cadena (str).')
return float(number_str)


def set_meli_price( self, meli=None, config=None, plist=None ):
company = self.env.user.company_id
config = config or company
Expand All @@ -664,7 +685,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
Expand All @@ -684,7 +706,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
Expand Down Expand Up @@ -715,7 +737,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
Expand Down Expand Up @@ -1644,7 +1666,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))
Expand Down