Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • e-learning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Conocimientos
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Alimentación y hostelería
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Casa de huéspedes
    • Distribuidor de bebidas
    • Hotel
    Inmueble
    • Agencia inmobiliaria
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consultoría
    • Empresa contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Oficios
    • Handyman
    • Hardware y asistencia informática
    • Sistemas de energía solar
    • Zapatero
    • Servicios de limpieza
    • Servicios de calefacción, ventilación y aire acondicionado
    Otros
    • Organización sin ánimo de lucro
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Explorar todos los sectores
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Servicios para partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar 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
  • Proyecto
  • 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
3045 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.

Inscribirse
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
3642
Python3: How to get the article information of a fabrication order Resuelto
python3 v15
Avatar
Avatar
2
nov 22
3191
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
4015
Odoo 15 Navbar Customization
python3 v15 UI
Avatar
0
ene 24
2083
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información 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 totalmente integrado.

Website made with

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