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
    Nekilnojamasis turtas
    • Real Estate Agency
    • Architektūros įmonė
    • Konstrukcija
    • Estate Managament
    • Sodininkauti
    • Turto savininkų asociacija
    Konsultavimas
    • Accounting Firm
    • Odoo Partneris
    • Marketing Agency
    • Teisinė firma
    • Talentų paieška
    • Auditai & sertifikavimas
    Gamyba
    • Textile
    • Metal
    • Furnitures
    • Maistas
    • Brewery
    • Įmonių dovanos
    Sveikata & Fitnesas
    • Sporto klubas
    • Akinių parduotuvė
    • Fitneso Centras
    • Sveikatos praktikai
    • Vaistinė
    • Kirpėjas
    Trades
    • Handyman
    • IT įranga ir palaikymas
    • Saulės energijos sistemos
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Kiti
    • 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

Form Submission Odoo not loading HTTP Route

Prenumeruoti

Get notified when there's activity on this post

This question has been flagged
httproutes
3 Replies
6081 Rodiniai
Portretas
John


So I have a POST route in my controller that is supposed to send an email.

controller.py:

class Customer(http.Controller):
    @http.route('/api/hello', methods=['POST'], auth='public', type='http', website=True)
    def index(self, **kw):
        message = Mail(
          from_email='x@gmail.com',
          to_emails='x@gmail.com',
          subject='Notification',
          html_content="Working")
    sg = SendGridAPIClient(os.environ.get('SENDGRID_API_KEY'))
    sg.send(message)

And in my view.xml I have a form asking for name, email and that kind of stuff.

view_field.xml:

<?xml version="1.0" encoding="UTF-8"?>
<odoo>

<record model="ir.ui.view" id="customer_field_form">
    <field name="name">Field</field>
    <field name="model">customer.field</field>
    <field name="arch" type="xml">
        <form action="/api/hello" method="POST">
            <sheet>
                <group>
                    <field name="name" placeholder="Full Name"/><br />
                    <field name="email_address" placeholder="Email Address" /><br />
                    <field name="subject" placeholder="Subject"/><br />
                    <field name="message" placeholder="Message" /><br />
                    <button name="submit" type="submit" > Submit </button>
                </group>
            </sheet>
        </form>
    </field>
</record>

</odoo>

Well no matter what I do my route is never called and the email never sent. I tried putting an < input > instead of a button but it doesn't work either. I really don't see what I'm doing wrong.

If I change my method in a GET and launch it with Chrome the email is sent. So I doubt the problem comes from my route. And yes I have my imported my route in the init.py file.


0
Portretas
Atmesti
Portretas
Ravi Gadhia
Best Answer

Ok your goal is to send email using SendGridAPIClient

Odoo has its own javascript framework which simplifies the things. It handles many complexities and provides an easy way to manage CRUD operation on any model and communicate with the server.​

Here <sheet> <field> are not regular HTML element. it's interpreted by rendering engine and generate pure HTML view and Display it on DOM

So if you want to call the server method on button click then there is no need to define a controller.
on click of <button name="send_email" type="object" string="Send Email" /> it will call send_email method on model

==============================
class MyModel(models.Model):
    _name = 'customer.field'

    @api.multi
    def send_email(self):
        print('here you will get all the field value', self.name, self.email_address)
       # send email code here

==============================

replace view like

<form>
    <sheet>
        <group>
                <field name="name" placeholder="Full Name"/> <br />
                <field name="email_address" placeholder="Email Address" /><br />
                <field name="subject" placeholder="Subject"/><br />
                <field name="message" placeholder="Message" /><br />
                <button name="send_email" type="object" > Send Email </button>
        </group>
    </sheet>
</form>


 Here is the example of it https://www.odoo.com/documentation/11.0/howtos/backend.html#launching-wizards

0
Portretas
Atmesti
Portretas
John
Autorius Best Answer

Hi Jake,

Sorry but it doesn't work. I tried before to put CSRF=False in the params of my route and yet nothing happens (I also tried what you just did, still nothing).

I am still very new to Odoo, can you confirm to me that my view_field.xml is correct? The form is supposed to be here, under the model? I don't use any templating or anything, can an action on a form be called in a regular xml file? Can a form be placed under a field "arch"? That's the only reasons I'm seeing why it doesn't work, when I click on submit my entry is registered in the db but nothing else seems to happen, nothing is called.

I've been asking 5 other software engineers friends and no one can figure it out, I've been stuck for 2 days. 

0
Portretas
Atmesti
Portretas
Jake Robinson
Best Answer

Hi John,

Since version 9, as a part of its commitment to security, Odoo has implemented CSRF tokens. In order for a POST method to be called, you will need to add an input into your form similar to the following:

<input type="hidden" name="csrf_token" t-att-value="request.csrf_token()"/>

This CSRF token will be verified before your controller is even called.

For more information on the topic, check out the Web Controllers page in the Odoo Developer Documents. 


0
Portretas
Atmesti
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
MO Pick BOM Components Issue
routes
Portretas
0
geg. 25
1593
Route for 2 product lines
routes
Portretas
Portretas
1
liep. 24
2295
Odoo Studio - Show product routes in BoM list view (odoo.sh v13) Solved
routes
Portretas
Portretas
Portretas
2
gruod. 20
3671
Why am I unable to use port 80?
http
Portretas
Portretas
Portretas
2
gruod. 19
6379
BOM not displayed according to BOM Route
routes
Portretas
0
vas. 18
3888
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