I'm trying to use this Odoo addon:
https://www.odoo.com/apps/modules/8.0/warning_box/
https://github.com/ingadhoc/odoo-addons/tree/8.0/warning_box
to display some messages.
The install page says:
usage return self.pool.get('warning_box').info(cr, uid, title='The title', message='the message')
Since the code is written in V8.0 style, I think this is wrong. I've tried it anyway and it gave errors about cr and uid.
I then tried it like this:
self.env['warning_box'].info(self, title='The title', message='the message')
This gives me this error:
TypeError: info() got multiple values for keyword argument 'title'
This is the python code of the Odoo addon:
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()
I have been looking up the error and found these 2 pieces of information:
class method generates "TypeError: ... got multiple values for keyword argument ..."
TypeError: create() got multiple values for keyword argument 'context'
I've tried to understand it and to apply it to my situation, but I can't get it working... Can anyone tell me what's wrong with this code?
edit for Forvas:
I call the function like this now:
return self.env['warning_box'].error(title='The title', message='the message')
This didn't give any errors with the code above.
Now I've changed def message_action like you said. For this:
form_view_id = self.env.ref(
'your_module_name.your_form_view_xml_id').id
I used:
form_view_id = self.env.ref(
'warning_box_git.warning_box_form').id
Just to make sure, did you mean module name or model name? My model (class) is warning_box and my module name is warning_box_git (name of the folder of the module). Did I do this correct?
Either way I keep getting this error:
AttributeError: 'warning_box' object has no attribute 'error'
This is my 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>
Do you have any idea how to solve the error?
edit 2 for Forvas: I made a stupid indentation mistake. That error is gone now. But still, it doesn't show any pop-ups?