跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 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. [分享] 关于多对象数据导出的实践

[分享] 关于多对象数据导出的实践

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

    公司采购需要把一个数据导出到一张表里, 但是这些数据来自不同的Object,想从最后的质检结果里,导出产品名称,PO号,产品的运输单位,以及其他一些信息。
    经过shelly的指点,
    通过browse 回写,直接用function的方式,把这些数据都抓来!

    &nbsp; &nbsp; def _getsupplier(self,cr,uid,ids,field_name,arg,context={}):<br />&nbsp; &nbsp; &nbsp; &nbsp; res={}<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; for record in self.browse(cr,uid,ids,context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res[record.id]=record.orderline_id.order_id.partner_id.name<br />&nbsp; &nbsp; &nbsp; &nbsp; return res<br />&nbsp; &nbsp; def _getprice(self,cr,uid,ids,field_name,arg,context={}):<br />&nbsp; &nbsp; &nbsp; &nbsp; res={}<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; for record in self.browse(cr,uid,ids,context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res[record.id]=record.orderline_id.product_id.standard_price<br />&nbsp; &nbsp; &nbsp; &nbsp; return res<br />&nbsp; &nbsp; def _getunitqty(self,cr,uid,ids,field_name,arg,context={}):<br />&nbsp; &nbsp; &nbsp; &nbsp; res={}<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; for record in self.browse(cr,uid,ids,context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res[record.id]=record.orderline_id.order_id.carrier_id.weight_unit<br />&nbsp; &nbsp; &nbsp; &nbsp; return res<br />&nbsp; &nbsp; def _getsappo(self,cr,uid,ids,field_name,arg,context={}):<br />&nbsp; &nbsp; &nbsp; &nbsp; res={}<br />&nbsp; &nbsp; &nbsp; &nbsp; <br />&nbsp; &nbsp; &nbsp; &nbsp; for record in self.browse(cr,uid,ids,context):<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; res[record.id]=record.orderline_id.order_id.sap_po<br />&nbsp; &nbsp; &nbsp; &nbsp; return res
    



    添加字段:

    &#039;suppliers&#039;:fields.function(_getsupplier,method=True,type =&#039;char&#039;,string =&#039;suppliers&#039;), <br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;price&#039;:fields.function(_getprice,method=True,type=&#039;float&#039;,string=&#039;Prices&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;unitqty&#039;:fields.function(_getunitqty,method=True,type=&#039;integer&#039;,string=&#039;Uint qty&#039;),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;sappo&#039;:fields.function(_getsappo,method=True,type =&#039;char&#039;,string =&#039;SAP PO&#039;), 
    

    然后到了前台,导出的时候,居然找不到这些字段, 后来在xml文件里把它们都添加上,发现就可以找到相对用的字段了!

     <br /> &lt;field name=&quot;price&quot; string=&quot;price&quot; invisible=&quot;True&quot;/&gt;<br />
    



    因为太多字段来,影响前台显示,而且价格等也不希望被别的组的人看到!
    给加上了 invisible="True",就解决了!

    这里谢谢 shelly!

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

      标签英文逗号分隔..

      赞一个先...
      慢慢地大家的经验就汇成一些解决方案了.

      1 条回复 最后回复
      0
      • JoshuaJ 离线
        JoshuaJ 离线
        Joshua 管理员
        写于 最后由 编辑
        #3

        very nice .使用fields.function 是个办法

        【上海先安科技】(joshua AT openerp.cn),欢迎关注公众号:openerp_cn

        1 条回复 最后回复
        0

        • 登录

        • 没有帐号? 注册

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