Odoo中文社区可以通过以下三个域名访问:shine-it.net , odoocn.org,odoo.net.cn

原论坛用户的基本信息和发帖这里都予以保留,请注意:原论坛用户无需重新注册新用户,但是您的密码需要重置

开发人员可以登录gitter讨论组: http://gitter.im/odoo-china/Talk, 需要github账号

如果您登录系统碰到问题,请在微信公众号留言:

想实现一个根据产品作为BOM的原料而生成的所有产品列表的查询



  • 需求:<br />在产品tree列表中添加一个按钮,选中一个点击该按钮,弹出新窗口,显示以选中的产品作为BOM中原料的产品列表。例如,产品A作为产品B的BOM中的原料,在产品列表中选中A,点击按钮,就列出所有以A作为原料的产品列表,最好还是用产品tree列表显示。看大家有什么思路?



  • 我打算实现在一个产品的form页面点击一个按钮,执行一个action,调出产品tree_view,显示用该产品作为Bom原料的所有产品的列表。<br />我的思路是,新建一个model,继承product.product,添加一个函数,负责查询当前产品id在mrp_bom里作为原料的所有产品的ids,继承product_tree_view来显示这些产品。但是怎样显示,大家能否提供思路<br />



  • 使用 Wizard 做了一个 demo 你下载去参考看看.<br /><br />在产品页右边有个 "Relation Product"  wizard , 点击后就可以看到使用这个产品的相关产品


  • 管理员

    mrshelly的wizard解法很有启发,感谢啊。我用function field的fnct_search实现了相同的功能。参见附件<br /><br />想把mrshelly的wizard转成osv_memory的,想不出解法,哪位兄弟能提供思路,先谢了。


  • 管理员

    人来疯,再来一个解法,直接覆写search方法:<br />

    <br />from osv import osv, fields<br /><br />class product_product(osv.osv):<br /><br />&nbsp; &nbsp; _inherit = &#039;product.product&#039;<br /><br />&nbsp; &nbsp; def search(self, cr, uid, args=None, offset=0, limit=None, order=None,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context=None, count=False):<br />&nbsp; &nbsp; &nbsp; &nbsp; if context is None:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context = {}<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; if context.get(&#039;related_product&#039;) and context.get(&#039;active_ids&#039;):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bom_obj = self.pool.get(&#039;mrp.bom&#039;)<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; product_bom = bom_obj.search(cr,uid, [(&#039;product_id&#039;, &#039;in&#039;, context&#91;&#039;active_ids&#039;])])<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; parent_bom = [bom.bom_id.id for bom in<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; bom_obj.browse(cr,uid, product_bom) if bom.bom_id.id]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; rel_ids = [bom.product_id.id for bom in bom_obj.browse(cr, uid, parent_bom)]<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; args.append((&#039;id&#039;, &#039;in&#039;, rel_ids))<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return super(product_product, self).search(cr,uid,args,offset,limit,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order,context=context, count=count)<br /><br />&nbsp; &nbsp; &nbsp; &nbsp; return super(product_product, self).search(cr,uid,args,offset,limit,<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; order,context=context, count=count)<br />product_product()
    

    <br />

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;openerp&gt;<br />&nbsp; &nbsp; &lt;data&gt;<br />&nbsp; &nbsp; &nbsp; &nbsp; &lt;act_window name=&quot;Related Products&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; context=&quot;{&#039;related_product&#039;:1}&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res_model=&quot;product.product&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; src_model=&quot;product.product&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; view_mode=&quot;tree,form&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; key2=&quot;client_action_multi&quot;<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; id=&quot;action_related_products2&quot;/&gt;<br />&nbsp; &nbsp; &nbsp;  &lt;/data&gt;<br />&lt;/openerp&gt;<br />
    


  • Niubility



  • 写代码没注释,看不懂。痛扁这个唐僧



  • 看来使用  context 可以玩很多定制 检索的 查询显示...  8错, 8错....<br /><br />Niubility!



  • [quote author=digitalsatori link=topic=2059.msg6401#msg6401 date=1276075829]<br />mrshelly的wizard解法很有启发,感谢啊。我用function field的fnct_search实现了相同的功能。参见附件<br /><br />想把mrshelly的wizard转成osv_memory的,想不出解法,哪位兄弟能提供思路,先谢了。<br />[/quote]<br />这个代码挺好的,谁能够详细解释下么,<br />特别是

    context&#91;&#039;active_ids&#039;]
    

    这个怎么使用的问题<br />不胜感激啊,新手需要指点<br /><br />mrshelly的指点:tree view 中, 选中记录的 id 值会保存到 context['active_ids'] 中。



  • mark