Odoo is the world's easiest all-in-one management software. It includes hundreds of business apps:
CRM | e-Commerce | Accounting | Inventory | PoS | Project management | MRP | etc.
I would like to play a sound every time a custom button is pressed. The button is calling a server.action to update a custom field on an order and will be use to inform a user that the order is ready to be delivered. I would like to use pyglet with this simple script:
wavfile = '/home/effe/theetone.wav' sound = pyglet.media.load(wavfile) core = pyglet.media.Player() core.queue(sound) core.play()
But is not working when I use a python expression on server.actions.
ValueError: opcode IMPORT_NAME not allowed (u"import pyglet\n\nwavfile = '/home/effe/theetone.wav'\nsound = pyglet.media.load(wavfile)\ncore = pyglet.media.Player()\ncore.queue(sound)\ncore.play()")
Seems I can't declare an import (import pyglet) on python expression field and even if I put the import line on my module seems not to works. Where am I wrong?
I think import will not work in the code section of the server action ...
you can make a new function in your model and call it from the action, model.py :
def play_sound(self, cr, uid, context=None):
myfile = '/home/ahmed/Music/bell.ogg'
sound = pyglet.media.load(myfile)
core = pyglet.media.Player()
Then from the action you can call this function:
<record model="ir.actions.server" id="play_sound_action">
<field name="name">Play Server Action</field>
<field name="model_id" ref="model_test_test"/>
# you code here
self.play_sound(cr, uid, context)
since I got some issues even on pycharm I've update my script using pygame instead of pyglet because I need to separate the audio channels :
sound = pygame.mixer.Sound("/home/effe/theetone.wav")
channel = sound.play()
#depending of the sound use left or right channel to mute
Works fine on the IDE but I'm still unable to correctly create a function on point_of_sale.py and link it to the server.action via gui on Odoo.
About This Community
This platform is for beginners and experts willing to share their Odoo knowledge. It's not a forum to discuss ideas, but a knowledge base of questions and their answers.Register
Odoo Training Center
Access to our E-learning platform and experience all Odoo Apps through learning videos, exercises and Quizz.Test it now
|Asked: 5/24/15, 8:12 PM|
|Seen: 1059 times|
|Last updated: 5/26/15, 7:32 PM|