0

i have a method that prints a report. That method is not defined inside an Odoo model class, but it is defined inside the website controller. I want to call that method from odoo website, 'My Invoices' section. The method do something in backend and if it doesn't find some information it raises a Warning error. I want to show that error in a website pop up, using javascript.

I found out how to show a simple alert "Hello" in a pop up using the following code:

<script>
    function printInvoice(){
        alert("Hello");
    }
</script>
<a href="javascript:printInvoice();">
    <t t-esc="invoice.full_name"/>
</a>

now i want to call the python method and show the string message it returns inside the alert. python code:

def my_function(self, invoice_report_render):
    try:
       invoice_report_render.get_pdf()

    except Exception, e:
       return e[0]

Is there any way to call 'my_function' from javascript above code and put the message in the alert?

Thank you very much

  • Javascript can make an HTTP call to your server. Your server can run the function and return a result back to the client, and the javascript can read that result and react appropriately. – TKoL Oct 20 '17 at 11:48
  • HTTP calls (AJAX) can be made using various libraries, xmlhttprequest, $.get (jquery), or the new Fetch api. – TKoL Oct 20 '17 at 11:49
  • This question may have been badly worded, but it wasn't a duplicate at all. – David V. Jun 15 '21 at 13:03

0 Answers0