Passa al contenuto
Odoo Menu
  • Accedi
  • Provalo gratis
  • App
    Finanze
    • Contabilità
    • Fatturazione
    • Note spese
    • Fogli di calcolo (BI)
    • Documenti
    • Firma
    Vendite
    • CRM
    • Vendite
    • Punto vendita Negozio
    • Punto vendita Ristorante
    • Abbonamenti
    • Noleggi
    Siti web
    • Configuratore sito web
    • E-commerce
    • Blog
    • Forum
    • Live chat
    • E-learning
    Supply chain
    • Magazzino
    • Produzione
    • PLM
    • Acquisti
    • Manutenzione
    • Qualità
    Risorse umane
    • Dipendenti
    • Assunzioni
    • Ferie
    • Valutazioni
    • Referral dipendenti
    • Parco veicoli
    Marketing
    • Social marketing
    • E-mail marketing
    • SMS marketing
    • Eventi
    • Marketing automation
    • Sondaggi
    Servizi
    • Progetti
    • Fogli ore
    • Assistenza sul campo
    • Helpdesk
    • Pianificazione
    • Appuntamenti
    Produttività
    • Comunicazioni
    • Intelligenza artificiale
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    App di terze parti Odoo Studio Piattaforma cloud Odoo
  • Settori
    Retail
    • Libreria
    • Negozio di abbigliamento
    • Negozio di arredamento
    • Alimentari
    • Ferramenta
    • Negozio di giocattoli
    Cibo e ospitalità
    • Bar e pub
    • Ristorante
    • Fast food
    • Pensione
    • Grossista di bevande
    • Hotel
    Agenzia immobiliare
    • Agenzia immobiliare
    • Studio di architettura
    • Edilizia
    • Gestione immobiliare
    • Impresa di giardinaggio
    • Associazione di proprietari immobiliari
    Consulenza
    • Società di contabilità
    • Partner Odoo
    • Agenzia di marketing
    • Studio legale
    • Selezione del personale
    • Audit e certificazione
    Produzione
    • Tessile
    • Metallo
    • Arredamenti
    • Alimentare
    • Birrificio
    • Ditta di regalistica aziendale
    Benessere e sport
    • Club sportivo
    • Negozio di ottica
    • Centro fitness
    • Centro benessere
    • Farmacia
    • Parrucchiere
    Commercio
    • Tuttofare
    • Hardware e assistenza IT
    • Ditta di installazione di pannelli solari
    • Calzolaio
    • Servizi di pulizia
    • Servizi di climatizzazione
    Altro
    • Organizzazione non profit
    • Ente per la tutela ambientale
    • Agenzia di cartellonistica pubblicitaria
    • Studio fotografico
    • Punto noleggio di biciclette
    • Rivenditore di software
    Carica tutti i settori
  • Community
    Apprendimento
    • Tutorial
    • Documentazione
    • Certificazioni 
    • Formazione
    • Blog
    • Podcast
    Potenzia la tua formazione
    • Programma educativo
    • Scale Up! Business Game
    • Visita Odoo
    Ottieni il software
    • Scarica
    • Versioni a confronto
    • Note di versione
    Collabora
    • Github
    • Forum
    • Eventi
    • Traduzioni
    • Diventa nostro partner
    • Servizi per partner
    • Registra la tua società di contabilità
    Ottieni servizi
    • Trova un partner
    • Trova un contabile
    • Incontra un esperto
    • Servizi di implementazione
    • Testimonianze dei clienti
    • Supporto
    • Aggiornamenti
    GitHub Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Richiedi una demo
  • Prezzi
  • Aiuto
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
È necessario essere registrati per interagire con la community.
Tutti gli articoli Persone Badge
Etichette (Mostra tutto)
odoo accounting v14 pos v15
Sul forum
Assistenza

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

Iscriviti

Ricevi una notifica quando c'è un'attività per questo post

La domanda è stata contrassegnata
automatic_emailmailtemplatesendmail
2 Risposte
10611 Visualizzazioni
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
Abbandona
Sehrish

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

Avatar
faOtools
Risposta migliore

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
Abbandona
nasim
Autore

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)
Risposta migliore

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
Abbandona
nasim
Autore

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

Ti stai godendo la conversazione? Non leggere soltanto, partecipa anche tu!

Crea un account oggi per scoprire funzionalità esclusive ed entrare a far parte della nostra fantastica community!

Registrati
Post correlati Risposte Visualizzazioni Attività
Send Email from Template When convert_opportunity sends duplicate mails
mailtemplate sendmail
Avatar
0
mag 16
4011
Automatisation of mails to customers
automatic_email
Avatar
Avatar
Avatar
3
set 25
2722
How to send mail automatically while saving the record Risolto
automatic_email
Avatar
Avatar
Avatar
Avatar
Avatar
5
feb 25
9422
Automatic Email only if some fields are filled
automatic_email
Avatar
Avatar
1
lug 21
3610
Override mail template in Odoo 9
mailtemplate
Avatar
Avatar
Avatar
Avatar
5
nov 19
11616
Community
  • Tutorial
  • Documentazione
  • Forum
Open source
  • Scarica
  • Github
  • Runbot
  • Traduzioni
Servizi
  • Hosting Odoo.sh
  • Supporto
  • Aggiornamenti
  • Sviluppi personalizzati
  • Formazione
  • Trova un contabile
  • Trova un partner
  • Diventa nostro partner
Chi siamo
  • La nostra azienda
  • Branding
  • Contattaci
  • Lavora con noi
  • Eventi
  • Podcast
  • Blog
  • Clienti
  • Note legali • Privacy
  • Sicurezza
الْعَرَبيّة 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 è un gestionale di applicazioni aziendali open source pensato per coprire tutte le esigenze della tua azienda: CRM, Vendite, E-commerce, Magazzino, Produzione, Fatturazione elettronica, Project Management e molto altro.

Il punto di forza di Odoo è quello di offrire un ecosistema unico di app facili da usare, intuitive e completamente integrate tra loro.

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