Ir al contenido
Odoo Menú
  • Iniciar sesión
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • PdV para tiendas
    • PdV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en vivo
    • eLearning
    Cadena de suministro
    • Inventario
    • Manufactura
    • PLM
    • Compras
    • Mantenimiento
    • Calidad
    Recursos humanos
    • Empleados
    • Reclutamiento
    • Vacaciones
    • Evaluaciones
    • Referencias
    • Flotilla
    Marketing
    • Redes sociales
    • Marketing por correo
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyectos
    • Registro de horas
    • Servicio externo
    • Soporte al cliente
    • Planeación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Artículos
    • WhatsApp
    Aplicaciones externas Studio de Odoo Plataforma de Odoo en la nube
  • Industrias
    Venta minorista
    • Librería
    • Tienda de ropa
    • Mueblería
    • Tienda de abarrotes
    • Ferretería
    • Juguetería
    Alimentos y hospitalidad
    • Bar y pub
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidora de bebidas
    • Hotel
    Bienes inmuebles
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión de bienes inmuebles
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Firma contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Manufactura
    • Textil
    • Metal
    • Muebles
    • Comida
    • Cervecería
    • Regalos corporativos
    Salud y ejercicio
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Trades
    • Personal de mantenimiento
    • Hardware y soporte de TI
    • Sistemas de energía solar
    • Zapateros y fabricantes de calzado
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin fines de lucro
    • Agencia para la protección del medio ambiente
    • Alquiler de anuncios publicitarios
    • Fotografía
    • Alquiler de bicicletas
    • Distribuidor de software
    Descubre todas las industrias
  • Odoo Community
    Aprende
    • Tutoriales
    • Documentación
    • Certificaciones
    • Capacitación
    • Blog
    • Podcast
    Fortalece la educación
    • Programa educativo
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtén el software
    • Descargar
    • Compara ediciones
    • Versiones
    Colabora
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Conviértete en partner
    • Servicios para partners
    • Registra tu firma contable
    Obtén servicios
    • Encuentra un partner
    • Encuentra un contador
    • Contacta a un consultor
    • Servicios de implementación
    • Referencias de clientes
    • Soporte
    • Actualizaciones
    GitHub YouTube Twitter LinkedIn Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicita una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyectos
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Class self is always empty while running schedule action but implemented button with same method always works

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
buttonclasspython3scheduledactionv15
1 Responder
3048 Vistas
Avatar
Wasnik Malla

i have written a code to import contacts to third party database and implemented shceduled action. Created new class, wrote a method to sync such that initial sync would import all contacts data and subsequent sync only syncs data in a way if write date is greater than last scheduled action date.

i have implemented a button as well becaus while running schedule action, self is always empty but running button it works, i have applied sql contraints as well. still scheduled action would not work as intended because it is not using existing recordsets and is always empty.

Any help.

/class my_class(models.Model):
_name = 'model.name'
# _description = ''

last_cron_update = fields.Datetime(string='Sync Time')
phone_id = fields.Integer(string='Unique Phonebook ID', required=True )
company_id = fields.Many2one('res.company', string='Company', required=True, readonly=True,
default=lambda self: self\.env\.company\)

\ \ \ \ \ _sql_constraints\ =\ \[\
\ \ \ \ \ \ \ \ \('phone_id_company_uniq',\ 'unique\ \(phone_id\ ,company_id\)',\ 'The\ phone\ id\ must\ be\ unique\ for\ a\ company!'\)\
\ \ \ \ \]


/@api\.model
\ \ \ \ def\ sync_phone_book\(self\):

\ \ \ \ \ \ \ \ print\("\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+\+",\ self\)

\ \ \ \ \ \ \ \ url_id\ =\ '\.\.\.\.\.\.\.'
\ \ \ \ \ \ \ \ headers\ =\ \{'\.\.\.\.\.\.'\}

