Xml Odoo,Python:TypeError:info()为关键字参数';标题';
我正在尝试使用这个Odoo插件:Xml Odoo,Python:TypeError:info()为关键字参数';标题';,xml,python-2.7,typeerror,odoo,odoo-8,Xml,Python 2.7,Typeerror,Odoo,Odoo 8,我正在尝试使用这个Odoo插件: WARNING_TYPES = [('warning', 'Warning'), ('info', 'Information'), ('error', 'Error')] class warning_box(models.TransientModel): _name = 'warning_box' _description = 'warning_box' _req_name = 'title' type = fields.Se
WARNING_TYPES = [('warning', 'Warning'), ('info', 'Information'), ('error', 'Error')]
class warning_box(models.TransientModel):
_name = 'warning_box'
_description = 'warning_box'
_req_name = 'title'
type = fields.Selection(WARNING_TYPES, string='Type', readonly=True)
title = fields.Char(string="Title", size=100, readonly=True)
message = fields.Text(string="Message", readonly=True)
@api.multi
def message_action(self):
self.ensure_one
message_type = [t[1]for t in WARNING_TYPES if self.type == t[0]][0]
res = {
'name': '%s: %s' % (_(message_type), _(self.title)),
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env['ir.model.data'].xmlid_to_res_id(
'warning_box.warning_box_form'),
'res_model': 'warning_box',
'domain': [],
'context': self._context,
'type': 'ir.actions.act_window',
'target': 'new',
'res_id': self.id
}
return res
@api.model
def warning(self, title, message):
record = self.create({'title': title, 'message': message, 'type': 'warning'})
return record.message_action()
@api.model
def info(self, title, message):
record = self.create({'title': title, 'message': message, 'type': 'info'})
return record.message_action()
@api.model
def error(self, title, message):
record = self.create({'title': title, 'message': message, 'type': 'error'})
return record.message_action()
显示一些消息
安装页面显示:
用法返回self.pool.get('warning_box').info(cr、uid、title='The
title',message='the message')
由于代码是用V8.0风格编写的,我认为这是错误的。我已经尝试过了,但它给出了关于cr和uid的错误
然后我试着这样做:
self.env['warning_box'].info(self, title='The title', message='the message')
这给了我一个错误:
TypeError:info()为关键字参数“title”获取了多个值
这是Odoo插件的python代码:
WARNING_TYPES = [('warning', 'Warning'), ('info', 'Information'), ('error', 'Error')]
class warning_box(models.TransientModel):
_name = 'warning_box'
_description = 'warning_box'
_req_name = 'title'
type = fields.Selection(WARNING_TYPES, string='Type', readonly=True)
title = fields.Char(string="Title", size=100, readonly=True)
message = fields.Text(string="Message", readonly=True)
@api.multi
def message_action(self):
self.ensure_one
message_type = [t[1]for t in WARNING_TYPES if self.type == t[0]][0]
res = {
'name': '%s: %s' % (_(message_type), _(self.title)),
'view_type': 'form',
'view_mode': 'form',
'view_id': self.env['ir.model.data'].xmlid_to_res_id(
'warning_box.warning_box_form'),
'res_model': 'warning_box',
'domain': [],
'context': self._context,
'type': 'ir.actions.act_window',
'target': 'new',
'res_id': self.id
}
return res
@api.model
def warning(self, title, message):
record = self.create({'title': title, 'message': message, 'type': 'warning'})
return record.message_action()
@api.model
def info(self, title, message):
record = self.create({'title': title, 'message': message, 'type': 'info'})
return record.message_action()
@api.model
def error(self, title, message):
record = self.create({'title': title, 'message': message, 'type': 'error'})
return record.message_action()
我一直在查找错误,发现以下两条信息:
我试着去理解它,并把它运用到我的处境中,但我无法让它发挥作用。。。
谁能告诉我这个代码有什么问题吗
编辑Forvas:
我现在这样调用函数:
return self.env['warning_box'].error(title='The title', message='the message')
上面的代码没有出现任何错误
现在我已经像你说的那样改变了行动。
为此:
form_view_id = self.env.ref(
'your_module_name.your_form_view_xml_id').id
我用过:
form_view_id = self.env.ref(
'warning_box_git.warning_box_form').id
只是想确定一下,您是指模块名还是模型名?
我的模型(类)是warning_box,我的模块名是warning_box_git(模块文件夹的名称)。我做得对吗
无论哪种方式,我都会不断出现以下错误:
AttributeError:“警告框”对象没有属性“错误”
这是我的XML:
<openerp>
<data>
<record id="warning_box_form" model="ir.ui.view">
<field name="name">warning_box.form</field>
<field name="model">warning_box</field>
<field eval="20" name="priority"/>
<field name="arch" type="xml">
<form string="Warning">
<field name="message" nolabel="1"/>
<footer>
<button string="OK" class="oe_highlight" special="cancel"/>
</footer>
</form>
</field>
</record>
<record model="ir.actions.act_window" id="action_warning_box">
<field name="name">Warning Box</field>
<field name="res_model">warning_box</field>
<field name="view_type">form</field>
<field name="view_mode">form</field>
<field name="view_id" ref="warning_box_form" />
<field name="target">new</field>
</record>
</data>
</openerp>
警告表格
警告箱
警告箱
警告箱
形式
形式
新的
你知道如何解决这个错误吗
为Forvas编辑2:
我犯了一个愚蠢的错误。这个错误现在已经消失了。
但是,它仍然没有显示任何弹出窗口?您不能将
self
作为参数传递
self.env['warning_box'].info(title='The title', message='the message')
当您从self
调用模型时,“传递”它
编辑
请尝试下一个代码:
@api.multi
def message_action(self):
self.ensure_one()
message_type = [t[1]for t in WARNING_TYPES if self.type == t[0]][0]
form_view_id = self.env.ref(
'your_module_name.your_form_view_xml_id').id
return {
'name': '%s: %s' % (_(message_type), _(self.title)),
'view_type': 'form',
'view_mode': 'form',
'views': [(form_view_id, 'form'), ],
'res_model': 'warning_box',
'context': self._context,
'type': 'ir.actions.act_window',
'target': 'new',
'flags': {'action_buttons': True},
}
但是仍然没有弹出窗口。你也知道为什么会这样吗?我已经编辑了我的答案@RobbeM,看看当我想打开一个弹出窗口时我会做什么(显然用你的数据替换你的模块名、表单视图、xml id)。谢谢你的努力。但是我现在有一个新的错误。。。我已经用细节编辑了我的作品。我想问题一定出在装饰师身上。从具有
@api.model
的其他方法调用message\u action
,尝试删除该方法并改为写入@api.multi
或@api.one
。