Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

Form Submission Odoo not loading HTTP Route

Odoberať

Get notified when there's activity on this post

This question has been flagged
httproutes
3 Replies
6082 Zobrazenia
Avatar
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
Avatar
Zrušiť
Avatar
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
Avatar
Zrušiť
Avatar
John
Autor 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
Avatar
Zrušiť
Avatar
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
Avatar
Zrušiť
Enjoying the discussion? Don't just read, join in!

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

Registrácia
Related Posts Replies Zobrazenia Aktivita
MO Pick BOM Components Issue
routes
Avatar
0
máj 25
1594
Route for 2 product lines
routes
Avatar
Avatar
1
júl 24
2296
Odoo Studio - Show product routes in BoM list view (odoo.sh v13) Solved
routes
Avatar
Avatar
Avatar
2
dec 20
3671
Why am I unable to use port 80?
http
Avatar
Avatar
Avatar
2
dec 19
6380
BOM not displayed according to BOM Route
routes
Avatar
0
feb 18
3888
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 je sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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