Ir al contenido
Odoo Menú
  • Identificarse
  • Pruébalo gratis
  • Aplicaciones
    Finanzas
    • Contabilidad
    • Facturación
    • Gastos
    • Hoja de cálculo (BI)
    • Documentos
    • Firma electrónica
    Ventas
    • CRM
    • Ventas
    • TPV para tiendas
    • TPV para restaurantes
    • Suscripciones
    • Alquiler
    Sitios web
    • Creador de sitios web
    • Comercio electrónico
    • Blog
    • Foro
    • Chat en directo
    • eLearning
    Cadena de suministro
    • Inventario
    • Fabricación
    • PLM
    • Compra
    • Mantenimiento
    • Calidad
    Recursos Humanos
    • Empleados
    • Reclutamiento
    • Ausencias
    • Evaluación
    • Referencias
    • Flota
    Marketing
    • Marketing social
    • Marketing por correo electrónico
    • Marketing por SMS
    • Eventos
    • Automatización de marketing
    • Encuestas
    Servicios
    • Proyecto
    • Partes de horas
    • Servicio de campo
    • Servicio de asistencia
    • Planificación
    • Citas
    Productividad
    • Conversaciones
    • Aprobaciones
    • IoT
    • VoIP
    • Información
    • WhatsApp
    Aplicaciones de terceros Studio de Odoo Plataforma de Odoo Cloud
  • Industrias
    Comercio al por menor
    • Librería
    • Tienda de ropa
    • Tienda de muebles
    • Tienda de ultramarinos
    • Ferretería
    • Juguetería
    Food & Hospitality
    • Bar y taberna
    • Restaurante
    • Comida rápida
    • Guest House
    • Distribuidor de bebidas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Estudio de arquitectura
    • Construcción
    • Gestión inmobiliaria
    • Jardinería
    • Asociación de propietarios
    Consulting
    • Accounting Firm
    • Partner de Odoo
    • Agencia de marketing
    • Bufete de abogados
    • Adquisición de talentos
    • Auditorías y certificaciones
    Fabricación
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Regalos de empresas
    Salud y bienestar
    • Club deportivo
    • Óptica
    • Gimnasio
    • Terapeutas
    • Farmacia
    • Peluquería
    Trades
    • Handyman
    • Hardware y asistencia informática
    • Solar Energy Systems
    • Zapatero
    • Servicios de limpieza
    • HVAC Services
    Others
    • Nonprofit Organization
    • Agencia de protección del medio ambiente
    • Alquiler de paneles publicitarios
    • Estudio fotográfico
    • Alquiler de bicicletas
    • Distribuidor de software
    Browse all Industries
  • Comunidad
    Aprender
    • Tutoriales
    • Documentación
    • Certificaciones
    • Formación
    • Blog
    • Podcast
    Potenciar la educación
    • Programa de formación
    • Scale Up! El juego empresarial
    • Visita Odoo
    Obtener el software
    • Descargar
    • Comparar ediciones
    • Versiones
    Colaborar
    • GitHub
    • Foro
    • Eventos
    • Traducciones
    • Convertirse en partner
    • Services for Partners
    • Registrar tu empresa contable
    Obtener servicios
    • Encontrar un partner
    • Encontrar un asesor fiscal
    • Contacta con un experto
    • Servicios de implementación
    • Referencias de clientes
    • Ayuda
    • Actualizaciones
    GitHub YouTube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Solicitar una demostración
  • Precios
  • Ayuda

Odoo is the world's easiest all-in-one management software.
It includes hundreds of business apps:

  • CRM
  • e-Commerce
  • Contabilidad
  • Inventario
  • PoS
  • Proyecto
  • MRP
All apps
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Debe estar registrado para interactuar con la comunidad.
Todas las publicaciones Personas Insignias
Etiquetas (Ver todo)
odoo accounting v14 pos v15
Acerca de este foro
Ayuda

Call Python function from JavaScript

Suscribirse

Reciba una notificación cuando haya actividad en esta publicación

Se marcó esta pregunta
javascriptpythonxmlodooV8
6 Respuestas
26950 Vistas
Avatar
Ranga Dharmapriya


