gpt4 book ai didi

python - 在odoo开发中,我每次创建数据的时候,都会出现这样的xml编码错误

转载 作者:数据小太阳 更新时间:2023-10-29 02:38:19 24 4
gpt4 key购买 nike

我已经创建了model对象和对应的xml,但是在odoo首页点击Create按钮添加数据对象时,出现如下错误:

ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

系统规范:

  • Ubuntu16.04。 2
  • Odoo 版本为 10.0
  • python解释器是2.7
  • lxml版本为3.5.0
  • pycharm版本为2018
  • Chrome 版本为 50.0.2661.102(64 位)

sudo locale时,出现这些
LANG=zh_CN.UTF-8
LANGUAGE=zh_CN:en_US:en
LC_CTYPE="zh_CN.UTF-8"
LC_NUMERIC=zh_CN.UTF-8
LC_TIME=zh_CN.UTF-8
LC_COLLATE="zh_CN.UTF-8"
LC_MONETARY=zh_CN.UTF-8
LC_MESSAGES="zh_CN.UTF-8"
LC_PAPER=zh_CN.UTF-8
LC_NAME=zh_CN.UTF-8
LC_ADDRESS=zh_CN.UTF-8
LC_TELEPHONE=zh_CN.UTF-8
LC_MEASUREMENT=zh_CN.UTF-8
LC_IDENTIFICATION=zh_CN.UTF-8
LC_ALL=

代码:

追随者.py

# -*- coding: utf-8 -*-
from odoo import models, api, fields
class follower(models.Model):
_inherit = 'res.partner'
bug_ids = fields.Many2many('bm.bug',string='bug')

错误.py

# -*- coding: utf-8 -*-
from odoo import models,api,fields
class bug(models.Model):
_name = 'bm.bug'
_description = 'bug'
name = fields.Char(u'bug简述',required=True)
detail = fields.Text(size=150)
is_closed = fields.Boolean(u'是否关闭')
close_reason = fields.Selection([('changed',u'已修改'),('cannot',u'无法修改'),('delay',u'推迟')],string='关闭理由')
user_id = fields.Many2one('res.users',string=u'负责人')
follower_id = fields.Many2many('res.partner',string=u'关注者')
@api.multi
def do_close(self):
for item in self:
item.is_closed = True
return True

bug_adv.py

# -*- coding: utf-8 -*-
from odoo import api,fields,models
class bugAdvanced(models.Model):
_inherit = 'bm.bug'
need_time = fields.Integer(string='所需时间(小时)')
name = fields.Char(help='简要描述发现的bug')
stage_id = fields.Many2one('bm.bug.stage', string='阶段')
tag_ids = fields.Many2many('bm.bug.tag',string='标示')

bug_stage.py

# -*- coding: utf-8 -*-
from odoo import models,fields,api
class bugStage(models.Model):
_name = 'bm.bug.stage'
_description = 'bug阶段'
_order = 'sequence,name'
name = fields.Char('名称')
desc_detail = fields.Text('描述')
status = fields.Selection([('waiting','未开始'),('doing','进行中'),('closed','关闭'),('rework','重测未通过')],'状态')
document = fields.Html('文档')
sequence = fields.Integer('Sequence')
percent_pro = fields.Float('进度',(3,2))
deadline = fields.Date('最晚解决日期')
create_on = fields.Datetime('创建时间',default=lambda self:fields.Datetime.now())
delay = fields.Boolean('是否延误')
image = fields.Binary('图片')

错误标签.py

# -*- coding: utf-8 -*-
from odoo import fields,models,api
class bugTag(models.Model):
_name = 'bm.bug.tag'
_description = 'bug标示'
name = fields.Char('名称')
bug_ids = fields.Many2many('bm.bug',string='bug')

bugs.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="bug-manage_list">
<field name="name">bug列表</field>
<field name="model">bm.bug</field>
<field name="arch" type="xml">
<tree>
<field name="name"/>
<field name="is_closed"/>
<field name="user_id"/>
</tree>
</field>
</record>

<record model="ir.ui.view" id="bug-manage_form">
<field name="name">bug列表</field>
<field name="model">bm.bug</field>
<field name="arch" type="xml">
<form>
<header>
<button name="do_close" type="object" string="关闭bug"/>
</header>
<sheet>
<group name="group_top" col="2">
<group name="goup_left">
<field name="name"/>
<field name="user_id"/>
<field name="is_closed"/>
</group>
<group name="group_right">
<field name="close_reason"/>
<field name="follower_id"/>
</group>
</group>
<notebook>
<page string="详细内容">
<field name="detail"/>
</page>
</notebook>
</sheet>
</form>
</field>
</record>

<record model="ir.ui.view" id="bug-manage_search">
<field name="name">bug搜索</field>
<field name="model">bm.bug</field>
<field name="arch" type="xml">
<search>
<field name="name"/>
<field name="is_closed"/>
<field name="user_id"/>
</search>
</field>
</record>

<record model="ir.actions.act_window" id="bug-manage_action_window">
<field name="name">bug-manage window</field>
<field name="res_model">bm.bug</field>
<field name="view_mode">tree,form</field>
</record>>

