跳转至内容
  • 版块
  • 标签
  • 热门
  • 用户
  • 群组
皮肤
  • 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 中文社区

S

sage

@sage
关于
帖子
4
主题
3
群组
0
粉丝
0
关注
0

帖子

最新 最佳 有争议的

  • OpenERP在product中增加外部网络链接图片
    S sage

    最近的一个项目要求在Product_Template中增加类似与HTML中<img src=”" />的形式的图片,效果如图:
    [img [检测到链接无效,已移除] /img]

    product_img_extra.py

    <br />from osv import osv, fields<br />import urllib2<br />import base64<br />class product_template_img(osv.osv):<br />&nbsp; &nbsp; _name = &#039;product.template&#039;<br />&nbsp; &nbsp; _inherit = &#039;product.template&#039;<br />&nbsp; &nbsp; _description = &#039;Product Extra Image&#039;<br /><br />&nbsp; &nbsp; def _get_image(self, cursor, user, ids, name, arg, context=None):<br />&nbsp; &nbsp; &nbsp; &nbsp; image = {}<br />&nbsp; &nbsp; &nbsp; &nbsp; opener = urllib2.build_opener()<br />&nbsp; &nbsp; &nbsp; &nbsp; res = self.read(cursor, user, ids, &#91;&#039;image_link&#039;])<br />&nbsp; &nbsp; &nbsp; &nbsp; image_link = res[0]&#91;&#039;image_link&#039;]<br />&nbsp; &nbsp; &nbsp; &nbsp; if image_link:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; pic = base64.encodestring(opener.open(image_link).read())<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for id in ids:<br />&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; image[id] = pic<br />&nbsp; &nbsp; &nbsp; &nbsp; return image<br /><br />&nbsp; &nbsp; _columns = {<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;image_link&#039; : fields.char(&#039;Image Link&#039;, size=180),<br />&nbsp; &nbsp; &nbsp; &nbsp; &#039;image&#039; : fields.function(_get_image, method=True, string=&#039;Product Image&#039;, type=&#039;binary&#039;, store=False), <br />&nbsp; &nbsp; }<br /><br />product_template_img()<br />
    

     

    product_img_extra_view.xml

    <br />&lt;?xml version=&quot;1.0&quot; encoding=&quot;utf-8&quot;?&gt;<br />&lt;openerp&gt;<br />	&lt;data&gt;<br />		&lt;record id=&quot;product_img_view&quot; model=&quot;ir.ui.view&quot;&gt;<br />			&lt;field name=&quot;name&quot;&gt;product.template.product.form&lt;/field&gt;<br />			&lt;field name=&quot;model&quot;&gt;product.template&lt;/field&gt;<br />			&lt;field name=&quot;type&quot;&gt;form&lt;/field&gt;<br />			&lt;field name=&quot;inherit_id&quot; ref=&quot;product.product_template_form_view&quot; /&gt;<br />			&lt;field name=&quot;arch&quot; type=&quot;xml&quot;&gt;<br />				&lt;field name=&quot;name&quot; position=&quot;before&quot;&gt;<br />					&lt;field name=&quot;image&quot; widget=&quot;image&quot; nolabel=&quot;1&quot; img_width=&quot;168&quot; img_height=&quot;168&quot; colspan=&quot;4&quot;/&gt;<br />					&lt;field name=&quot;image_link&quot; colspan=&quot;4&quot;/&gt;<br />				&lt;/field&gt;<br />			&lt;/field&gt;<br />		&lt;/record&gt;<br />	&lt;/data&gt;<br />&lt;/openerp&gt;<br /><br />
    



    由于OpenERP的基本开发概念的其中一点是读取数据库动态生成界面.这时我就想到了使用fields.function来在界面生成时做一些特别的处理.

    product_img_extra.py中的_columns将对productTemplate增加image_link和image两个column.其中image_link用于保存图片链接的column,当界面生成时通过链接读取图片.image为显示图片的column,但由于store已设置为False所以不会直接保存到数据库中,而只会在界面生成时运行.

    因为需要读取外部链接,所以需要用到Python自带的urllib2模块,值得注意的是opener.open(image_link).read()获取回来的虽然已经是二进制数据,但仍需要使用base64.encodestring对其进行转码才可以被所识别.

    转载自:http://blog.sajolab.com/?p=52


  • 关于fields.function显示网络图片的问题
    S sage

    问题已解决
    使用basse64转换编码. ;D ;D
    image[id] = base64.encodestring(opener.open('http://www.sajolab.com/sajolab.jpg').read())


  • 关于fields.function显示网络图片的问题
    S sage

    我的目标是希望通过fields.function来获取外部网站图片显示到OE上,在开发过程中有以下问题:

    1. 我已经使用urllib2获取到了网络的图片opener.open('http://www.sajolab.com/sajolab.jpg'),然后使用read()将图片转换为Binary类型,但是在添加Module时却报 in ustr raise UnicodeError('unable de to convert %r' % (orig,))错误,相信应该是转码问题,请问各位大神,我在使用fields.function转码应该如何处理才可以正确显示??

    附上Python代码:
    from osv import osv, fields
    import urllib2
    import netsvc
    class product_product(osv.osv):
        _name = 'product.product'
        _inherit = 'product.product'
        _description = 'Product'

        def _get_image(self, cursor, user, ids, name, arg, context=None):
            image = {}
            logger = netsvc.Logger()
            opener = urllib2.build_opener()
            for id in ids:
                logger.notifyChannel('addon:' + self._name, netsvc.LOG_INFO, 'id:%s' % (id))
                image[id] = opener.open('http://www.sajolab.com/sajolab.jpg').read()
            logger.notifyChannel('addon:' + self._name, netsvc.LOG_INFO, 'image:%s' % (image))
            return image

        _columns = { 'image' : fields.function(_get_image, method=True, string='Product Image', type='binary', store=True), }

    product_product()


  • Open ERP 5.0.16 Windows 7源码运行
    S sage

    近日开始真正地接触Open ERP(下简称OE)的模块开发. 一开始在朋友的推荐下装了一个AllInOne版的OE. AllInOne版的OE适合直接使用者,但对于开发者来说需要Debug时就十分麻烦,也不方法对OE源码的理解.

    所以这两天还是下了一个源码版的来安装,由于发现网络上对于windows下的源码运行资料并不是很完整,也比较旧,所以自己写了这篇文章来总结一下.

    首先需要对些概念明确一下:

    1. 所谓源码安装指的是Server端的源码运行,其它的Web端, Client端一般都还会用安装版;

    2. 源码运行不一定需要在Eclipse下运行,也可以在CMD下运行,但如果在Eclipse下运行可以Debug.

    接下来就是源码运行过程:

    1. 整体环境配置, 其中包括:Python + Server(可以不装,但建议装上) + GTKclient + WebClient + PostgreSQL. 当然这里可以直接用Python + AllInOne, 也可以一个一个安装, 但版本需要注意, 如果分开装以下是连接:
    <br / http://www.python.org/ftp/python/2.5/python-2.5.msi br /><br / http://www.openerp.com/downloads/contact?param=stable/win32/openerp-server-setup-5.0.16.exe br /><br / http://www.openerp.com/downloads/contact?param=stable/win32/openerp-client-setup-5.0.16.exe br /><br / http://www.openerp.com/downloads/contact?param=stable/win32/openerp-web-setup-5.0.16.exe br /><br / http://www.enterprisedb.com/products-services-training/pgdownload#windows br />
    2. Eclipse环境配置, 首先至Eclipse官方下载Eclipse,理论上来说版本应该没有什么区别, 我使用的是Eclipse3.6版.

    3. 安装Eclipse的Python插件,依次点击Help –> Software Update, 增加pydev插件,地址是 http://pydev.org/updates/ br />[img [检测到链接无效,已移除] /img]
    点击Software Update进行安装

    [img [检测到链接无效,已移除] /img]
    安装Python插件

    [img [检测到链接无效,已移除] /img]
    选择之前所安装的Python目录

    4. 下载好OE的Server源码, 解压缩, 例如我解压后的路径为F:\Projects\workspace_Python\openerp-server-5.0.15, 然后在将先前安装好的OE Server中Copy一份openerp-server.conf并修改相应的路径, 新建一个PyDev Project路径指向该文件夹

    [img [检测到链接无效,已移除] /img]
    注意Python版本以及路径

    [img [检测到链接无效,已移除] /img]
    导入源码后的目录

    5. 运行bin/openerp-server.py
    [img [检测到链接无效,已移除] /img]

    6. 第一次运行时一般都会出现如下错误”ImportError: No module named lxml”之类的错误,需要安装相关的文件.根我的经验一般都缺少的文件包括:lxml, egenix-mx-base, psycopg, PyChart, pytz, ReportLab

    [img [检测到链接无效,已移除] /img]
    这一类错误其实是Python缺少相关的包所至

    [img [检测到链接无效,已移除] /img]
    所缺少的安装文件

    7. 当所有文件都安装好后就可以再次启动OE Server了, 值得注意的是如果有安装OE Server的在启动源码Server前需要先停掉安装版的OE Server.

    至此整个安装过程结束.

    转载自http://blog.sajolab.com/?p=8

  • 登录

  • 没有帐号? 注册

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