I have created function called mrp_Order and call this function when click the req button. But I got this error.

Odoo Server Error

Traceback (most recent call last):

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 530, in _handle_exception

return super(JsonRequest, self)._handle_exception(exception)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 567, in dispatch

result = self._call_function(**self.params)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 303, in _call_function

return checked_call(self.db, *args, **kwargs)

File "D:\Odoo\odoo-v8-osm\openerp\service\model.py", line 113, in wrapper

return f(dbname, *args, **kwargs)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 300, in checked_call

return self.endpoint(*a, **kw)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 796, in __call__

return self.method(*args, **kw)

File "D:\Odoo\odoo-v8-osm\openerp\http.py", line 396, in response_wrap

response = f(*args, **kw)

File "D:\Odoo\odoo-v8-osm\addons\web\controllers\main.py", line 935, in call_kw

return self._call_kw(model, method, args, kwargs)

File "D:\Odoo\odoo-v8-osm\addons\web\controllers\main.py", line 927, in _call_kw

return getattr(request.registry.get(model), method)(request.cr, request.uid, *args, **kwargs)

File "D:\Odoo\odoo-v8-osm\openerp\api.py", line 241, in wrapper

return old_api(self, *args, **kwargs)

TypeError: mrp_Order() takes at least 4 arguments (3 given)

Python code

def mrp_Order(self, cr, uid, ids, context=None):

result = {

'name': "mrpOrder",

'view_mode': 'form',

'view_type': 'form',

'res_model': 'mrp.production',

'type': 'ir.actions.act_window',

'nodestory': True,

'target' : 'new',

'context' : context,

}

return result

JavaScript code

function openerp_restaurant_reqbill(instance,module){

var QWeb = instance.web.qweb;

var _t = instance.web._t;

module.PosWidget.include({

build_widgets: function(){

var self = this;

this._super();

if(this.pos.config.iface_raqbill){

var reqbill = $(QWeb.render('PrintReqButton'));

reqbill.click(function(){

var order = self.pos.get('selectedOrder');

if(order.get('orderLines').models.length > 0){

var receipt = order.export_for_printing();

self.pos.proxy.print_receipt(QWeb.render('BillReceipts',{

receipt: receipt, widget: self,

}));

}

new instance.web.Model("pos.order").call("mrp_Order");

});

reqbill.appendTo(this.$('.control-buttons'));

this.$('.control-buttons').removeClass('oe_hidden');

}

},

});

}

2
Avatar
Descartar
Temur

a side note: you taged question with "odooV8" but function definition is in old style. take look of this post if you interested in new v8.0 API way to do the same.

Avatar
Temur
Mejor respuesta

you have to remove ids parameter from your function definition, or pass ids from javascript. in first case, your function definition will become:

def mrp_Order(self, cr, uid, context=None): 

-note that ids parameter is NOT present.

otherwise, when you need to have ids parameter in your function, then you've to pass ids from javascript, as first element of argument list, in your case you can pass empty array of ids (but as you don't use ids anyway in your python function, better to use above posted option):

new instance.web.Model("pos.order").call("mrp_Order", [[]]); 

-used array of argument list and it's first element is list of ids, that's going to be value of ids parameter in your python function.


4
Avatar
Descartar
Avatar
Virali
Mejor respuesta

For this you can use:

new instance.web.Model('pos.order').call("mrp_Order",[ [SPECIFY IDS IN LIST] ]);

4
Avatar
Descartar
Avatar
Shameem Babu
Mejor respuesta


In Javascript

odoo.define('custom_module.my_javascript', function (require) {"use strict"; 
var Model = require('web.Model')

var custom_model = new Model('custom.model')
custom_model.call('my_function')

});

In Python

from odoo import models, fields, api 

class CustomModel(models.Model):
_name = 'custom.model'
     # .............

@api.model
def my_function(self):
        print 'fooooooooooooooo'
Watch this on YouTube !

It is working in Odoo 10


2
Avatar
Descartar
LaoThai

But not in odoo 11, because Odoo 11 doesn't have web.Model. Any suggest for Odoo 11?

Avatar
Ranga Dharmapriya
Autor Mejor respuesta

 

