Odoo11通过exe安装包的方式安装到Win7上之后,接连出现几个问题。导入翻译的时候报错:write() argument must be str, not bytes
查看日志如下:
2018-07-29 14:32:32,919 12068 INFO postgres werkzeug: 127.0.0.1 - - [29/Jul/2018 14:32:32] "GET /web/webclient/locale/zh_TW HTTP/1.1" 500 -
2018-07-29 14:32:32,929 12068 ERROR postgres werkzeug: Error on request:
Traceback (most recent call last):
这个问题还是因为字符编码引起的。
解决办法:
\server\odoo\addons\base\module\wizard\base_import_language.py,代码查看如下:
class BaseLanguageImport(models.TransientModel):
_name = "base.language.import"
_description = "Language Import"
name = fields.Char('Language Name', required=True)
code = fields.Char('ISO Code', size=5, required=True,
help="ISO Language and Country code, e.g. en_US")
data = fields.Binary('File', required=True)
filename = fields.Char('File Name', required=True)
overwrite = fields.Boolean('Overwrite Existing Terms',
help="If you enable this option, existing translations (including custom ones) "
"will be overwritten and replaced by those in this file")
@api.multi
def import_lang(self):
this = self[0]
this = this.with_context(overwrite=this.overwrite)
with TemporaryFile('wb+') as buf:
try:
buf.write(base64.decodestring(this.data))
# now we determine the file format
buf.seek(0)
fileformat = os.path.splitext(this.filename)[-1][1:].lower()
tools.trans_load_data(this._cr, buf, fileformat, this.code,
lang_name=this.name, context=this._context)
except Exception as e:
_logger.exception('File unsuccessfully imported, due to format mismatch.')
raise UserError(_('File not imported due to format mismatch or a malformed file. (Valid formats are .csv, .po, .pot)\n\nTechnical Details:\n%s') % tools.ustr(e))
return True