为什么还要直接执行 SQL 语句。。知道 ORM 的概念吗?了解一些 ORM 的操作模式(就是面向对象),你的问题也就不是问题了
fxiao
-
Xmlrpc,php 操作 OE 的方法 --- 搜索、读取、创建、更新 -
Openerp 与 httplib2 冲突操作系统:debian 6.0.7
oe:openerp_7.0-20121227-075624-1 到 openerp_8.0dev-20130328-000101-1
用 /etc/init.d/openerp start 启动。进程一闪而过,/var/log/openerp-server.log 没有墨迹。
直接用命令:<br />start-stop-daemon --start --quiet --pidfile /var/run/openerp-server.pid --chuid openerp --make-pidfile --exec /usr/bin/openerp-server -- --config=/etc/openerp/openerp-server.conf<br />
报错:<br />IOError: [Errno 13] Permission denied: '/usr/local/lib/python2.6/dist-packages/httplib2-0.8-py2.6.egg/EGG-INFO/top_level.txt'<br />
解决:easy_install -m httplib2
P.S. 没有进一步追踪了。很奇怪,oe 关 httplib2 鸟事。期望有人有空追踪一下。 -
Xmlrpc,php 操作 OE 的方法 --- 搜索、读取、创建、更新php 操作 OE 的方法
phpxmlrpc 版本:v2.2.2( http://phpxmlrpc.sourceforge.net/ )
openerp 版本:v7.0-20130103-002220-1
LNMP 版本:v0.9
* 搜索
* 读取
* 创建
* 更新。
如果报 "Call to a member function scalarval() on a non-object" 错,请看看是不是 fsockopen 函数被禁用。
* vi /usr/local/php/etc/php.ini
* 搜索 disable_functions, 删除里面的 fsockopen
还有个问题,创建和更新的方法,不能用 $GLOBALS['xmlrpc_internalencoding']='UTF-8'; 必须要用 ISO-8859-1,否则就会报错。
<br /><?php<br />require("./xmlrpc/lib/xmlrpc.inc");<br />// 这里就是解决商品名称中有中文时的乱码问题<br />//$GLOBALS['xmlrpc_internalencoding']='UTF-8'; // 如果从里定义的话,那么 create、write 方法就会出现 500 错误。<br />class XmlrpcOe{<br /> public $user = 'admin';<br /> public $password = 'admin';<br /> public $user_id = -1;<br /> public $dbname = 'test';<br /> public $server_url = 'http://127.0.0.1:8069/xmlrpc/';<br /> public function __construct() {<br /> $this->sock_common();<br /> $this->sock_object();<br /> $this->connect();<br /> }<br /><br /> public function sock_common() {<br /> $this->sock_com = new xmlrpc_client($this->server_url.'common');<br /> }<br /> public function sock_object() {<br /> $this->sock_obj = new xmlrpc_client($this->server_url.'object');<br /> }<br /> /**<br /> * 登录,获取 user_id<br /> */<br /> public function connect() {<br /> /*<br /> if(isset($_COOKIE["user_id"]) == true) {<br /> if($_COOKIE["user_id"]>0) {<br /> return $_COOKIE["user_id"];<br /> }<br /> }<br /> */<br /> $msg = new xmlrpcmsg('login');<br /> $msg->addParam(new xmlrpcval($this->dbname, "string"));<br /> $msg->addParam(new xmlrpcval($this->user, "string"));<br /> $msg->addParam(new xmlrpcval($this->password, "string"));<br /> $resp = $this->sock_com->send($msg);<br /> $val = $resp->value();<br /> $this->user_id = $val->scalarval();<br /> setcookie("user_id",$this->user_id,time()+3600);<br /> }<br /><br /> /**<br /> * 搜索-单条件<br /> * $relation: 搜索的对象,如:product.category<br /> * $attribute: 属性,如:name<br /> * $operator: 条件,如:>、=、!=、like<br /> * $keys: 值,如:p<br /> */<br /> public function search($relation, $attribute, $operator, $keys) {<br /> $GLOBALS['xmlrpc_internalencoding']='UTF-8';<br /> $key = array(new xmlrpcval(array(new xmlrpcval($attribute , "string"),<br /> new xmlrpcval($operator,"string"),<br /> new xmlrpcval($keys,"string")),"array"),);<br /> $msg = new xmlrpcmsg('execute');<br /> $msg->addParam(new xmlrpcval($this->dbname, "string"));<br /> $msg->addParam(new xmlrpcval($this->user_id, "int"));<br /> $msg->addParam(new xmlrpcval($this->password, "string"));<br /> $msg->addParam(new xmlrpcval($relation, "string"));<br /> $msg->addParam(new xmlrpcval("search", "string"));<br /> $msg->addParam(new xmlrpcval($key, "array"));<br /> $resp = $this->sock_obj->send($msg);<br /> $val = $resp->value();<br /> $ids_rpc_array = $val->scalarval();<br /> $ids = array();<br /> foreach($ids_rpc_array as $id_obj) {<br /> $ids[] = $id_obj->me["int"];<br /> }<br /> return $ids_rpc_array;<br /> //return $ids;<br /> }<br /> /**<br /> * 读数据,通过 id 读取相关数据<br /> * $relation: 数据对象,如:product.product<br /> * $ids: id 的数组,如:array(new xmlrpcval(4, "int"));<br /> * $field_array: 字段数组<br /> */<br /> public function read($relation, $ids, $field_array) {<br /> $GLOBALS['xmlrpc_internalencoding']='UTF-8';<br /> <br /> $msg = new xmlrpcmsg('execute');<br /> $msg->addParam(new xmlrpcval($this->dbname, "string"));<br /> $msg->addParam(new xmlrpcval($this->user_id, "int"));<br /> $msg->addParam(new xmlrpcval($this->password, "string"));<br /> $msg->addParam(new xmlrpcval($relation, "string"));<br /> $msg->addParam(new xmlrpcval("read", "string"));<br /> $msg->addParam(new xmlrpcval($ids, "array"));<br /> $msg->addParam(new xmlrpcval($field_array, "array"));<br /> $resp = $this->sock_obj->send($msg);<br /> $val = $resp->value();<br /> return $val->scalarval();<br /> }<br /> public function create($relation, $partner_data) {<br /> $GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';<br /> $msg = new xmlrpcmsg('execute');<br /> $msg->addParam(new xmlrpcval($this->dbname, "string"));<br /> $msg->addParam(new xmlrpcval($this->user_id, "int"));<br /> $msg->addParam(new xmlrpcval($this->password, "string"));<br /> $msg->addParam(new xmlrpcval($relation, "string"));<br /> $msg->addParam(new xmlrpcval("create", "string"));<br /> $msg->addParam(new xmlrpcval($partner_data, "struct"));<br /> $resp = $this->sock_obj->send($msg);<br /> if ($resp->faultCode())<br /> echo 'Error: '.$resp->faultString();<br /> else<br /> echo 'Partner '.$resp->value()->scalarval().' created !';<br /> }<br /> public function write($relation, $data, $ids) {<br /> $GLOBALS['xmlrpc_internalencoding']='ISO-8859-1';<br /> $msg = new xmlrpcmsg('execute');<br /> $msg->addParam(new xmlrpcval($this->dbname, "string"));<br /> $msg->addParam(new xmlrpcval($this->user_id, "int"));<br /> $msg->addParam(new xmlrpcval($this->password, "string"));<br /> $msg->addParam(new xmlrpcval($relation, "string"));<br /> $msg->addParam(new xmlrpcval("write", "string"));<br /> $msg->addParam(new xmlrpcval($ids, "array"));<br /> $msg->addParam(new xmlrpcval($data, "struct"));<br /> $resp = $this->sock_obj->send($msg);<br /> $val = $resp->value();<br /> return $val->scalarval();<br /> }<br />}<br />$xmlrpc_oe = new XmlrpcOe();<br /># 搜索<br />echo "search:<br />";<br />$ids = $xmlrpc_oe->search("product.product", "id", ">", "1");<br />print_r($ids);<br />echo "<br /><br />";<br /><br />$id_array = array();<br />foreach($ids as $id_obj) {<br /> $id_array[] = $id_obj->me["int"];<br />}<br />print_r($id_array);<br />echo "<br /><br />---------------------------------------------------------<br />";<br /> <br /># 读数据<br />echo "read:<br />";<br />$field_array = array(<br /> new xmlrpcval("id", "int"),<br /> new xmlrpcval("name", "string"),<br /> new xmlrpcval("list_price", "string"),<br /> );<br />$ret_array = $xmlrpc_oe->read("product.product", $ids, $field_array);<br />print_r($ret_array);<br />echo "<br /><br />";<br />$out_array = array();<br />foreach($ret_array as $k => $v) {<br /> $tmp_id = $v->me['struct']['id']->me["int"];<br /> $tmp_name = $v->me['struct']['name']->me["string"];<br /> $tmp_price = $v->me['struct']['list_price']->me["double"];<br /> $out_array[] = array(<br /> "id" => $tmp_id,<br /> "name" => $tmp_name,<br /> "list_price" => $tmp_price,<br /> );<br />}<br />print_r($out_array);<br />echo "<br /><br />---------------------------------------------------------<br />";<br /><br /># 添加<br />echo "create:<br />";<br />$partner_data = array(<br /> "name" => new xmlrpcval("魅族 MX2 32GB", "string"),<br /> "list_price" => new xmlrpcval(2999.00, "double"),<br /> );<br />//$xmlrpc_oe->create("product.product", $partner_data);<br />echo "<br /><br />---------------------------------------------------------<br />";<br /><br /># 修改<br />echo "write:<br />";<br />$ids = array(<br /> new xmlrpcval(7, "int"),<br /> );<br />$data = array(<br /> "name" => new xmlrpcval("魅族 MX2 64GB", "string"),<br /> "list_price" => new xmlrpcval(3999.00, "double"),<br /> );<br />$xmlrpc_oe->write("product.product", $data, $ids);<br />$ret_array = $xmlrpc_oe->read("product.product", $ids, $field_array);<br />$out_array = array();<br />foreach($ret_array as $k => $v) {<br /> $tmp_id = $v->me['struct']['id']->me["int"];<br /> $tmp_name = $v->me['struct']['name']->me["string"];<br /> $tmp_price = $v->me['struct']['list_price']->me["double"];<br /> $out_array[] = array(<br /> "id" => $tmp_id,<br /> "name" => $tmp_name,<br /> "list_price" => $tmp_price,<br /> );<br />}<br />print_r($out_array);<br /><br />
参考:
[检测到链接无效,已移除]
http://doc.openerp.com/v6.0/developer/6_22_XML-RPC_web_services/index.html -
Oe6.1.1 安装模块 product_links(6.0版),抛出no attribute 'external_osv' 解决方案[size=18pt]抛出错误[/size]
AttributeError: 'module' object has no attribute 'external_osv'
[size=18pt]原因[/size]
product_links 继承了 base_external_referentials模块的 external_osv类。
base_external_referentials模块6.0版,有一个external_osv类<br />class external_osv(osv.osv):<br /> pass #FIXME remove! only here for compatibility purpose for now<br />
但安装是6.1版,已经去掉了这个类
[size=18pt]解决方案[/size]
修改product_links.py文件。
原代码(部分)<br />from osv import fields, osv<br />from base_external_referentials import external_osv<br /><br />class product_link(external_osv.external_osv):<br /> _name = 'product.link'<br /> _rec_name = 'linked_product_id'<br />
修改成<br />from osv import fields, osv<br />#from base_external_referentials import external_osv<br /><br />#class product_link(external_osv.external_osv):<br />class product_link(osv.osv):<br /> _name = 'product.link'<br /> _rec_name = 'linked_product_id'<br />
-
基于 openerp-6.2dev-20121014-230101 进行翻译修补更新基于 openerp-6.2dev-20121014-230101 已有的翻译基础上,进行修补更新,
每个模块一个文件zh_CN.po文件,附件解压后格式 --- 模块名-zh_CN.po。
先更新:
web
web_graph
明天预算:
l10n_ch
sale -
求:如何在产品列表tree添加图片字段(显示缩略图)在视图product.product.tree上添加
<field name="product_image" widget="image" img_width="300" img_height="300"></field>
显示是图片的大小。
应该如何定义这个字段才可以显示图片和控制这个图片大小?
求教!!谢谢 -
OpenERP基础篇-新手入门-环境搭建- Ubuntu&OpenERPV6基本原因是 web client 没有启动成功。查看 openerp-server.log 找问题
-
FreeBSD安装OpenERP 6.1谢谢!参考一下,看看在LION安装如何,还有CENTOS5.8