0
Avatar
Descartar
Temur

interesting... it does nothing? you've had wrong call of python function, I corrected it for you and I think you have no more the error posted in your question. actually you are asking new question on the same thread, that's "how to show popup in pos?" it's a bit different then "Call Python function from JavaScript". I suggest to open new thread with "how to show popup in pos?" title, or something more close to your requirements. because of question asked and error log provided I have not read your code line by line, but I found the source of error. whereas as I see now, after you clarified your requirement to open popup... the problem is that this is not a way to open popup. I investigated your code more deeply, you simply call "mrp_Order" function, but you do nothing with result of this call. you can use such call(and do not handle result in "then()") if it does something at server side and returns nothing, i.e. for "void" functions. but if you've to handle returned value, then you should use "then()" as follows:

new instance.web.Model("pos.order").call("mrp_Order").then(function(result){
        //here result contains whatever is returned from mrp_Oder function, in your case
        //result contains: {'name': "mrpOrder", 'view_mode': 'form', 'view_type': 'form', 'res_model': 'mrp.production', 'type': 'ir.actions.act_window', 'nodestory': True, 'target' : 'new', 'context' : context,}
        //that's all. try this:
        console.log(result)
    }); 
you see? you can do whatever you want with result(returned value) of mrp_Oder function in then() part, but if you expect the mrp_Order to open popup window at client side just because you call it, then I'm afraid to disappoint you, but that's not going to happen.
one more side note, I'm not familiar with pos module but pos is implemented to work independently in case of internet connection interruption. probably adding RPC call can compromise this ability, as RPC can't be done in offline mode. maybe you need something like https://github.com/odoo/odoo/blob/2ac4a3854be846a178972ecc6ee5a6318bce3995/addons/point_of_sale/static/src/js/screens.js#L359-L383 ?
¿Le interesa esta conversación? ¡Participe en ella!

Cree una cuenta para poder utilizar funciones exclusivas e interactuar con la comunidad.

Inscribirse
Publicaciones relacionadas Respuestas Vistas Actividad
How to add restriction to Users in Odoo
python xml odooV8
Avatar
Avatar
1
nov 22
3886
Document type: account.analytic.account, Operation: read
python xml odooV8
Avatar
Avatar
1
feb 21
8036
synchronous JS
javascript python xml
Avatar
Avatar
2
jun 18
6233
How to know menu parent id? Resuelto
python xml odooV8
Avatar
Avatar
1
ene 16
7485
Error : "TypeError: data[0] is undefined " [EDITED with code]? Resuelto
javascript python xml
Avatar
Avatar
Avatar
Avatar
Avatar
7
dic 23
27196
Comunidad
  • Tutoriales
  • Documentación
  • Foro
Código abierto
  • Descargar
  • GitHub
  • Runbot
  • Traducciones
Servicios
  • Alojamiento Odoo.sh
  • Ayuda
  • Actualizar
  • Desarrollos personalizados
  • Educación
  • Encontrar un asesor fiscal
  • Encontrar un partner
  • Convertirse en partner
Sobre nosotros
  • Nuestra empresa
  • Activos de marca
  • Contacta con nosotros
  • Puestos de trabajo
  • Eventos
  • Podcast
  • Blog
  • Clientes
  • Información legal • Privacidad
  • Seguridad
الْعَرَبيّة Català 简体中文 繁體中文 (台灣) Čeština Dansk Nederlands English Suomi Français Deutsch हिंदी Bahasa Indonesia Italiano 日本語 한국어 (KR) Lietuvių kalba Język polski Português (BR) română русский язык Slovenský jazyk slovenščina Español (América Latina) Español ภาษาไทย Türkçe українська Tiếng Việt

Odoo es un conjunto de aplicaciones de código abierto que cubren todas las necesidades de tu empresa: CRM, comercio electrónico, contabilidad, inventario, punto de venta, gestión de proyectos, etc.

La propuesta única de valor de Odoo es ser muy fácil de usar y totalmente integrado.

Website made with

Odoo Experience on YouTube

1. Use the live chat to ask your questions.
2. The operator answers within a few minutes.

Live support on Youtube
Watch now