跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • 默认(Flatly)
  • 不使用皮肤
折叠

Odoo 中文社区

  1. 主页
  2. 版块
  3. Odoo 开发与实施交流
  4. 想实现一个根据产品作为BOM的原料而生成的所有产品列表的查询

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

已定时 已固定 已锁定 已移动 Odoo 开发与实施交流
11 帖子 6 发布者 15.5k 浏览
  • 从旧到新
  • 从新到旧
  • 最多赞同
登录后回复
此主题已被删除。只有拥有主题管理权限的用户可以查看。
  • D 离线
    D 离线
    derek.li
    写于 最后由 编辑
    #1

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

    1 条回复 最后回复
    0
    • D 离线
      D 离线
      derek.li
      写于 最后由 编辑
      #2

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

      1 条回复 最后回复
      0
      • mrshellyM 离线
        mrshellyM 离线
        mrshelly
        写于 最后由 编辑
        #3

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

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

        1 条回复 最后回复
        0
        • digitalsatoriD 离线
          digitalsatoriD 离线
          digitalsatori 管理员
          写于 最后由 编辑
          #4

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

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

          【上海先安科技】(tony AT openerp.cn)

          1 条回复 最后回复
          0
          • digitalsatoriD 离线
            digitalsatoriD 离线
            digitalsatori 管理员
            写于 最后由 编辑
            #5

            人来疯,再来一个解法,直接覆写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>
            ```

            【上海先安科技】(tony AT openerp.cn)

            1 条回复 最后回复
            0
            • mrshellyM 离线
              mrshellyM 离线
              mrshelly
              写于 最后由 编辑
              #6

              Niubility

              1 条回复 最后回复
              0
              • wjfonhandW 离线
                wjfonhandW 离线
                wjfonhand
                写于 最后由 编辑
                #7

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

                GoodERP -- Odoo China fork

                1 条回复 最后回复
                0
                • mrshellyM 离线
                  mrshellyM 离线
                  mrshelly
                  写于 最后由 编辑
                  #8

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

                  Niubility!

                  1 条回复 最后回复
                  0
                  • X 离线
                    X 离线
                    xiaobaixy
                    写于 最后由 编辑
                    #9

                    [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 条回复 最后回复
                    0
                    • M 离线
                      M 离线
                      mf1389004071
                      写于 最后由 编辑
                      #10

                      mark

                      1 条回复 最后回复
                      0

                      • 登录

                      • 没有帐号? 注册

                      • 登录或注册以进行搜索。
                      • 第一个帖子
                        最后一个帖子
                      0
                      • 版块
                      • 标签
                      • 热门
                      • 用户
                      • 群组