Siirry sisältöön
Odoo Menu
  • Kirjaudu sisään
  • Kokeile ilmaiseksi
  • Sovellukset
    Talous
    • Kirjanpito
    • Laskutus
    • Kulut
    • Datataulukot (BI)
    • Asiakirjat
    • Allekirjoita
    Myynti
    • CRM
    • Myynti
    • Kassajärjestelmä myymälään
    • Kassajärjestelmä ravintolaan
    • Tilaukset
    • Vuokraus
    Verkkosivut
    • Verkkosivun Rakennustyökalu
    • Verkkokauppa
    • Blogi
    • Foorumi
    • Livechat
    • Verkko-oppiminen
    Toimitusketju
    • Varastointi
    • Tuotanto
    • Tuotteen elinkaaren hallinta (PLM)
    • Ostot
    • Huolto
    • Laatu
    Henkilöstöhallinto
    • Työntekijät
    • Rekrytointi
    • Vapaat
    • Arvioinnit
    • Suositukset
    • Kuljetuskalusto
    Markkinointi
    • Somemarkkinointi
    • Sähköpostimarkkinointi
    • Tekstiviestimarkkinointi
    • Tapahtumat
    • Markkinoinnin automaatio
    • Kyselyt
    Palvelut
    • Projekti
    • Työaikakirjaukset
    • Kenttähuolto
    • Asiakaspalvelu
    • Suunnittelu
    • Ajanvaraukset
    Tuottavuus
    • Viestintä
    • Hyväksynnät
    • IoT
    • IP-puhe
    • Tietokirjasto
    • WhatsApp
    Kolmannen osapuolen sovellukset Odoo-Studio Odoo-Pilvialusta
  • Toimialat
    Vähittäiskauppa
    • Kirjakauppa
    • Vaatekauppa
    • Huonekaluliike
    • Ruokakauppa
    • Laitteistokauppa
    • Lelukauppa
    Ruoka & Majoitus
    • Baari ja Pubi
    • Ravintola
    • Pikaruoka
    • Majatalo
    • Juomien jakelija
    • Hotelli
    Kiinteistöt
    • Kiinteistönvälitystoimisto
    • Arkkitehtitoimisto
    • Rakentaminen
    • Kiinteistönhallinta
    • Puutarhanhoito
    • Kiinteistön omistajien yhdistys
    Konsultointi
    • Tilitoimisto
    • Odoo-kumppani
    • Markkinointitoimisto
    • Lakitoimisto
    • Osaajahankinta
    • Tilintarkastus & sertifiointi
    Tuotanto
    • Tekstiili
    • Metalli
    • Huonekalut
    • Ruoka
    • Panimo
    • Yrityslahjat
    Terveys & Liikunta
    • Urheiluseura
    • Silmälasiliike
    • Kuntokeskus
    • Hyvinvointialan ammattilaiset
    • Apteekki
    • Kampaamo
    Kaupat
    • Yleismies
    • IT-laitteisto & Tuki
    • Aurinkoenergiajärjestelmät
    • Suutari
    • Siivouspalvelut
    • LVI-palvelut
    Muut
    • Voittoa tavoittelematon järjestö
    • Ympäristötoimisto
    • Mainostaulujen vuokraus  
    • Valokuvaus
    • Leasing-pyörät
    • Ohjelmistojen jälleenmyyjä
    Selaa kaikkia toimialoja
  • Yhteisö
    Opi
    • Kurssit
    • Dokumentaatio
    • Todistukset
    • Koulutus
    • Blogi
    • Podcast
    Kannusta kouluttautumaan
    • Koulutusohjelmat
    • Scale Up! Liiketoimintapeli
    • Vieraile Odoolla
    Hanki ohjelmisto
    • Lataa
    • Vertaile versioita
    • Julkaisut
    Tee yhteistyötä
    • Github
    • Foorumi
    • Tapahtumat
    • Käännökset
    • Ryhdy kumppaniksi
    • Kumppanipalvelut
    • Rekisteröi tilitoimistosi
    Hanki palveluja
    • Löydä kumppani
    • Löydä kirjanpitäjä
    • Varaa asiantuntijatapaaminen
    • Implementaatiopalvelut
    • Asiakasreferenssit
    • Tuki
    • Versionkorotukset
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Varaa demo
  • Hinnoittelu
  • Asiakaspalvelu

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

  • CRM
  • e-Commerce
  • Kirjanpito
  • Varastointi
  • PoS
  • Projekti
  • MRP
All apps
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Sinun on rekisteröidyttävä, jotta voit olla vuorovaikutuksessa yhteisön kanssa.
Kaikki kirjoitukset Ihmiset Merkit
Tunnisteet (Näytä kaikki)
odoo accounting v14 pos v15
Tietoa tästä foorumista
Apua

Form Submission Odoo not loading HTTP Route

Tilaa

Saat ilmoituksen, kun tähän viestiin ilmaantuu aktiviteettia

Tämä kysymys on merkitty
httproutes
3 Vastaukset
6085 Näkymät
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
Hylkää
Avatar
Ravi Gadhia
Paras vastaus

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
Hylkää
Avatar
John
Tekijä Paras vastaus

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
Hylkää
Avatar
Jake Robinson
Paras vastaus

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
Hylkää
Nautitko keskustelusta? Älä vain lue, vaan osallistu!

Luo tili jo tänään nauttiaksesi yksinoikeusominaisuuksista ja osallistuaksesi mahtavaan yhteisöömme!

Rekisteröidy
Aiheeseen liittyviä artikkeleita Vastaukset Näkymät Toimenpide
MO Pick BOM Components Issue
routes
Avatar
0
toukok. 25
1595
Route for 2 product lines
routes
Avatar
Avatar
1
heinäk. 24
2297
Odoo Studio - Show product routes in BoM list view (odoo.sh v13) Ratkaistu
routes
Avatar
Avatar
Avatar
2
jouluk. 20
3673
Why am I unable to use port 80?
http
Avatar
Avatar
Avatar
2
jouluk. 19
6382
BOM not displayed according to BOM Route
routes
Avatar
0
helmik. 18
3890
Yhteisö
  • Kurssit
  • Dokumentaatio
  • Foorumi
Avoin lähdekoodi
  • Lataa
  • Github
  • Runbot
  • Käännökset
Palvelut
  • Odoo.sh hosting
  • Tuki
  • Versionkorotus
  • Räätälöidyt kehitykset
  • Koulutus
  • Löydä kirjanpitäjä
  • Löydä kumppani
  • Ryhdy kumppaniksi
Meistä
  • Yrityksemme
  • Tavaramerkki
  • Ota yhteyttä
  • Työpaikat
  • Tapahtumat
  • Podcast
  • Blogi
  • Asiakkaat
  • Oikeudellinen ilmoitus • Yksityisyys
  • Tietoturva
الْعَرَبيّة 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 on kokoelma avoimen lähdekoodin yrityssovelluksia, jotka kattavat kaikki yrityksesi tarpeet: asiakkuudenhallinta eli CRM, verkkokauppa, kirjanpito, varastointi, kassajärjestelmä, projektinhallinta, jne.

Odoon uniikki arvolupaus on olla samanaikaisesti erittäin helppokäyttöinen ja täysin integroitu.

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