2016-01-20 29 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

相关问题