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

How to domain filter equipment that is not already being used for an event on the same date.

Langganan

Dapatkan notifikasi saat terdapat aktivitas pada post ini

Pertanyaan ini telah diberikan tanda
domainmany2manydomain_filter
1 Balas
3987 Tampilan
Avatar
Paul Brown

I am running Odoo 12.0-20201125 (Community Edition) and developing, if possible, using the developer mode in the web interface. I don't mind getting into the back-end if this problem needs it, though.

I have the following behaviour: any number of pieces of equipment (maintenance.equipment) can be assigned to any number of event records (event.event) accomplished using a many2many field.

What I would like is to be able to filter pieces of equipment to only show those not already in use on the same date as the current record (based on event start date). That is, if I have 'equipment1' and 'equipment2' already assigned to 'event1' that starts of 05/12/2020 I could not then assign 'equipment1' or 'equipment2' to 'event2' that also starts on 05/12/2020 (but I could assign 'equipment3' to 'event2', say).

To try and accomplish this, I set up another many2many field in Equipment that would show the Events to which that piece of equipment was assigned. I then accessed this field using a domain filter on the Event form view in the hope of saying 'if any of the start dates in this list of events match the start date of this Event record, filter out this piece of equipment'. I got close to the exact opposite of the desired behaviour by doing (in the Event form view):

<field name="x_equipment" widget="many2many_tags" domain="[('x_equipment_event_ids.date_begin', '=', date_begin)]"/>

this filters the field to show me only equipment that is already being used for an event with the same start date. To generate the logical opposite, I tried to filter for 'not equal to' -- like:  domain="[('x_equipment_event_ids.date_begin', '!=', date_begin)]" -- but that let through any equipment already assigned on any date. I have since tried every combination of logic I can find having scoured previous forum posts and the documentation on domain filters. (Putting '!' at the start of the expression, using 'like', 'ilike', 'not like', 'not ilike', 'in', 'not in'.)

It may be that I am missing a more obvious way to accomplish this or that I need to get into the back-end to manage it. Either way, I'd be most grateful for a solution or any help anyone can provide.

0
Avatar
Buang
Avatar
Jack Dane
Jawaban Terbai

Hello Paul, 

I do believe you have to go into the backend, I have completed code which I have tested on a version 13 Odoo database. 

It changes the domain based on the date on an "onchange" event. The code will change the domain based on what is returned from the database and match ids. 

Here is the code:

class OdooHelp(models.Model):

    _inherit = "crm.lead"


    datetime_used = fields.Date()

    equipment_used = fields.Many2many(comodel_name="equipment")


    @api.onchange("datetime_used")

    def change_equipment_filter(self):

        return {"domain": {"equipment_used": [("id", "in", self.equipment_not_being_used())]}}


    def equipment_not_being_used(self):

        return self.env["equipment"].search(["|", ("crm_events.datetime_used", "!=", self.datetime_used), ("crm_events", "=", False)]).mapped("id")



class Equipment(models.Model):

    _name = "equipment"


    name = fields.Char()

    crm_events = fields.Many2many(comodel_name="crm.lead")


Could you give this a try, I would also see if anyone can figure out a way to do this purely in the views as this is an interesting question. 

Thanks,

1
Avatar
Buang
Paul Brown
Penulis

Hi Jack,

Thanks so much -- this code does look like it will accomplish exactly what I need.

I should, however, have been more explicit about my competence in the back-end: I've been using Odoo for a couple of years but have managed all my customisation using the developer mode in the web interface, just for ease. This is the first time I'll need to edit the back-end. When I was starting with Odoo I worked my way through about a third of this textbook (https://www.packtpub.com/product/odoo-12-development-essentials-fourth-edition/9781789532470) so I have a rough steer on what I need to do. I'm comfortable with Python too. This is a roundabout way of saying that I can't just bang your code into my test database and check it: I've got to remind myself of how to extend existing models and create a new one -- it'll probably take me the best part of a week to get up to speed and report back.

Sorry to keep you hanging and thanks again!

Jack Dane

Hi Paul,

Glad to hear it.

If you get stuck, send me an email and I'll be more than happy help.

Thanks,

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
Filter many2many
domain many2many domain_filter
Avatar
0
Jun 17
4713
[v14] How do I use Many2many fields on Domain Filtering? Diselesaikan
domain many2many domain_filter v14
Avatar
Avatar
1
Jul 22
7020
Condition Drop Down Items
domain domain_filter
Avatar
0
Feb 25
18
Many2many domain works when click search more but wrong values in dropdown
domain many2many
Avatar
0
Nov 22
80
[SOLVED] Create rule using many2many - how to? Diselesaikan
domain many2many
Avatar
1
Jun 22
8132
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