Přejít na obsah
Odoo Menu
  • Přihlásit se
  • Vyzkoušejte zdarma
  • Aplikace
    Finance
    • Účetnictví
    • Fakturace
    • Výdaje
    • Spreadsheet (BI)
    • Dokumenty
    • Podpisy
    Prodej
    • CRM
    • Prodej
    • POS Obchod
    • POS Restaurace
    • Předplatné
    • Pronájem
    Webové stránky
    • Webové stránky
    • E-shop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Dodavatelský řetězec
    • Sklad
    • Výroba
    • PLM
    • Nákup
    • Údržba
    • Kvalita
    Lidské zdroje
    • Zaměstnanci
    • Nábor
    • Volno
    • Hodnocení zaměstnanců
    • Doporučení
    • Vozový park
    Marketing
    • Marketing sociálních sítí
    • Emailový marketing
    • SMS Marketing
    • Události
    • Marketingová automatizace
    • Dotazníky
    Služby
    • Projekt
    • Časové výkazy
    • Práce v terénu
    • Helpdesk
    • Plánování
    • Schůzky
    Produktivita
    • Diskuze
    • Schvalování
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Aplikace třetích stran Odoo Studio Odoo cloudová platforma
  • Branže
    Maloobchod
    • Knihkupectví
    • Obchod s oblečením
    • Obchod s nábytkem
    • Potraviny
    • Obchod s hardwarem
    • Hračkářství
    Jídlo a pohostinství
    • Bar a Pub
    • Restaurace
    • Fast Food
    • Penzion
    • Distributor nápojů
    • Hotel
    Nemovitost
    • Realitní kancelář
    • Architektonická firma
    • Stavba
    • Správa nemovitostí
    • Zahradnictví
    • Asociace vlastníků nemovitosti
    Poradenství
    • Účetní firma
    • Odoo Partner
    • Marketingová agentura
    • Právník
    • Akvizice talentů
    • Audit a certifikace
    Výroba
    • Textile
    • Kov
    • Nábytek
    • Jídlo
    • Brewery
    • Korporátní dárky
    Zdraví a fitness
    • Sportovní klub
    • Prodejna brýli
    • Fitness Centrum
    • Wellness praktikové
    • Lékárna
    • Kadeřnictví
    Transakce
    • Údržbář
    • IT hardware a podpora
    • Systémy solární energie
    • Výrobce obuvi
    • Úklidové služby
    • Služby HVAC
    Ostatní
    • Nezisková organizace
    • Agentura pro životní prostředí
    • Pronájem billboardů
    • Fotografování
    • Leasing jízdních kol
    • Prodejce softwaru
    Browse all Industries
  • Komunita
    Edukační program
    • Tutoriály
    • Dokumentace
    • Certifikace
    • Vzdělávání
    • Blog
    • Podcast
    Podpora vzdělávání
    • Vzdělávací program
    • Scale Up! Hra na firmu
    • Navštivte Odoo
    Získat software
    • Stáhnout
    • Porovnejte edice
    • Verze
    Spolupráce
    • Github
    • Fórum
    • Události
    • Překlady
    • Stát se partnerem
    • Services for Partners
    • Registrujte svou účetní firmu
    Získat služby
    • Najít partnera
    • Najít účetní
    • Setkejte se s poradcem
    • Implementační služby
    • Zákaznické reference
    • Podpora
    • Upgrady
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Dohodnout demo
  • Ceník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účetnictví
  • Sklad
  • PoS
  • Projekty
  • MRP
All apps
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
You need to be registered to interact with the community.
All Posts Lidé Odznaky
Štítky (View all)
odoo accounting v14 pos v15
O tomto fóru
Pomoc

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

Odebírat

Get notified when there's activity on this post

This question has been flagged
domainmany2manydomain_filter
1 Odpovědět
3984 Zobrazení
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
Zrušit
Avatar
Jack Dane
Nejlepší odpověď

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
Zrušit
Paul Brown
Autor

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,

Enjoying the discussion? Don't just read, join in!

Create an account today to enjoy exclusive features and engage with our awesome community!

Přihlásit se
Related Posts Odpovědi Zobrazení Aktivita
Filter many2many
domain many2many domain_filter
Avatar
0
čvn 17
4709
[v14] How do I use Many2many fields on Domain Filtering? Vyřešeno
domain many2many domain_filter v14
Avatar
Avatar
1
čvc 22
7003
Condition Drop Down Items
domain domain_filter
Avatar
0
úno 25
18
Many2many domain works when click search more but wrong values in dropdown
domain many2many
Avatar
0
lis 22
80
[SOLVED] Create rule using many2many - how to? Vyřešeno
domain many2many
Avatar
1
čvn 22
8129
Komunita
  • Tutoriály
  • Dokumentace
  • Fórum
Open Source
  • Stáhnout
  • Github
  • Runbot
  • Překlady
Služby
  • Odoo.sh hostování
  • Podpora
  • Upgrade
  • Nestandardní vývoj
  • Edukační program
  • Najít účetní
  • Najít partnera
  • Stát se partnerem
O nás
  • Naše společnost
  • Podklady značky
  • Kontakujte nás
  • Práce
  • Události
  • Podcast
  • Blog
  • Zákazníci
  • Právní dokumenty • Soukromí
  • Zabezpečení
الْعَرَبيّة 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 je balíček open-source aplikací, které pokrývají všechny potřeby vaší společnosti: CRM, e-shop, účetnictví, sklady, kasy, projektové řízení a další.

Unikátní nabídka od Odoo poskytuje velmi jednoduché uživatelské rozhraní a vše je integrované na jednom místě.

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