Bỏ qua để đến Nội dung
Menu
Câu hỏi này đã bị gắn cờ
4 Trả lời
6935 Lượt xem

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]


Ảnh đại diện
Huỷ bỏ
Câu trả lời hay nhất

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


Ảnh đại diện
Huỷ bỏ
Tác giả

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 ?

Tác giả

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

Tác giả

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

Tác giả

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)

Tác giả

Now asking for vals. vals not defined.

Tác giả

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 ?

Tác giả

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.

Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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

Tác giả Câu trả lời hay nhất

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

Ảnh đại diện
Huỷ bỏ

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


Câu trả lời hay nhất

Can someone give me a working example of  the modul ?

Ảnh đại diện
Huỷ bỏ
Tác giả

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

Bài viết liên quan Trả lời Lượt xem Hoạt động
0
thg 5 15
3953
0
thg 7 25
252
0
thg 4 24
1796
4
thg 11 23
5841
0
thg 10 23
1635