Skip to Content
Odoo Meniu
  • Autentificare
  • Try it free
  • Aplicații
    Finanțe
    • Contabilitate
    • Facturare
    • Cheltuieli
    • Spreadsheet (BI)
    • Documente
    • Semn
    Vânzări
    • CRM
    • Vânzări
    • POS Shop
    • POS Restaurant
    • Abonamente
    • Închiriere
    Site-uri web
    • Constructor de site-uri
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Lanț Aprovizionare
    • Inventar
    • Producție
    • PLM
    • Achiziție
    • Maintenance
    • Calitate
    Resurse Umane
    • Angajați
    • Recrutare
    • Time Off
    • Evaluări
    • Referințe
    • Flotă
    Marketing
    • Social Marketing
    • Marketing prin email
    • SMS Marketing
    • Evenimente
    • Automatizare marketing
    • Sondaje
    Servicii
    • Proiect
    • Foi de pontaj
    • Servicii de teren
    • Centru de asistență
    • Planificare
    • Programări
    Productivitate
    • Discuss
    • Aprobări
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Aplicații Terțe Odoo Studio Platforma Odoo Cloud
  • Industrii
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Managament
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Producție
    • Textile
    • Metal
    • Furnitures
    • Food
    • 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
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Comunitate
    Învăță
    • Tutorials
    • Documentație
    • Certificări
    • Instruire
    • Blog
    • Podcast
    Empower Education
    • Program Educațional
    • Scale Up! Business Game
    • Visit Odoo
    Obține Software-ul
    • Descărcare
    • Compară Edițiile
    • Lansări
    Colaborați
    • Github
    • Forum
    • Evenimente
    • Translations
    • Devino Partener
    • Services for Partners
    • Înregistrează-ți Firma de Contabilitate
    Obține Servicii
    • Găsește un Partener
    • Găsiți un contabil
    • Meet an advisor
    • Servicii de Implementare
    • Referințe ale clienților
    • Suport
    • Actualizări
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Obține un demo
  • Prețuri
  • Ajutor

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

  • CRM
  • e-Commerce
  • Contabilitate
  • Inventar
  • PoS
  • Proiect
  • MRP
All apps
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Trebuie să fiți înregistrat pentru a interacționa cu comunitatea.
All Posts Oameni Insigne
Etichete (View all)
odoo accounting v14 pos v15
Despre acest forum
Suport

How to make a controller on Odoo for custom value?

Abonare

Primiți o notificare când există activitate la acestă postare

Această întrebare a fost marcată
controllerodoo10
2 Răspunsuri
12116 Vizualizări
Imagine profil
Pablo Escobar

I need to make a custom controller on Odoo for getting information from the particular task. And I can able to produce the result also. But now I'm facing an issue.

The client needs to retrieve the information with a particular field.

For example, The client needs to retrieve the information with the tracking number and the data must be JSON format also. If the tracking number is 15556456356, the URL should be www.customurl.com/dataset/15556456356


1
Imagine profil
Abandonează
Imagine profil
Pablo Escobar
Autor Cel mai bun răspuns

Found answer by myself:


The route of that URL should be @http.route('/dataset/<string:tracking_number>', type='http or json', auth="user or public"), basically the method should be like this:


import json

from odoo import http
from odoo.http import Response, request

class tracking(http.Controller):
    # if user must be authenticated use auth="user"
    @http.route('/dataset/<string:tracking_number>', type='http', auth="public")
    def tracking(self, tracking_number):  # use the same variable name
        result = # compute the result with the given tracking_number and the result should be a dict to pass it json.dumps
        return Response(json.dumps(result), content_type='application/json;charset=utf-8',status=200)



This method accept http request and return a json response, if the client is sending a json requests you should change type='json'. don't forget to import the file in the __init___.py.

Lets take an example let say that I want to return some information about a sale.order by a giving ID in the URL:



import json

from odoo import http
from odoo.http import Response, request

 class Tracking(http.Controller):
    @http.route('/dataset/<int:sale_id>', type='http', auth="public")
    def tracking(self, sale_id):
        # get the information using the SUPER USER
        result = request.env['sale.order'].sudo().browse([sale_id]).read(['name', 'date_order'])
        return Response(json.dumps(result), content_type='application/json;charset=utf-8',status=200)

So when I enter this URL using my Browser: http://localhost:8069/dataset/1:




6
Imagine profil
Abandonează
Imagine profil
Jake Robinson
Cel mai bun răspuns

Taking a look at how other controllers in Odoo work is the easiest way to understand how to set one up.

URL routing is based on Werkzeug Route Expressions. This means you can use angled brackets to add variables to the url, eg. '/dataset/<string:tracking_number>'. This will be passed into your controller function by name, so make sure you include tracking_number as a parameter.

-2
Imagine profil
Abandonează
Enjoying the discussion? Don't just read, join in!

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

Înscrie-te
Related Posts Răspunsuri Vizualizări Activitate
How to redirect from one controller to another in the website of odoo 10?
redirect controller odoo10
Imagine profil
Imagine profil
Imagine profil
Imagine profil
3
iun. 24
24743
Create schedule action For sending emails
odoo10
Imagine profil
Imagine profil
Imagine profil
2
iul. 25
6399
How to send messages that are not shown in chatter? Rezolvat
odoo10
Imagine profil
Imagine profil
Imagine profil
2
oct. 25
8769
How to ORDER BY? [Odoo 10] Rezolvat
odoo10
Imagine profil
Imagine profil
2
nov. 24
29659
Dynamic domain functionality - possible to change domain of a field in another model with onchange? (Odoo 10) Rezolvat
odoo10
Imagine profil
Imagine profil
Imagine profil
2
mai 24
8356
Comunitate
  • Tutorials
  • Documentație
  • Forum
Open Source
  • Descărcare
  • Github
  • Runbot
  • Translations
Servicii
  • Hosting Odoo.sh
  • Suport
  • Actualizare
  • Custom Developments
  • Educație
  • Găsiți un contabil
  • Găsește un Partener
  • Devino Partener
Despre Noi
  • Compania noastră
  • Active de marcă
  • Contactați-ne
  • Locuri de muncă
  • Evenimente
  • Podcast
  • Blog
  • Clienți
  • Aspecte juridice • Confidențialitate
  • Securitate
الْعَرَبيّة 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 este o suită de aplicații de afaceri open source care acoperă toate nevoile companiei dvs.: CRM, comerț electronic, contabilitate, inventar, punct de vânzare, management de proiect etc.

Propunerea de valoare unică a Odoo este să fie în același timp foarte ușor de utilizat și complet integrat.

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