Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Artificial Intelligence
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Property Management
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

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

Subscriure's

Get notified when there's activity on this post

This question has been flagged
automatic_emailmailtemplatesendmail
2 Respostes
10627 Vistes
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
Best Answer

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)
Best Answer

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

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registrar-se
Related Posts Respostes Vistes Activitat
Send Email from Template When convert_opportunity sends duplicate mails
mailtemplate sendmail
Avatar
0
de maig 16
4015
Automatisation of mails to customers
automatic_email
Avatar
Avatar
Avatar
3
de set. 25
2722
How to send mail automatically while saving the record Solved
automatic_email
Avatar
Avatar
Avatar
Avatar
Avatar
5
de febr. 25
9422
Automatic Email only if some fields are filled
automatic_email
Avatar
Avatar
1
de jul. 21
3610
Override mail template in Odoo 9
mailtemplate
Avatar
Avatar
Avatar
Avatar
5
de nov. 19
11616
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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