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

Odoo 14: Inherit python method is not working.

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
stockfunctioninheritancesuperdef
1 Balas
5552 Tampilan
Avatar
Muhammad Faheem Khan

I am trying to inherit a method in stock.inventory.line. My issue is, when this method is called from write method, it is working fine (inherited function work), but if I call it from create method, the original function is being used and my inherited function is being ignored.

Original method:

def _check_no_duplicate_line(self):
domain = [
('product_id', 'in', self.product_id.ids),
('location_id', 'in', self.location_id.ids),
'|', ('partner_id', 'in', self.partner_id.ids), ('partner_id', '=', None),
'|', ('package_id', 'in', self.package_id.ids), ('package_id', '=', None),
'|', ('prod_lot_id', 'in', self.prod_lot_id.ids), ('prod_lot_id', '=', None),
'|', ('inventory_id', 'in', self.inventory_id.ids), ('inventory_id', '=', None),
]
groupby_fields = ['product_id', 'location_id', 'partner_id', 'package_id', 'prod_lot_id', 'inventory_id']
lines_count = {}
for group in self.read_group(domain, ['product_id'], groupby_fields, lazy=False):
key = tuple([group[field] and group[field][0] for field in groupby_fields])
lines_count[key] = group['__count']
for line in self:
key = (line.product_id.id, line.location_id.id, line.partner_id.id, line.package_id.id, line.prod_lot_id.id, line.inventory_id.id)
if lines_count[key] > 1:
raise UserError(_("There is already one inventory adjustment line for this product,"
" you should rather modify this one instead of creating a new one."))


Inherited method:


    def _check_no_duplicate_line(self):
res = super(InventoryLine, self)._check_no_duplicate_line()
print('duplicate line called')
_logger.debug('duplicate line verifeid')
# active_id = self.env.context.get('active_id')
# print(active_id)
invent = self.inventory_id.my_custom_field
print(invent)
if invent:
print('in duplicate tag id fond')
return
else:
print('no id found')
return res

write method:

def write(self, vals):
res = super(InventoryLine, self).write(vals)
self._check_no_duplicate_line()
return res

create method:

@api.model_create_multi
def create(self, vals_list):
some code here. . .

res = super(InventoryLine, self).create(vals_list)
res._check_no_duplicate_line()
return res

What could be the reason? Any help will be greatly appreciated.

0
Avatar
Buang
Avatar
Ibrahim Boudmir
Jawaban Terbai

Hi, 

I'm commenting your code generally speaking: 

1- In create function, you're calling bulk create.Therefore, You may have a recordset that's been created. so, you need to loop inside your method.

Using return inside of a loop will break it and exit the function even if the loop is still not finished.

Can you try this instead: 

def _check_no_duplicate_line(self):
    for line in self:
        if not line.inventory_id.my_custom_field:
            super(InventoryLine, line)._check_no_duplicate_line()

Add prints or pdb debug to check.

You can write back for further analysis.
Regards.

1
Avatar
Buang
Muhammad Faheem Khan
Penulis

Thank you for your response.
I tried what you suggested.
I added _logger.debug('called successfully') in your proposed code (loop)
when I called it from write function, I am getting log in terminal "called successfully"
but when I call it for create, I am not even getting this log, but I am getting error in original method. It is really upsetting me.

Ibrahim Boudmir

can you debug code using pdb package and put it (import pdb; pdb.set_trace() ) just after calling super of create function please?

Then print res and click on "s" in order to get into your method...etc
this is how we're going to understand what's happening.
more at: https://docs.python.org/3/library/pdb.html#pdbcommand-next
--------------------------
If all this is "useless", i suggest you use monkey patch : targetting your method in import section, declare all the method and then replace the native with yours.

Muhammad Faheem Khan
Penulis

Thank you very much for pointing me the right direction. I don't know what is the issue, but I just tested my custom module on another installation after applying your proposed solution (loop), and it worked fine. I did several tests there. It is working fine, but in old installation, it is still the same. Anyway, +100 for you. I will test it with pdb and post results here later from my effected installation.

Ibrahim Boudmir

Thank you

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
Inherit python function
function python inheritance class super
Avatar
Avatar
Avatar
2
Mei 25
2082
Python "super" - function does not work Diselesaikan
python inheritance super
Avatar
Avatar
Avatar
2
Des 22
13569
Add/Override parent compute method (event.booth) Odoo15 Diselesaikan
inheritance super v15
Avatar
Avatar
1
Des 22
4946
Problems overriding the same function from two different modules
function inheritance override
Avatar
0
Jan 17
5536
Execution order on inherited functions
function python inheritance
Avatar
0
Jul 25
5897
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