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
    • Discuss
    • 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
    • Manajemen Properti
    • 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
    • Tanya ahli
    • Layanan Implementasi
    • Referensi Pelanggan
    • Bantuan
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dapatkan demo
  • Harga
  • Bantuan
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

write() method not working

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
development
2 Replies
4770 Tampilan
Avatar
Alfredo Fabián Altamirano Tena

Hello, 

I have been struggling the past couple of days with a method on an inherited model that tries to sync data with an external API. Everything seems ok to me, but self.write() doesn't sends the updated data to the database.

Can someone tell what am I doing wrong?


Here is a simplified version of my code:


class ResPartner(models.Model):
"""Customer"""

_inherit = "res.partner"

external_id = fields.Char()

    def sync_with_external(self):
        api_key = self.env["ir.config_parameter"].get_param("custom_account_invoicing.external_api_key")

        data = {
            "legal_name": self.name,
            "tax_id": self.vat
        }

        api = ExternalApi(api_key)
        res = api.customers.create(data)

        self.write({"external_id": res["id"]})



0
Avatar
Buang
Manish Bohra

Hello,
I think you need to change the field name.

Reason: Odoo already external id field in import and export data.
Thanks.

Alfredo Fabián Altamirano Tena
Penulis

Already tried another field name, but same results

Avatar
Alfredo Fabián Altamirano Tena
Penulis Jawaban Terbai

After further analysis, I noticed that Postgres was receiving a ROLLBACK query every time the sync_with_external method was being called. So the problem wasn´t the write() method.

Finally the culprit was a line of code at the end of the custom method:

raise exceptions.Warning(_("Customer synced successfully"))

I thought raising a Warning was innocent enough to be used just to display a success message to the user. Little I knew this was going to cost me several days of rethinking my life choices and almost falling into insanity.

I hope this helps anyone that may fall into this same issue.

0
Avatar
Buang
Avatar
Jort de Vreeze
Jawaban Terbai

Why don't you use

self.external_id = res['id']

Instead of 

self.write({"external_id": res["id"]})

Are you also certain that the method sync_with_external is being executed and that res['id'] is not None. I hope this helps.

0
Avatar
Buang
Alfredo Fabián Altamirano Tena
Penulis

1. Using self.external_id = res['id'] does change the instance property value. Even I tested it using odoo shell. But in the database doesn't the field remains empty.

2. The method is manually executed by a button in the form view.

Thanks

Jort de Vreeze

But what does print(res['id']) output? If the API doesn't return anything it can't be saved.

Did you do a module upgrade/odoo restart?

Alfredo Fabián Altamirano Tena
Penulis

Oh sorry, res["id"] returns the correct value every time.
Also I did a module upgrade, odoo restart, even a database wipeout and fresh install, testing it out on docker container instead of the repo build. And all have the same results.

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
[((Spirit Airlines Escalation~Guide))] How do I file a dispute with Spirit Airlines?
development
Avatar
0
Apr 26
1
How to add a text over an image in my website.
development
Avatar
0
Apr 26
5
1. What is the human digestive system?
development
Avatar
0
Apr 26
9
Prices tax excluded and included ?
development
Avatar
0
Apr 26
2
What is the difference between a list and a tuple in Python? Explain with examples.
development
Avatar
0
Apr 26
10
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
  • Karir
  • 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 Svenska ภาษาไทย 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