Skip ke Konten
Odoo Menu
  • Login
  • Uji coba gratis
  • Aplikasi
    Keuangan
    • Akuntansi
    • Faktur
    • Pengeluaran
    • Spreadsheet (BI)
    • Dokumen
    • Tanda Tangan
    Sales
    • CRM
    • Sales
    • POS Toko
    • POS Restoran
    • Langganan
    • Rental
    Website
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Rantai Pasokan
    • Inventaris
    • Manufaktur
    • PLM
    • Purchase
    • Maintenance
    • Kualitas
    Sumber Daya Manusia
    • Karyawan
    • Rekrutmen
    • Cuti
    • Appraisal
    • Referensi
    • Armada
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Acara
    • Otomatisasi Marketing
    • Survei
    Layanan
    • Project
    • Timesheet
    • Layanan Lapangan
    • Meja Bantuan
    • Planning
    • Appointment
    Produktivitas
    • Diskusi
    • Approval
    • IoT
    • VoIP
    • Pengetahuan
    • WhatsApp
    Aplikasi pihak ketiga Odoo Studio Platform Odoo Cloud
  • Industri-Industri
    Retail
    • Toko Buku
    • Toko Baju
    • Toko Furnitur
    • Toko Kelontong
    • Toko Hardware
    • Toko Mainan
    Makanan & Hospitality
    • Bar dan Pub
    • Restoran
    • Fast Food
    • Rumah Tamu
    • Distributor Minuman
    • Hotel
    Real Estate
    • Agensi Real Estate
    • Firma Arsitektur
    • Konstruksi
    • Estate Management
    • Perkebunan
    • Asosiasi Pemilik Properti
    Konsultansi
    • Firma Akuntansi
    • Mitra Odoo
    • Agensi Marketing
    • Firma huku
    • Talent Acquisition
    • Audit & Sertifikasi
    Manufaktur
    • Tekstil
    • Logam
    • Perabotan
    • Makanan
    • Brewery
    • Corporate Gift
    Kesehatan & Fitness
    • Sports Club
    • Toko Kacamata
    • Fitness Center
    • Wellness Practitioners
    • Farmasi
    • Salon Rambut
    Perdagangan
    • Handyman
    • IT Hardware & Support
    • Sistem-Sistem Energi Surya
    • Pembuat Sepatu
    • Cleaning Service
    • Layanan HVAC
    Lainnya
    • Organisasi Nirlaba
    • Agen Lingkungan
    • Rental Billboard
    • Fotografi
    • Penyewaan Sepeda
    • Reseller Software
    Browse semua Industri
  • Komunitas
    Belajar
    • Tutorial-tutorial
    • Dokumentasi
    • Sertifikasi
    • Pelatihan
    • Blog
    • Podcast
    Empower Education
    • Program Edukasi
    • Game Bisnis 'Scale Up!'
    • Kunjungi Odoo
    Dapatkan Softwarenya
    • Download
    • Bandingkan Edisi
    • Daftar Rilis
    Kolaborasi
    • Github
    • Forum
    • Acara
    • Terjemahan
    • Menjadi Partner
    • Layanan untuk Partner
    • Daftarkan perusahaan Akuntansi Anda.
    Dapatkan Layanan
    • Temukan Mitra
    • Temukan Akuntan
    • Temui penasihat
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan

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

  • CRM
  • e-Commerce
  • Akuntansi
  • Inventaris
  • PoS
  • Project
  • MRP
All apps
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Anda harus terdaftar untuk dapat berinteraksi di komunitas.
Semua Post Orang Lencana-Lencana
Label (Lihat semua)
odoo accounting v14 pos v15
Mengenai forum ini
Help

Using base_external_dbsource in Custom Module.

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
sqlcustommodule
2 Replies
6341 Tampilan
Avatar
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
Avatar
Buang
Bertus Kruger

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

Avatar
Heiko Groeneweg
Jawaban Terbai

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
Avatar
Buang
Avatar
Kelvin Maina
Jawaban Terbai

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

0
Avatar
Buang
Menikmati diskusi? Jangan hanya membaca, ikuti!

Buat akun sekarang untuk menikmati fitur eksklufi dan agar terlibat dengan komunitas kami!

Daftar
Post Terkait Replies Tampilan Aktivitas
Usage Of SQl Queries In odoo
sql
Avatar
Avatar
1
Nov 22
7469
sql constraints aren't being detected in my model
sql
Avatar
Avatar
1
Okt 21
4316
[odoo12]How to update data inside a custom module Diselesaikan
update sql custommodule odoo12
Avatar
Avatar
2
Jul 20
4521
Odoo on microsoft sql server instead postgres sql?
sql
Avatar
2
Nov 18
11038
Openerp with MS-SQL
sql
Avatar
Avatar
Avatar
Avatar
4
Mar 15
6108
Komunitas
  • Tutorial-tutorial
  • Dokumentasi
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Terjemahan
Layanan
  • Odoo.sh Hosting
  • Bantuan
  • Peningkatan
  • Custom Development
  • Pendidikan
  • Temukan Akuntan
  • Temukan Mitra
  • Menjadi Partner
Tentang Kami
  • Perusahaan kami
  • Aset Merek
  • Hubungi kami
  • Tugas
  • Acara
  • Podcast
  • Blog
  • Pelanggan
  • Hukum • Privasi
  • Keamanan
الْعَرَبيّة 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 adalah rangkaian aplikasi bisnis open source yang mencakup semua kebutuhan perusahaan Anda: CRM, eCommerce, akuntansi, inventaris, point of sale, manajemen project, dan seterusnya.

Mudah digunakan dan terintegrasi penuh pada saat yang sama adalah value proposition unik Odoo.

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