Navigation

    Odoo 中文社区

    • Register
    • Login
    • Search
    • Categories
    • Tags
    • Popular
    • Users
    • Groups

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

    由于系统升迁的原因,本论坛部分较早期的内容存在格式和链接损坏失效的问题,并非本论坛系统本身的缺陷,望谅解

    本社区没有维护任何QQ群讨论组,任何与本社区同名的QQ群讨论组的言论与本社区无关!

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

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

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

    Odoo 开发与实施交流
    6
    11
    14713
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      derek.li last edited by

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

      1 Reply Last reply Reply Quote 0
      • D
        derek.li last edited by

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

        1 Reply Last reply Reply Quote 0
        • mrshelly
          mrshelly last edited by

          使用 Wizard 做了一个 demo 你下载去参考看看.

          在产品页右边有个 "Relation Product"  wizard , 点击后就可以看到使用这个产品的相关产品

          1 Reply Last reply Reply Quote 0
          • digitalsatori
            digitalsatori 管理员 last edited by

            mrshelly的wizard解法很有启发,感谢啊。我用function field的fnct_search实现了相同的功能。参见附件

            想把mrshelly的wizard转成osv_memory的,想不出解法,哪位兄弟能提供思路,先谢了。

            1 Reply Last reply Reply Quote 0
            • digitalsatori
              digitalsatori 管理员 last edited by

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

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

              ``` <?xml version="1.0" encoding="utf-8"?>
              <openerp>
                  <data>
                      <act_window name="Related Products"
                                  context="{'related_product':1}"
                                  res_model="product.product"
                                  src_model="product.product"
                                  view_mode="tree,form"
                                  key2="client_action_multi"
                                  id="action_related_products2"/>
                    </data>
              </openerp>
              ```
              1 Reply Last reply Reply Quote 0
              • mrshelly
                mrshelly last edited by

                Niubility

                1 Reply Last reply Reply Quote 0
                • wjfonhand
                  wjfonhand last edited by

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

                  1 Reply Last reply Reply Quote 0
                  • mrshelly
                    mrshelly last edited by

                    看来使用  context 可以玩很多定制 检索的 查询显示...  8错, 8错....

                    Niubility!

                    1 Reply Last reply Reply Quote 0
                    • X
                      xiaobaixy last edited by

                      [quote author=digitalsatori link=topic=2059.msg6401#msg6401 date=1276075829]
                      mrshelly的wizard解法很有启发,感谢啊。我用function field的fnct_search实现了相同的功能。参见附件

                      想把mrshelly的wizard转成osv_memory的,想不出解法,哪位兄弟能提供思路,先谢了。
                      [/quote]
                      这个代码挺好的,谁能够详细解释下么,
                      特别是

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

                      这个怎么使用的问题
                      不胜感激啊,新手需要指点

                      mrshelly的指点:tree view 中, 选中记录的 id 值会保存到 context['active_ids'] 中。

                      1 Reply Last reply Reply Quote 0
                      • M
                        mf1389004071 last edited by

                        mark

                        1 Reply Last reply Reply Quote 0
                        • First post
                          Last post