Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

If statement triggering action - send mail

Naroči se

Get notified when there's activity on this post

This question has been flagged
codemessage_postodoo8.0
4 Odgovori
7573 Prikazi
Avatar
Dr Obx

Guys, how to do it:

#Read quantity from table, if qty_available <50 send message

(example)

[code]

 def _get_current_stock(self, cr, uid, ids, field_name, arg, context=None):

res = []

tot_qty = 0

product_id = 0

for obj in self.browse(cr, uid, ids, context=context):

cr.execute(""" select sum(qty) from stock_quant where product_id = %s and location_id != 7;""" %(obj.product_id.id))

tot_qty = cr.fetchall()

if tot_qty<50: #here message sending procedure, how to  send message ?

   

print '==========================================='

print '|| Product QTY ', res

print '==========================================='

return res

[/code]


0
Avatar
Opusti
Avatar
Tarek Mohamed Ibrahim
Best Answer

First, you have to define the outgoing mail server in Settings->General settings, you can use for example your gmail account.

You have to test it and get an 'ok' message , if there is any error, it will show you a message what needs to be changed

I used the following code to send emails under a certain condition

    def mailing(self, cr, uid, ids,vals,context=None):
domain=[('name','=','MY_TEMPLATE')] # here is my email template which contains the message
templates = self.pool.get('email.template').search(cr,uid,domain)
if not templates:
return
template = self.pool.get('email.template').browse(cr,uid,templates[0])
if template.email_to:                             #The 'To' email is defined in the template
self.pool.get('email.template').send_mail(cr, uid, template.id, ids[0], True, context=context)

I applied this code and sent emails successfully


1
Avatar
Opusti
Dr Obx
Avtor

Oh great Tarek, thank you, I'll try. However I would like to use a special template or define it inside the method. What do you think ?

Dr Obx
Avtor

Also i would like to add some data from my module ... so either template must be generated by module or template will be able to use data from module. Don't know yet which way to go :)

Dr Obx
Avtor

But first I have to find out how to use this definition :) How to connect it to if statement :)

Tarek Mohamed Ibrahim

to add data to your template you have to define variables in the template based on 'object' variable, check the following example : Dear ${object.responsible.name}, The document ${object.name} status has been changed to ${object.state}, pls check and take the appropriate action

Dr Obx
Avtor

Got it ;) Because i'm quiet new in this, still looking how to trigger it, how to call the function which generate the message (def mailing).

Tarek Mohamed Ibrahim

Pls note that this function is not standard, I just created it to collect this block of code in one place, you can think your own ideas also. to use it you can do something like the following: if some condition : self.mailing(cr, uid, ids, vals, context)

Dr Obx
Avtor

Now asking for vals. vals not defined.

Dr Obx
Avtor

As a testing stuff I created an empty form which is displayed in console once the statement is true. What about template ? Have you created a new one or used an existing one ? And what about vals ?

Dr Obx
Avtor

Tarek, by any chance, can you tell me how can i using this method send more than just short message which contain only one item (). I would like to create a list of products and put into the message then send.

Avatar
Duane Ellis
Best Answer

Finished ;) Since I'm still learning the ropes, I need to figure out how to activate it and invoke the function that creates the message (def mailing).

0
Avatar
Opusti
Duane Ellis

Thank you for sharing such an informative article. https://slopegame.net

Avatar
Dr Obx
Avtor Best Answer

Awesome, already got it, working fine. Now i need to create a template with appropriate fields :)

0
Avatar
Opusti
wizardz

Can you show me your example mate?

OdooBot
I just did :) check https://www.odoo.com/forum/help-1/question/how-to-make-a-modul-with-normal-email-function-96489


On 27 January 2016 at 07:49, wizardz <stee.diez@gmx.ch> wrote:

Can you show me your example mate?

--
wizardz


Avatar
wizardz
Best Answer

Can someone give me a working example of  the modul ?

0
Avatar
Opusti
Dr Obx
Avtor

Already gave you an example of the function and how to apply. What else do you need ?

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

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

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Automatically selected "source location" for selected product in MOVE ?
code modification odoo8.0
Avatar
0
maj 15
4464
18.3-saas: calling message_post on sale.order no longer sends an email
message_post
Avatar
0
jul. 25
1005
how to implement joint piece in odoo 8 in one view
odoo8.0
Avatar
0
apr. 24
2598
what is the reason behind extra move? in stock
odoo8.0
Avatar
Avatar
Avatar
Avatar
4
nov. 23
6765
How to solve fields.function issue in odoo 8
odoo8.0
Avatar
0
okt. 23
2617
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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