\ \ \ \ \ \ \ \ date\ =\ self\.last_cron_update
\ \ \ \ \ \ \ \ now\ =\ datetime\.datetime\.now\(\)

\ \ \ \ \ \ \ \ \#\ if\ not\ date:
\ \ \ \ \ \ \ \ \#\ \ \ \ \ partner_lines\ =\ self\.env\['res\.partner'\]\.search\(\[\('write_date',\ '\ \ \ \ \ \ \ \ \#\ else:
\ \ \ \ \ \ \ \ \#\ \ \ \ \ partner_lines\ =\ self\.env\['res\.partner'\]\.search\(\[\('write_date',\ '>',\ date\)\]\)



\ \ \ \ \ \ \ \ if\ self\.last_cron_update:
\ \ \ \ \ \ \ \ \ \ \ \ partner_lines\ =\ self\.env\['res\.partner'\]\.search\(\[\('write_date',\ '>',\ date\)\]\)
\ \ \ \ \ \ \ \ else:
\ \ \ \ \ \ \ \ \ \ \ \ partner_lines\ =\ self\.env\['res\.partner'\]\.search\(\[\('write_date',\ '
\ \ \ \ \ \ \ \ for\ line\ in\ partner_lines:
\ \ \ \ \ \ \ \ \ \ \ \
\ \ \ \ \ \ \ \ \ \ \ \ updates\ =\ requests\.post\(url_id,\ headers=headers,\ data=\{'name':line\.name,\ 'office':line\.phone,\ 'mobile':line\.mobile\}\)

\ \ \ \ \ \ \ \ \ \ \ \ print\(updates\.status_code\)
\ \ \ \ \ \ \ \ \ \ \ \ print\(updates\.text\)
\ \ \ \ \ \ \ \ \ \ \ \ print\("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"\)

\ \ \ \ \ \ \ \ \#\ last_cron_update\ =\ fields\.Date\.context_today\(self,\ timestamp=None\)

\ \ \ \ \ \ \ \ self\.last_cron_update\ =\ \ fields\.Datetime\.now\(\)

\ \ \ \ \ \ \ \ \#\ self\.last_cron_update\ =\ self\.write\(\{'last_cron_update':\ fields\.Datetime\.now\(\)\}\)
\ \ \ \
\ \ \ \ \ \ \ \ \#\ if\ not\ date:
\ \ \ \ \ \ \ \ \#\ \ \ \ \ self\.create\(\{'last_cron_update':\ fields\.Datetime\.now\(\)\}\)
\ \ \ \ \ \ \ \ \#\ else:
\ \ \ \ \ \ \ \ \#\ \ \ \ \ self\.write\(\{'last_cron_update':\ fields.Datetime.now()})

print("==================================================================================")
print(self.last_cron_update)

0
Avatar
Descartar
Avatar
Marcelo Pereira
Mejor respuesta

Hello!

If you want to use that method with a cron, you must use a search to get the records.
When the conjob run odoo does't know the records that you want to run it on
it works on your button because you are running the method directly in that record

1
Avatar
Descartar
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Registrarse
Publicaciones relacionadas Respuestas Vistas Actividad
How can I insert a list of values as the title of an excel sheet? Resuelto
python3 v15
Avatar
1
dic 22
3644
Python3: How to get the article information of a fabrication order Resuelto
python3 v15
Avatar
Avatar
2
nov 22
3192
How to reset a existing cookie in odoo using python
python3 v15
Avatar
Avatar
1
mar 22
4268
How to transfer data in invoice to register payment in odo v15 ?
python3 v15
Avatar
Avatar
2
mar 22
4016
Odoo 15 Navbar Customization
python3 v15 UI
Avatar
0
ene 24
2084
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento en Odoo.sh
  • Soporte
  • Actualizaciones del software
  • Desarrollos personalizados
  • Educación
  • Encuentra un contador
  • Encuentra un partner
  • Conviértete en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contáctanos
  • Empleos
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y estar totalmente integrado.

Sitio web hecho con

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now