diff --git a/__init__.py b/__init__.py
index b28efe41..33eefee3 100644
--- a/__init__.py
+++ b/__init__.py
@@ -28,7 +28,7 @@ def pre_init_check(cr):
pre_init_check(cr=None)
-def pre_init_hook(cr, registry):
+def pre_init_hook(cr, registry=None):
env = api.Environment(cr, SUPERUSER_ID, {})
#env['ir.model'].search([('model', '=', 'warning')]).unlink()
diff --git a/__manifest__.py b/__manifest__.py
index 86f9215b..acaba63a 100644
--- a/__manifest__.py
+++ b/__manifest__.py
@@ -9,7 +9,7 @@
{
'name': 'MercadoLibre Publisher / Mercado Libre Odoo Connector',
'summary': 'MercadoLibre Publisher / Mercado Libre Odoo Connector',
- 'version': '17.0.24.8',
+ 'version': '17.0.24.14',
'author': 'Moldeo Interactive',
'website': 'https://www.moldeointeractive.com',
"category": "Sales",
diff --git a/models/category.py b/models/category.py
index b18c2357..8f3da1ff 100644
--- a/models/category.py
+++ b/models/category.py
@@ -208,12 +208,12 @@ class mercadolibre_category(models.Model):
def get_meli( self, meli=None ):
- _logger.info("get_meli")
- _logger.info(self)
- _logger.info(meli)
- _logger.info(str(meli and meli.seller_id))
- _logger.info(str(meli and meli.client_id))
- _logger.info(str(meli and meli.meli_login_id))
+ #_logger.info("get_meli")
+ #_logger.info(self)
+ #_logger.info(meli)
+ #_logger.info(str(meli and meli.seller_id))
+ #_logger.info(str(meli and meli.client_id))
+ #_logger.info(str(meli and meli.meli_login_id))
if meli:
return meli
diff --git a/models/company.py b/models/company.py
index 0d1c128b..792cf251 100644
--- a/models/company.py
+++ b/models/company.py
@@ -306,11 +306,9 @@ def cron_meli_questions(self):
mercadolibre_recursive_import = fields.Boolean( string='Recursive import', help='Import all the category tree from Category Code')
mercadolibre_cron_refresh = fields.Boolean(string='Keep alive',help='Cron Automatic Token Refresh for keeping ML connection alive.')
- mercadolibre_cron_mail = fields.Many2one(
- comodel_name="mail.template",
+ mercadolibre_cron_mail = fields.Many2one("mail.template",
string="Error E-mail Template",
- help="Select the email template that will be sent when "
- "cron refresh fails.")
+ help="Select the email template that will be sent when cron refresh fails.")
mercadolibre_cron_get_orders = fields.Boolean(string="Importar pedidos",help='Cron Get Orders / Pedidos de venta')
mercadolibre_cron_get_orders_shipment = fields.Boolean(string='Importar envíos',help='Cron Get Orders Shipment')
mercadolibre_cron_get_orders_shipment_client = fields.Boolean(string='Importar clientes',help='Cron Get Orders Shipment Client')
@@ -429,6 +427,10 @@ def cron_meli_questions(self):
mercadolibre_banner = fields.Many2one("mercadolibre.banner",string="Plantilla Descriptiva")
+ mercadolibre_contact_partner = fields.Many2one("res.partner",string="Contacto Predeterminado")
+ mercadolibre_shipping_partner = fields.Many2one("res.partner",string="Contacto de Envio Predeterminado")
+ mercadolibre_invoice_partner = fields.Many2one("res.partner",string="Contacto de Facturación Predeterminado")
+
#mercadolibre_use_buyer_name = fields.Boolean(string="Use buyer name",default=True)
#Toma y lista los ids de las publicaciones del sitio de MercadoLibre, filtrados por official_store_id
diff --git a/models/orders.py b/models/orders.py
index 02de1d00..b2e87997 100644
--- a/models/orders.py
+++ b/models/orders.py
@@ -71,14 +71,14 @@ def _meli_status_brief(self):
order.meli_status_detail = order.meli_status_detail
def search_meli_status_brief(self, operator, value):
- _logger.info("search_meli_status_brief")
- _logger.info(operator)
- _logger.info(value)
+ #_logger.info("search_meli_status_brief")
+ #_logger.info(operator)
+ #_logger.info(value)
if operator == 'ilike':
#name = self.env.context.get('name', False)
#if name is not False:
id_list = []
- _logger.info(self.env.context)
+ #_logger.info(self.env.context)
#name = self.env.context.get('name', False)
sale_orders = self.env['sale.order'].search([], limit=10000,order='id desc')
if (value):
@@ -93,7 +93,50 @@ def search_meli_status_brief(self, operator, value):
' with the operator: {}',format(operator)
)
+ def _search_meli_buyer_name( self, operator, value ):
+ #_logger.info("_search_meli_buyer_name")
+ #_logger.info(operator)
+ #_logger.info(value)
+ if operator == 'ilike':
+ #name = self.env.context.get('name', False)
+ #if name is not False:
+ id_list = []
+ #_logger.info(self.env.context)
+ #name = self.env.context.get('name', False)
+ meli_orders = []
+ buyer_ids = []
+ if value:
+ buyers = self.env['mercadolibre.buyers'].search([('name','=ilike','%'+str(value)+'%')], limit=10000,order='name asc')
+ if buyers:
+ for buyer in buyers:
+ buyer_ids.append(buyer.id)
+ if buyer_ids:
+ meli_orders = self.env['mercadolibre.orders'].search([('buyer','in',buyers_ids)], limit=10000 )
+ #sale_orders = self.env['sale.order'].search([], limit=10000,order='id desc')
+ #if (value):
+ #for so in sale_orders:
+ # if (value in so.meli_buyer_name):
+ # id_list.append(so.id)
+ if (meli_orders):
+ for mo in meli_orders:
+ if mo.sale_order and mo.sale_order.id:
+ id_list.append(mo.sale_order.id)
+ return [('id', 'in', id_list)]
+ else:
+ _logger.error(
+ 'The field name is not searchable'
+ ' with the operator: {}',format(operator)
+ )
+
+ def _get_meli_order( self ):
+ for so in self:
+ so.meli_order = so.meli_orders and so.meli_orders[0]
+ so.meli_buyer = so.meli_order and so.meli_order.buyer
+ so.meli_buyer_name = so.meli_buyer and so.meli_buyer.name
+ meli_order = fields.Many2one( 'mercadolibre.orders',string="Meli Orden", compute="_get_meli_order" )
+ meli_buyer = fields.Many2one( "mercadolibre.buyers",string="Meli Comprador", compute="_get_meli_order")
+ meli_buyer_name = fields.Char( string="Meli Comprador Nombre", compute="_get_meli_order", search=_search_meli_buyer_name, store=False, index=True )
meli_status = fields.Selection( [
#Initial state of an order, and it has no payment yet.
@@ -1572,7 +1615,8 @@ def orders_update_order_json( self, data, context=None, config=None, meli=None )
pass;
else:
try:
- partner_invoice_id = respartner_obj.create(( partner_update ))
+ if config.mercadolibre_cron_get_orders_shipment_client:
+ partner_invoice_id = respartner_obj.create(( partner_update ))
if partner_invoice_id:
#partner_update = self.update_partner_billing_info( partner_id=partner_invoice_id, meli_buyer_fields=partner_update )
#partner_invoice_id.write(partner_update)
@@ -1588,7 +1632,8 @@ def orders_update_order_json( self, data, context=None, config=None, meli=None )
#_logger.info( "creating new partner:" + str(meli_buyer_fields) )
try:
meli_buyer_fields.update(billing_partner_update)
- partner_id = respartner_obj.create(( meli_buyer_fields ))
+ if config.mercadolibre_cron_get_orders_shipment_client:
+ partner_id = respartner_obj.create(( meli_buyer_fields ))
partner_invoice_id = partner_id
except Exception as e:
_logger.info("orders_update_order > Error creando Partner:"+str(e))
@@ -1629,7 +1674,8 @@ def orders_update_order_json( self, data, context=None, config=None, meli=None )
#partner_id.write( meli_buyer_fields )
if (partner_id):
- partner_shipping_id = self.env["mercadolibre.shipment"].partner_delivery_id( partner_id=partner_id, Receiver=Receiver)
+ if config.mercadolibre_cron_get_orders_shipment_client:
+ partner_shipping_id = self.env["mercadolibre.shipment"].partner_delivery_id( partner_id=partner_id, Receiver=Receiver)
if (partner_id):
if ("fe_habilitada" in self.env['res.partner']._fields):
@@ -1644,12 +1690,19 @@ def orders_update_order_json( self, data, context=None, config=None, meli=None )
_logger.error("Buyer not fetched!")
if (not partner_id):
- _logger.error("No partner founded or created for ML Order" )
- return {'error': 'No partner founded or created for ML Order' }
+ if config.mercadolibre_cron_get_orders_shipment_client:
+ _logger.error("No partner founded or created for ML Order" )
+ return {'error': 'No partner founded or created for ML Order' }
+
#process base order fields
+ #asignar datos de invoicing predeterminado....(mexico)
+ partner_id = ("mercadolibre_contact_partner" in config._fields and config.mercadolibre_contact_partner) or partner_id
+ partner_invoice_id = ("mercadolibre_invoice_partner" in config._fields and config.mercadolibre_invoice_partner) or partner_invoice_id
+ partner_shipping_id = ("mercadolibre_shipping_partner" in config._fields and config.mercadolibre_shipping_partner) or partner_shipping_id
+
meli_order_fields = self.prepare_sale_order_vals( order_json=order_json, meli=meli, config=config, sale_order=sorder )
meli_order_fields.update({
- 'partner_id': partner_id.id,
+ 'partner_id': (partner_id and partner_id.id),
'partner_invoice_id': (partner_invoice_id and partner_invoice_id.id),
'pricelist_id': plistid.id,
})
diff --git a/models/shipment.py b/models/shipment.py
index 2818b676..952ee784 100644
--- a/models/shipment.py
+++ b/models/shipment.py
@@ -528,12 +528,15 @@ def _update_sale_order_shipping_info( self, order, meli=None, config=None ):
except:
_logger.info("Could not unlink.")
- def partner_delivery_id( self, partner_id=None, Receiver=None ):
+ def partner_delivery_id( self, partner_id=None, Receiver=None, config=None ):
if (not Receiver or not partner_id):
_logger.info("partner_delivery_id > no Partner or no Receiver")
return None
+ if (config and not config.mercadolibre_cron_get_orders_shipment_client):
+ return None
+
orders_obj = self.env['mercadolibre.orders']
partner_shipping_id = None
@@ -969,7 +972,8 @@ def fetch( self, order, meli=None, config=None ):
#_logger.info("ship_json[receiver_address]:"+str(ship_json["receiver_address"]) )
partner_shipping_id = None
if "receiver_address" in ship_json:
- partner_shipping_id = self.partner_delivery_id( partner_id=partner_id, Receiver=ship_json["receiver_address"])
+ if config.mercadolibre_cron_get_orders_shipment_client:
+ partner_shipping_id = self.partner_delivery_id( partner_id=partner_id, Receiver=ship_json["receiver_address"])
if partner_shipping_id:
sorder = sorder_pack
diff --git a/views/company_view.xml b/views/company_view.xml
index 1396adeb..59cba260 100644
--- a/views/company_view.xml
+++ b/views/company_view.xml
@@ -104,6 +104,11 @@
+
+
+
+
+
diff --git a/views/orders_view.xml b/views/orders_view.xml
index 5d48824f..4e3624a0 100644
--- a/views/orders_view.xml
+++ b/views/orders_view.xml
@@ -77,14 +77,17 @@
-
+
+
+
+
@@ -117,7 +120,7 @@
+ invisible="meli_buyer_id == False">