我创建了一个带有计划操作的方法。
对象:'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 :(得分: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
在产品中的产品代码中:不是必需的。您可以直接发送ids的产品列表来浏览方法
答案 1 :(得分: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