Skip to Content
Odoo Menu
  • Prisijungti
  • Išbandykite nemokamai
  • Programėlės
    Finansai
    • Apskaita
    • Pateikimas apmokėjimui
    • Sąnaudos
    • Skaičiuoklė (BI)
    • Dokumentai
    • Pasirašymas
    Pardavimai
    • CRM
    • Pardavimai
    • Kasų sistema - Parduotuvė
    • Kasų sistema - Restoranas
    • Prenumeratos
    • Nuoma
    Svetainės
    • Svetainių kūrėjimo įrankis
    • El. Prekyba
    • Internetinis Tinklaraštis
    • Forumas
    • Tiesioginis pokalbis
    • eMokymasis
    Tiekimo grandinė
    • Atsarga
    • Gamyba
    • PLM
    • Įsigijimai
    • Priežiūra
    • Kokybė
    Žmogaus ištekliai
    • Darbuotojai
    • Įdarbinimas
    • Atostogos
    • Įvertinimai
    • Rekomendacijos
    • Transporto priemonės
    Rinkodara
    • Socialinė rinkodara
    • Rinkodara el. paštu
    • SMS rinkodara
    • Renginiai
    • Rinkodaros automatizavimas
    • Apklausos
    Paslaugos
    • Projektas
    • Darbo laiko žiniaraščiai
    • Priežiūros tarnyba
    • Pagalbos tarnyba
    • Planavimas
    • Rezervacijos
    Produktyvumas
    • Diskucija
    • Patvirtinimai
    • IoT
    • VoIP
    • Žinių biblioteka
    • WhatsApp
    Trečiųjų šalių programos Odoo Studija Odoo debesijos platforma
  • Pramonės šakos
    Mažmeninė prekyba
    • Knygynas
    • Drabužių parduotuvė
    • Baldų parduotuvė
    • Maisto prekių parduotuvė
    • Techninės įrangos parduotuvė
    • Žaislų parduotuvė
    Food & Hospitality
    • Barai ir pub'ai
    • Restoranas
    • Greitasis maistas
    • Guest House
    • Gėrimų platintojas
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Consulting
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Aplinkos agentūra
    • Reklaminių stendų nuoma
    • Fotografavimas
    • Dviračių nuoma
    • Programinės įrangos perpardavėjas
    Browse all Industries
  • Bendrija
    Mokykitės
    • Mokomosios medžiagos
    • Dokumentacija
    • Sertifikatai
    • Mokymai
    • Internetinis Tinklaraštis
    • Tinklalaidės
    Skatinkite švietinimą
    • Švietimo programa
    • Scale Up! Verslo žaidimas
    • Aplankykite Odoo
    Gaukite programinę įrangą
    • Atsisiųsti
    • Palyginkite versijas
    • Leidimai
    Bendradarbiauti
    • Github
    • Forumas
    • Renginiai
    • Vertimai
    • Tapkite partneriu
    • Services for Partners
    • Registruokite jūsų apskaitos įmonę
    Gaukite paslaugas
    • Susiraskite partnerį
    • Susirask buhalterį
    • Susitikti su konsultantu
    • Diegimo paslaugos
    • Klientų rekomendavimas
    • Palaikymas
    • Atnaujinimai
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Gaukite demo
  • Kainodara
  • Pagalba

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

  • CRM
  • e-Commerce
  • Apskaita
  • Atsarga
  • PoS
  • Projektas
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Žymos (View all)
odoo accounting v14 pos v15
About this forum
Pagalba

Call Python function from JavaScript

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
javascriptpythonxmlodooV8
6 Replies
26977 Rodiniai
Portretas
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
Portretas
Atmesti
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.

Portretas
Temur
Best Answer

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
Portretas
Atmesti
Portretas
Virali
Best Answer

For this you can use:

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

4
Portretas
Atmesti
Portretas
Shameem Babu
Best Answer


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
Portretas
Atmesti
LaoThai

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

Portretas
Ranga Dharmapriya
Autorius Best Answer

 

0
Portretas
Atmesti
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 ?
Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Registracija
Related Posts Replies Rodiniai Veikla
How to add restriction to Users in Odoo
python xml odooV8
Portretas
Portretas
1
lapkr. 22
3913
Document type: account.analytic.account, Operation: read
python xml odooV8
Portretas
Portretas
1
vas. 21
8082
synchronous JS
javascript python xml
Portretas
Portretas
2
birž. 18
6250
How to know menu parent id? Solved
python xml odooV8
Portretas
Portretas
1
saus. 16
7505
Error : "TypeError: data[0] is undefined " [EDITED with code]? Solved
javascript python xml
Portretas
Portretas
Portretas
Portretas
Portretas
7
gruod. 23
27224
Bendrija
  • Mokomosios medžiagos
  • Dokumentacija
  • Forumas
Atvirasis kodas
  • Atsisiųsti
  • Github
  • Runbot
  • Vertimai
Paslaugos
  • Odoo.sh talpinimas
  • Palaikymas
  • Atnaujinti
  • Pritaikytas programavimo kūrimas
  • Švietimas
  • Susirask buhalterį
  • Susiraskite partnerį
  • Tapkite partneriu
Apie mus
  • Mūsų įmonė
  • Prekės ženklo turtas
  • Susisiekite su mumis
  • Darbo pasiūlymai
  • Renginiai
  • Tinklalaidės
  • Internetinis Tinklaraštis
  • Klientai
  • Teisinis • Privatumas
  • Saugumas
الْعَرَبيّة 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 yra atvirojo kodo verslo programų rinkinys, kuris apima visas įmonės poreikius: CRM, El. Prekybą, Apskaitą, Atsargų, Kasų sistemą, Projektų valdymą ir kt.

Unikali Odoo vertės pasiūla – būti tuo pačiu metu labai lengvai naudojama ir visiškai integruota sistema.

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