<menuitem name="bug管理系统" id="menu_root"/>
<menuitem name="bug管 理" id="menu_1" parent="bug-manage.menu_root"/>
<menuitem name="bug列表" id="menu_1_list" parent="bug-manage.menu_1" action="bug-manage.bug-manage_action_window"/>
</data>>
</odoo>

追随者.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="bug-manage_follower_form">
<field name="name">关注者</field>
<field name="model">res.partner</field>
base.view_partner_form-->
<field name="inherit_id" ref="base.view_partner_form"/>
<field name="arch" type="xml">
<field name="mobile" position="after">
<field name="bug_ids"/>
</field>
</field>
</record>

<record model="ir.actions.act_window" id="bug-manage_follower_action_window">
<field name="name">follower window</field>
<field name="res_model">res.partner</field>
<field name="view_mode">form</field>
</record>

<menuitem name="关注者管理" id="menu_2" parent="bug-manage.menu_root"/>
<menuitem name="关注者" id="menu_2_form" parent="bug-manage.menu_2" action="bug-manage.bug-manage_follower_action_window"/>
</data>
</odoo>

bugs_adv.xml

<?xml version="1.0" encoding="utf-8"?>
<odoo>
<data>
<record model="ir.ui.view" id="bug-manage_form2">
<field name="name">bug表单2</field>
<field name="model">bm.bug</field>
<field name="inherit_id" ref="bug-manage.bug-manage_form"/>
<field name="arch" type="xml">
<xpath expr="//field[@name='follower_id']" position="after">
<field name="stage_id"/>
<field name="tag_ids"/>
</xpath>
</field>
</record>
</data>
</odoo>

错误

Traceback (most recent call last):
File "/home/python/Desktop/odoo10/server/odoo/http.py", line 638, in _handle_exception
return super(JsonRequest, self)._handle_exception(exception)
File "/home/python/Desktop/odoo10/server/odoo/http.py", line 675, in dispatch
result = self._call_function(**self.params)
File "/home/python/Desktop/odoo10/server/odoo/http.py", line 331, in _call_function
return checked_call(self.db, *args, **kwargs)
File "/home/python/Desktop/odoo10/server/odoo/service/model.py", line 119, in wrapper
return f(dbname, *args, **kwargs)
File "/home/python/Desktop/odoo10/server/odoo/http.py", line 324, in checked_call
result = self.endpoint(*a, **kw)
File "/home/python/Desktop/odoo10/server/odoo/http.py", line 933, in __call__
return self.method(*args, **kw)
File "/home/python/Desktop/odoo10/server/odoo/http.py", line 504, in response_wrap
response = f(*args, **kw)
File "/home/python/Desktop/odoo10/server/odoo/addons/web/controllers/main.py", line 872, in call_kw
return self._call_kw(model, method, args, kwargs)
File "/home/python/Desktop/odoo10/server/odoo/addons/web/controllers/main.py", line 864, in _call_kw
return call_kw(request.env[model], method, args, kwargs)
File "/home/python/Desktop/odoo10/server/odoo/api.py", line 685, in call_kw
return call_kw_model(method, model, args, kwargs)
File "/home/python/Desktop/odoo10/server/odoo/api.py", line 670, in call_kw_model
result = method(recs, *args, **kwargs)
File "/home/python/Desktop/odoo10/server/odoo/models.py", line 1328, in load_views
for [v_id, v_type] in views
File "/home/python/Desktop/odoo10/server/odoo/models.py", line 1328, in <dictcomp>
for [v_id, v_type] in views
File "/home/python/Desktop/odoo10/server/odoo/models.py", line 1399, in fields_view_get
arch_etree = getattr(self, '_get_default_%s_view' % view_type)()
File "/home/python/Desktop/odoo10/server/odoo/models.py", line 1230, in _get_default_tree_view
return E.tree(element, string=self._description)
File "/home/python/.virtualenvs/rhc_odoo_v10.0/local/lib/python2.7/site-packages/lxml/builder.py", line 218, in __call__
get(dict)(elem, attrib)
File "/home/python/.virtualenvs/rhc_odoo_v10.0/local/lib/python2.7/site-packages/lxml/builder.py", line 203, in add_dict
attrib[k] = v
File "src/lxml/lxml.etree.pyx", line 2402, in lxml.etree._Attrib.__setitem__ (src/lxml/lxml.etree.c:72066)
File "src/lxml/apihelpers.pxi", line 570, in lxml.etree._setAttributeValue (src/lxml/lxml.etree.c:23009)
File "src/lxml/apihelpers.pxi", line 1439, in lxml.etree._utf8 (src/lxml/lxml.etree.c:32441)
ValueError: All strings must be XML compatible: Unicode or ASCII, no NULL bytes or control characters

最佳答案

通过使用 u'your_label':

 help=u'简要描述发现的bug'

_description = u'bug阶段'

string=u'所需时间(小时)'

fields.Selection([('waiting',u'未开始'),('doing',u'进行中')....

我也在用阿拉伯语编码,我总是使用 Unicode 作为我的标签以避免这个问题。

关于python - 在odoo开发中,我每次创建数据的时候,都会出现这样的xml编码错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57780801/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com