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
    • Magazin de îmbrăcăminte
    • Magazin de Mobilă
    • Magazin alimentar
    • Magazin de materiale de construcții
    • Magazin de jucării
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Distribuitor de băuturi
    • Hotel
    Proprietate imobiliara
    • Real Estate Agency
    • Firmă de Arhitectură
    • Construcție
    • Estate Managament
    • Grădinărit
    • Asociația Proprietarilor de Proprietăți
    Consultanta
    • Firma de Contabilitate
    • Partener Odoo
    • Agenție de marketing
    • Law firm
    • Atragere de talente
    • Audit & Certification
    Producție
    • Textil
    • Metal
    • Mobilier
    • Mâncare
    • Brewery
    • Cadouri corporate
    Health & Fitness
    • Club Sportiv
    • Magazin de ochelari
    • Centru de Fitness
    • Wellness Practitioners
    • Farmacie
    • Salon de coafură
    Trades
    • Handyman
    • IT Hardware and Support
    • Asigurare socială de stat
    • Cizmar
    • Servicii de curățenie
    • HVAC Services
    Altele
    • Organizație nonprofit
    • Agenție de Mediu
    • Închiriere panouri publicitare
    • Fotografie
    • Închiriere biciclete
    • Asigurare socială
    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

Using base_external_dbsource in Custom Module.

Abonare

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

Această întrebare a fost marcată
sqlcustommodule
2 Răspunsuri
6335 Vizualizări
Imagine profil
Swinburne

What I am trying to do: use the base_external_dbsource to gain access to an MS SQL Server database, and query some information to add new records into an odoo model.

What I have done: I have an odoo installation in which I have used the base_external_datasource (odbc) to successfully connect to my ODBC database, and I have set up an odoo model to put the data into.

What I am stuck on: It is not clear how to retrieve information from the connected ODBC datasource using Odoo.

Note: I am happy to develop a module to do this if required, but it is still not clear to me how I could retrieve data using the base_external_dbsource ODBC connection I have set up from within a custom module.

Online documentation for 

base_external_dbsource only describes how to obtain a connection to your database and not how to utilize this connection. Many similar forum posts about base_external_dbsource have been left unanswered.

Thanks :)

1
Imagine profil
Abandonează
Bertus Kruger

I agree an example would be nice. I would love to have a SQL query that gets turned into a readonly model.

Imagine profil
Heiko Groeneweg
Cel mai bun răspuns

Not sure if this is best pratice to use it but at least it works for me.

Model:

from odoo import models, fields, api
from odoo.addons.base_external_dbsource_odbc.models.base_external_dbsource import BaseExternalDbsource


class wws_dai_extension(models.TransientModel):
    _name = 'my_test_model'
    _description = 'my_test_model'

    name = fields.Char()
    description = fields.Char()

    def get_odbc_data(self):
        vals = {}
        self.dbsource = self.env['base.external.dbsource'].search([('name', '=', 'test')], limit=1)

        conn = BaseExternalDbsource.connection_open_pyodbc(self.dbsource)

        query = 'select myfield1, myfield2 from schema.mytable'

        cursor = conn.execute(query)
        
        self.env['my_test_model'].search([]).unlink()
        for row in cursor.fetchall() or []:
            vals['name'] = row[0]
            vals['description'] = row[1]
            self.create(vals)

        BaseExternalDbsource.connection_close_pyodbc(self, conn)
        action_vals =  {'name': 'Transient Model from external datasource',
            'type': 'ir.actions.act_window',
            'view_mode': 'tree',
            'res_model': 'my_test_model',
        }
        return action_vals
       

View:
<record model="ir.actions.server" id="my_test_model.action_server">
      <field name="name">my_test_model server</field>
      <field name="model_id" ref="model_my_test_model"/>
      <field name="type">ir.actions.server</field>
      <field name="state">code</field>
      <field name="code">action = model.get_odbc_data()</field>
    </record>

1
Imagine profil
Abandonează
Imagine profil
Kelvin Maina
Cel mai bun răspuns

Been looking for the best example as well ...most of them seems like you're building a new model

0
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
Usage Of SQl Queries In odoo
sql
Imagine profil
Imagine profil
1
nov. 22
7465
sql constraints aren't being detected in my model
sql
Imagine profil
Imagine profil
1
oct. 21
4314
[odoo12]How to update data inside a custom module Rezolvat
update sql custommodule odoo12
Imagine profil
Imagine profil
2
iul. 20
4519
Odoo on microsoft sql server instead postgres sql?
sql
Imagine profil
2
nov. 18
11036
Openerp with MS-SQL
sql
Imagine profil
Imagine profil
Imagine profil
Imagine profil
4
mar. 15
6106
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