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

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

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

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

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

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



  • 公司采购需要把一个数据导出到一张表里, 但是这些数据来自不同的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!



  • 标签英文逗号分隔..

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


  • 管理员

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


Log in to reply