Skip to Content
Menu
You need to be registered to interact with the community.
This question has been flagged
4 Odgovori
6930 Prikazi

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]


Avatar
Opusti
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


Avatar
Opusti
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 ?

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 :)

Avtor

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

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

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).

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)

Avtor

Now asking for vals. vals not defined.

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 ?

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.

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).

Avatar
Opusti

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

Avtor Best Answer

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

Avatar
Opusti

Can you show me your example mate?


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

Can you show me your example mate?

--
wizardz


Best Answer

Can someone give me a working example of  the modul ?

Avatar
Opusti
Avtor

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

Related Posts Odgovori Prikazi Aktivnost
0
maj 15
3950
0
jul. 25
249
0
apr. 24
1795
4
nov. 23
5840
0
okt. 23
1632