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
    • 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
    • Inteligencia artificial
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Sectores
    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 pub
    • 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
    • Asesoría contable
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textil
    • Metal
    • Muebles
    • Alimentos
    • Cervecería
    • Regalos corporativos
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Especialistas en bienestar
    • Farmacia
    • Peluquería
    Oficios
    • Servicios de mantenimiento
    • Hardware y soporte técnico
    • 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 vallas publicitarias
    • 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 asesoría 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
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Sobre este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Sobre este foro
Ayuda

how send automatic email when a form's state is change?

Suscribirse

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

Esta pregunta ha sido marcada
automatic_emailmailtemplatesendmail
2 Respuestas
10623 Vistas
Avatar
nasim

hi

I want know, how send automatic email when a form's state is change?

I search and one page find that someone had given such a solution:

---------------------------------------------

@api.onchange('state')
@api.one
def email_onchange_state(self):
if self.state == 'done':
    tmplt_id = self.env['mail.template'].search([("name", "=", "my_temp_onchange_state_to_done")])  # (I create "my_temp_onchange_state_to_done" template email)
    if tmplt_id:
        self.env['mail.template'].browse(tmplt_id.id).send_mail(self.id, force_send=True)
--------------------------------------------

but when I test , it does not work.( without error)

do you have a solution?


0
Avatar
Descartar
Sehrish

Check how to send email on some event: https://goo.gl/z16PBZ

Avatar
faOtools
Mejor respuesta

A few hints:

1. Do not use 'onchange' for that purpose, since even not saved update will lead to an email of being sent. Instead use inverse.

2. Since you are working with some object (e.g a sale order or an opportunity) it is better to use message_post of that model without trying to use mail.template.

So, you should have something like:

@api.multi
def _inverse_state(self):
"""
For sure you can change body or subject, and generate those based on a template
"""
for obj in self:
obj.message_post(body="State is changed", subject="State is changed", subtype="mail.mt_comment")

state = fields.Selection(inverse=_inverse_state) # field type might be Many2one in case of certain models

Another alternative is to rely upon tracking. Look for examples in the project module - https://github.com/odoo/odoo/blob/12.0/addons/project/models/project.py

0
Avatar
Descartar
nasim
Autor

Hi

Thanks for your help

I wanted to use "mai". so my function became: (and works fine :) )

---------------------------------

@api.multi

def _inverse_state(self):

if self.state == 'done':

tmplt_id = self.env['mail.template'].search([("name", "=", "my_temp_onchange_state_to_done")])

if tmplt_id:

self.env['mail.template'].browse(tmplt_id.id).send_mail(self.id, force_send=True)

--------------------

state = fields.Selection(inverse='_inverse_state')

------------------------------------------------------------------------------------------

Thanks

Avatar
Niyas Raphy (Walnut Software Solutions)
Mejor respuesta

Hi,

 Can you please put a print statement or logger message for the tmplt_id and see whether it receives the email template, might be the email is not send or created as the execution of the code didn't enter inside the if statement.

Refer : Finding and sending e-mail templates in Odoo

Also you can check whether the onchange function is getting executed, you can test the same by putting a print statement it. If the state of the record is changed in a button click, you can override that button action and add this codes to send email in it.


For sending the email in the during the state change, you can use the automated action to send the email. For that install the module named base_automation in the database and navigate to Settings -> Technical -> Automation -> Automated Action and create a new record here by specifying the model for which the action has to be triggered, and in the field Trigger condition specify the condition and in the Action To Do select the Send Email option.


Thanks

0
Avatar
Descartar
nasim
Autor

thanks for your help

but I did not want to use 'Aoutomated Action' (because I want know it is posibble write this without automated action?)

so I used the above method.( def _inverse_state(self) )

so thanks

¿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
Send Email from Template When convert_opportunity sends duplicate mails
mailtemplate sendmail
Avatar
0
may 16
4015
Automatisation of mails to customers
automatic_email
Avatar
Avatar
Avatar
3
sept 25
2722
How to send mail automatically while saving the record Resuelto
automatic_email
Avatar
Avatar
Avatar
Avatar
Avatar
5
feb 25
9422
Automatic Email only if some fields are filled
automatic_email
Avatar
Avatar
1
jul 21
3610
Override mail template in Odoo 9
mailtemplate
Avatar
Avatar
Avatar
Avatar
5
nov 19
11616
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 Svenska ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones empresariales de código abierto que cubre 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.

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