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
    • 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

Hierarchy relationship

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
v14
5214 Tampilan
Avatar
Răzvan Anastasescu

I have extended Sale Order Line with parent / child hierarchy relationship because some lines (children) can be connected to others (parent) in the same Sale Order

class SaleOrderLine(models.Model):
_inherit = 'sale.order.line'
  _parent_name = 'my_parent_id'

my_parent_id = fields.Many2one('sale.order.line', 'Operation for', index=True, domain='[("my_parent_id", "=", False)]', ondelete='cascade')

my_children_ids = fields.One2many('sale.order.line', 'my_parent_id', 'Operations')

I am presenting children records differently in the view (different row color, disabled re-sequennce, and so on) based on the `my_parent_id` field (and I am also dealing with re-sequencing of the children together with the parent and all the rest) which is working fine

The problem I have is that I don't know how to properly add a new parent line with couple of children records on changing some field of an existing line (in the same Sale Order)

Meaning that if I change the quantity of one line, based on some conditions of course, I need to add another parent line with couple of children lines.

There are actually two problems, combined (examples of code below):

  1. Where exactly to put the code ?

    1. Most logical place would be in `sale_order_line.onchange('product_uom_qty')`
      But here I couldn't add even the single parent line using `self.new()` (it's just not showing up) although I'm on the same model, and using `self.create()` it's working but the new records do not show up until the user saves the Sale Order or just refresh / reloads it (as the records have been created into the DB using create() method)

    2. I did try also on `sale_order.onchange('order_line')`
      Here it's working to add the lines even with `new()` but the problem is that the parent / child relationship it's not held

  2. What method to use ?

    1. `sale_order_line.new()` - I would have preferred not to have the records saved into DB directly (in order to allow user to discard the change) but at least one method to work would be nice ... but this is not keeping the parent / child relationship
      Although if using debugger on the moment they're added, the connection between them seems fine using the NewIDs but as soon as the transaction finishes (I don't know which other code it's executing after my function) the relation drops (on next debug the relationship fields are empty)

    2. `sale_order_line.create()` - this seems to work, adding first the parent line and then connecting each child with the parent record ID, but the records do not show up in the view until user saves the Sale Order or simply refreshes / reloads the page

    3. `sale_order.update({'order_line': [(0, 0, {'product_id': parent, 'my_children_ids': [(0, 0, child products ...)]})` same issues as above


Code examples:

1. using `sale_order_line.new()` inside `sale_order_line._onchange_product_uom_qty()` method

not working at all, even for the single parent line, it doesn't show up ...

# in my SaleOrderLine extension class
@api.onchange('product_uom_qty')
def _onchange_product_uom_qty(self):
new_parent_line = self.new({
'order_id': rec.order_id.id,
'product_id': 10,
# I'm adding all the other required fields just to be sure ...
'name': 'Test parent',
'price_unit': 10,
'product_uom_qty': 1,
})


2. using `sale_order_line.create()` inside `sale_order_line._onchange_product_uom_qty()` method

it's working, even adding child lines correctly, but:

  •  they are not visible to the user until Sale Order get's saved manually by the user (which does some kind of refresh afterwards) or entire page reloaded (as the records are already saved in the DB)
    Is there a method to save the Sale Order from code and automatically show the new records created ?

  • it would have been nice to be able to use the discard functionality (like new()) - but anyway, at least one decent way to achieve what I need would be nice though (correct parent / child relationship and displayed to the user after the change ...)

# in my SaleOrderLine extension class
@api.onchange('product_uom_qty')
def _onchange_product_uom_qty(self):
new_parent_line = self.create({
# I need to use the _origin to take order integer ID instead of the NewID format in order to work correctly ...
'order_id': rec._origin.order_id.id,
'product_id': 10,
# I'm adding all the other required fields just to be sure ...
'name': 'Test parent',
'price_unit': 10,
'product_uom_qty': 1,
# this doesn't work to automatically create children records too ...
# 'my_children_ids': [
# (0, 0, {child 1 values ...}),
# (0, 0, {child 2 values ...}),
# ],
})

new_child_1_line = self.create({
'my_parent_id': new_parent_line.id,
# other child 1 values ...
})


3. using `sale_order.order_line.new()` from `sale_order._onchange_order_line()`

The records show up, but the parent / child relation it's not kept

Actually debugging the code during execution which adds them, the relationship seems fine (based on the NewIDs), but as soon as the code ends (and whatever the framework does afterwards) it seems that is broken

I've debugged again and for those records the link fields (parent / child) are empty

 

# in my SaleOrder extension class
@api.onchange('order_line')
def _onchange_order_line(self):
new_parent_line = self.order_line.new({
'order_id': self.id,
'product_id': 10,
# I'm adding all the other required fields just to be sure ...
'name': 'Test parent',
'price_unit': 10,
'product_uom_qty': 1,
   'my_children_ids': [
(0, 0, {child 1 values ...}),
(0, 0, {child 2 values ...}),
]
})


4. using `sale_order.update({'order_line': [(0, 0, {parent values ...}]})` from `sale_order._omchange_order_line()`

the same like point above, they appear but without parent / child relation

# in my SaleOrder extension class
@api.onchange('order_line')
def _onchange_order_line(self):
self.update({
'order_line': [(0, 0, {
'order_id': self.id,
'product_id': 10,
# I'm adding all the other required fields just to be sure ...
'name': 'Test parent',
'price_unit': 10,
'product_uom_qty': 1,
    'my_children_ids': [
(0, 0, {child 1 values ...}),
(0, 0, {child 2 values ...}),
]
})]
})


Are there any other ways to achieve what I need ?

Thx,

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
Attached PDF file is not formatted properly
v14
Avatar
Avatar
1
Des 25
404
Odoo14 alternative for Automated Translations through Gengo API module
v14
Avatar
Avatar
Avatar
Avatar
3
Sep 25
3828
Odoo Community v14 Slow on High-End Servers, Fast on i5/i7 PCs
v14
Avatar
0
Agu 25
1223
How to Managing Birthdate and Age in Odoo
v14
Avatar
Avatar
1
Agu 25
3629
Update Initial Stock of Product using XMLRPC API [Odoo14] Diselesaikan
v14
Avatar
Avatar
Avatar
2
Jul 25
9253
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