コンテンツへスキップ
メニュー
この質問にフラグが付けられました
4 返信
6929 ビュー

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]


アバター
破棄
最善の回答

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


アバター
破棄
著作者

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 ?

著作者

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

著作者

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

著作者

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)

著作者

Now asking for vals. vals not defined.

著作者

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 ?

著作者

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.

最善の回答

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

アバター
破棄

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

著作者 最善の回答

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

アバター
破棄

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


最善の回答

Can someone give me a working example of  the modul ?

アバター
破棄
著作者

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

関連投稿 返信 ビュー 活動
0
5月 15
3949
0
7月 25
249
0
4月 24
1794
4
11月 23
5840
0
10月 23
1632