# Path: models/meli_oerp_config.py
# REDIRECT_URI = ''


import pytz
import odoo.addons.decimal_precision as dp
import requests
import json
import logging
import meli
from odoo import models, api, fields
from odoo.tools.translate import _
    from urllib import urlencode
    from urllib.parse import urlencode
from .meli_oerp_config import REDIRECT_URI
from ..melisdk.meli import Meli
from meli.rest import ApiException
from meli.api_client import ApiClient
from datetime import datetime
                        'job_exception': message,
                        'dbname': self._cr.dbname,
                    }

                    _logger.info(
                        "Sending scheduler error email with context=%s", context)
                    _logger.info("Sending to company:" + str(company.name)+ " mail:" + str(company.email)  )
                    rese = self.env['mail.template'].browse(
                                company.mercadolibre_cron_mail.id
                            ).with_context(context).sudo().send_mail( (company.id), force_send=True)
                    _logger.info("Result sending:" + str(rese) )
                company.write({'mercadolibre_access_token': '', 'mercadolibre_refresh_token': '', 'mercadolibre_code': '', 'mercadolibre_cron_refresh': False } )

        except Exception as e:
            _logger.error(e)

        for comp in company:
            if (last_token!=comp.mercadolibre_access_token):#comp.mercadolibre_state!=api_rest_client.needlogin_state:
                _logger.info("mercadolibre_state : "+str(api_rest_client.needlogin_state))
                comp.mercadolibre_state = api_rest_client.needlogin_state
            #else:
            #    _logger.info("mercadolibre_state already set: "+str(api_rest_client.needlogin_state))

        return api_rest_client

    @api.model
    def get_url_meli_login(self, app_instance):
        if not company:
            company = self.env.user.company_id
        REDIRECT_URI = company.mercadolibre_redirect_uri

# Path: models/meli_oerp_config.py
# REDIRECT_URI = ''


# Path: models/meli_util.py
import pytz
import odoo.addons.decimal_precision as dp
import requests
import json
import logging
import meli
from odoo import models, api, fields
from odoo.tools.translate import _
    from urllib import urlencode
    from urllib.parse import urlencode
from .meli_oerp_config import REDIRECT_URI
from ..melisdk.meli import Meli
from meli.rest import ApiException
from meli.api_client import ApiClient
from datetime import datetime

                        'job_exception': message,
                        'dbname': self._cr.dbname,
                    }

                    _logger.info(
                        "Sending scheduler error email with context=%s", context)
                    _logger.info("Sending to company:" + str(company.name)+ " mail:" + str(company.email)  )
                    rese = self.env['mail.template'].browse(
                                company.mercadolibre_cron_mail.id
                            ).with_context(context).sudo().send_mail( (company.id), force_send=True)
                    _logger.info("Result sending:" + str(rese) )
                company.write({'mercadolibre_access_token': '', 'mercadolibre_refresh_token': '', 'mercadolibre_code': '', 'mercadolibre_cron_refresh': False } )

        except Exception as e:
            _logger.error(e)

        for comp in company:
            if (last_token!=comp.mercadolibre_access_token):#comp.mercadolibre_state!=api_rest_client.needlogin_state:
                _logger.info("mercadolibre_state : "+str(api_rest_client.needlogin_state))
                comp.mercadolibre_state = api_rest_client.needlogin_state
            #else:
            #    _logger.info("mercadolibre_state already set: "+str(api_rest_client.needlogin_state))

        return api_rest_client

    @api.model
    def get_url_meli_login(self, app_instance):
        if not company:
            company = self.env.user.company_id
        REDIRECT_URI = company.mercadolibre_redirect_uri

        url_login_meli = app_instance.auth_url(redirect_URI=REDIRECT_URI)