2016-01-20 25 views
0

我創建了一個計劃操作的方法。如何檢查產品是否缺貨? [Odoo]

對象:「product.product」

我想實現的是將通知發送給購買者組如果產品脫銷。 到目前爲止,我有這樣的代碼:

class product_product(osv.osv): 
    _name = 'product.product' 
    _inherit = ['product.product', 'mail.thread', 'ir.needaction_mixin'] 

    def notification(self, cr, uid, context=None): 

    product_uom_obj = self.pool.get('product.uom') 
    partner_obj = self.pool.get('res.partner') 
    user_obj = self.pool.get('res.users') 
    group_obj = self.pool.get('res.groups') 
    partners = [] 
    followers = [] 

    group_users= group_obj.search(cr, uid, ['&', ('category_id.name', '=', 'Purchases'), ('name', '=', 'User')]) 

    for recipient in group_obj.browse(cr, uid, group_users).users: 
     partners.append(recipient.id) 

    for partner in partners: 
     for follower in user_obj.browse(cr, uid, partner).partner_id: 
      followers.append(follower.id) 


    products = self.search(cr, uid, [('type', '=', 'product')]) 


    for product in products: 
     for prod in self.browse(cr, uid, product): 
      #check if the product is out of stock 

所以,我怎麼能檢查,如果該產品缺貨?

回答

0

您可以使用prod.product_tmpl_id.qty_available檢查產品的庫存,但要獲取product.template的qty_available字段,您還必須安裝庫存模塊。所以,在取決於openerp .py也添加股票。

for prod in self.browse(cr, uid, products): 
     #check if the product is out of stock 
     if prod.product_tmpl_id.qty_available<=0: 
      #Send mail using message_post method 

在您的產品產品代碼中:不是必需的。您可以直接發送ID的產品列表進行瀏覽方法

0

發送郵件僅適用於產品的供應商,同時確認銷售訂單是

def action_button_confirm(self, cr, uid, ids, context=None): 
    ret = super(sale_order, self).action_button_confirm(cr, uid, ids, context=context) 
    for order in self.browse(cr, uid, ids, context=context): 
     for line in order.order_line: 
      if line.product_id and line.product_id.product_tmpl_id.qty_available<=0: 
       partnerids = [] 
       for suppinfo in line.product_id.seller_ids: 
        if suppinfo.name.email: 
         partnerids.append(suppinfo.name.id) 
       post_values = { 
        'partner_ids': partnerids, 
        'subject':"Send '%s' Stock of %s Quantity"%(line.product_id.name,line.product_uom_qty), 
        'body': '<div><p>Dear Seller,</p>' 
        '<p>Please send us "%s" Product Stock of %s Quantity as soon as Possible.</p></div>' 
          '<p>Regards,</p>' 
          '<p>%s</p>'%(line.product_id.name,line.product_uom_qty,order.company_id.name), 
         }  
       msg_id = self.message_post(cr, SUPERUSER_ID, [order.id], type='email', subtype=False, context=context, **post_values) 

    return ret 
+0

嗨@Murali爵士克里希納·雷迪,但我需要立即發送通知。我在[link](https://stackoverflow.com/questions/34913571/valueerror-odoo)中更新了我的代碼。我在選擇產品時遇到了新問題,您可以檢查一下嗎?如果有的話,你的答案將是我的另一種選擇。謝謝。 – wannabe

+0

該鏈接已刪除 – Krishh

相關問題