Odoo Help

Welcome!

This community 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.

1

[V8] Play sound on server on button event.

By
FEDERICO LEONI
on 5/24/15, 8:12 PM 835 views

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:

#!/usr/bin/env python

import pyglet
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?

 

2

Ahmed M.Elmubarak

--Ahmed M.Elmubarak--
2988
| 5 3 5
Sudan
--Ahmed M.Elmubarak--


Ahmed M.Elmubarak
On 5/25/15, 5:40 AM

Hello,

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()
    core.queue(sound)
    core.play()
    return True


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"/>
    <field name="code">
           #
           # you code here
           #
    self.play_sound(cr, uid, context)
</field>
</record>


Regards ..

I've added on my modified point_of_sale.py the import and inherit the pos.order model:

class pos_order(osv.Model):
    _inherit = 'pos.order'

def play_sound(self, cr, uid, context=None):
    myfile = '/home/effe/KDE_Beep_Digital_1.ogg'
    sound = pyglet.media.load(myfile)
    core = pyglet.media.Player()
    core.queue(sound)
    core.play()
    return True
The update of pos.order did work well but I can't figure out how to implement the python code directly on gui... I've added directly the line
self.play_sound(cr, uid, context)
but obviously didn't work:
ValueError: "'pos.order' object has no attribute 'play_sound'" while evaluating
u'self.play_sound(cr, uid, context)'
Where I'm wrong?
FEDERICO LEONI
on 5/25/15, 2:59 PM

Hi, where did you added the self.play_sound(cr, uid, context) ?

Ahmed M.Elmubarak
on 6/13/15, 2:59 AM
1
FEDERICO LEONI
On 5/26/15, 6:52 PM

Ahmed,

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 :

import pygame
import time

pygame.init()
sound = pygame.mixer.Sound("/home/effe/theetone.wav")
channel = sound.play()
#depending of the sound use left or right channel to mute
channel.set_volume(1,1)
time.sleep(2)

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.

Great!, I'll try it on point_of_sale.py whenever I have spare time ... It will be helpful if you can tell me the scenario, because I think you're working on POS ... and may be will need to call the function from js

Ahmed M.Elmubarak
on 5/27/15, 2:16 AM

Amhed, thanks for your time.
Scenario:
I'm working on a new module for my restaurant. Since we have just one thermal printer and sincerely I don't like how Odoo manages printers, I started to create a new flow using a server, a client on the kitchen and a tablet to make the orders.
The server is located between the kitchen and the front desk and has one speaker for each ambient. When I send the order to the kitchen the server will to play a sound on the right speaker

channel.set_volume(0,1)
and this function should be implemented on pos js as you propose (how is another story).
When an order is done and the button linked to the actions.server on my form view will be pressed, another different sound will be sent to left speaker
channel.set_volume(1,0)
That will be the def I need on my .py.
I'm already using this method (without sounds linked) and works fine for my needs but have an alert will be grab the attention when there are many customers. When all will be ready I'll pack a module and share with the community because there are many missing things for a restaurant implementation on stock Odoo. Think on pos_restaurant module for example: if you haven't an ESC/POS compatible printer is pretty unhelpful because the module can't generate pdf or interactive views.
FEDERICO LEONI
on 5/27/15, 9:39 AM

Hi, I think in Odoo 9 there will be a new POS for restaurants : https://docs.google.com/spreadsheets/d/18CZGaF7igfVEt5_P-F7KzmXPfc-XYXT0iaPFYldCkm0/edit#gid=0 anyway I think the second part is working with the script in the answer right ?

Ahmed M.Elmubarak
on 6/10/15, 3:02 AM

Yes, a new pos with (finally) tables management. What second part you're talking about? I'm still stuck but for now I'm not working on pos 9 because is unstable. On production with use V8.

FEDERICO LEONI
on 6/10/15, 8:20 AM

Hi, the second part is : when the order is done "and the button linked to the actions.server" ... - the first part is when you send the order to the kitchen ...

Ahmed M.Elmubarak
on 6/11/15, 2:00 AM

The script that send the order to the kitchen works, but not the sound.

FEDERICO LEONI
on 6/11/15, 8:10 AM

Your Answer

Please try to give a substantial answer. If you wanted to comment on the question or answer, just use the commenting tool. Please remember that you can always revise your answers - no need to answer the same question twice. Also, please don't forget to vote - it really helps to select the best questions and answers!

About This Community

This community is for professionals and enthusiasts of our products and services. Read Guidelines

Question tools

2 follower(s)

Stats

Asked: 5/24/15, 8:12 PM
Seen: 835 times
Last updated: 5/26/15, 7:32 PM