Skip to Content
Odoo Menu
  • Prihlásiť sa
  • Vyskúšajte zadarmo
  • Aplikácie
    Financie
    • Účtovníctvo
    • Fakturácia
    • Výdavky
    • Tabuľka (BI)
    • Dokumenty
    • Podpis
    Predaj
    • CRM
    • Predaj
    • POS Shop
    • POS Restaurant
    • Manažment odberu
    • Požičovňa
    Webstránky
    • Tvorca webstránok
    • eShop
    • Blog
    • Fórum
    • Živý chat
    • eLearning
    Supply Chain
    • Sklad
    • Výroba
    • Správa životného cyklu produktu
    • Nákup
    • Údržba
    • Manažment kvality
    Ľudské zdroje
    • Zamestnanci
    • Nábor zamestnancov
    • Voľné dni
    • Hodnotenia
    • Odporúčania
    • Vozový park
    Marketing
    • Marketing sociálnych sietí
    • Email marketing
    • SMS marketing
    • Eventy
    • Marketingová automatizácia
    • Prieskumy
    Služby
    • Projektové riadenie
    • Pracovné výkazy
    • Práca v teréne
    • Helpdesk
    • Plánovanie
    • Schôdzky
    Produktivita
    • Tímová komunikácia
    • Schvalovania
    • IoT
    • VoIP
    • Znalosti
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Priemyselné odvetvia
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Reštaurácia
    • Fast Food
    • Guest House
    • Beverage distributor
    • Hotel
    Reality
    • Real Estate Agency
    • Architecture Firm
    • Konštrukcia
    • Estate Managament
    • Gardening
    • Property Owner Association
    Poradenstvo
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Výroba
    • Textile
    • Metal
    • Furnitures
    • Jedlo
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware and Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Iní
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Komunita
    Vzdelávanie
    • Tutoriály
    • Dokumentácia
    • Certifikácie
    • Školenie
    • Blog
    • Podcast
    Empower Education
    • Vzdelávací program
    • Scale Up! Business Game
    • Visit Odoo
    Softvér
    • Stiahnuť
    • Porovnanie Community a Enterprise vierzie
    • Releases
    Spolupráca
    • Github
    • Fórum
    • Eventy
    • Preklady
    • Staň sa partnerom
    • Services for Partners
    • Register your Accounting Firm
    Služby
    • Nájdite partnera
    • Nájdite účtovníka
    • Meet an advisor
    • Implementation Services
    • Zákaznícke referencie
    • Podpora
    • Upgrades
    ​Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Získajte demo
  • Cenník
  • Pomoc

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

  • CRM
  • e-Commerce
  • Účtovníctvo
  • Sklady
  • PoS
  • Projektové riadenie
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tagy (View all)
odoo accounting v14 pos v15
About this forum
Pomoc

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

Odoberať

Get notified when there's activity on this post

This question has been flagged
domainmany2manydomain_filter
1 Odpoveď
3980 Zobrazenia
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šiť
Avatar
Jack Dane
Best Answer

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šiť
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!

Registrácia
Related Posts Replies Zobrazenia Aktivita
Filter many2many
domain many2many domain_filter
Avatar
0
jún 17
4708
[v14] How do I use Many2many fields on Domain Filtering? Solved
domain many2many domain_filter v14
Avatar
Avatar
1
júl 22
6999
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? Solved
domain many2many
Avatar
1
jún 22
8128
Komunita
  • Tutoriály
  • Dokumentácia
  • Fórum
Open Source
  • Stiahnuť
  • Github
  • Runbot
  • Preklady
Služby
  • Odoo.sh hosting
  • Podpora
  • Vyššia verzia
  • Custom Developments
  • Vzdelávanie
  • Nájdite účtovníka
  • Nájdite partnera
  • Staň sa partnerom
O nás
  • Naša spoločnosť
  • Majetok značky
  • Kontaktujte nás
  • Pracovné ponuky
  • Eventy
  • Podcast
  • Blog
  • Zákazníci
  • Právne dokumenty • Súkromie
  • Bezpečnosť
الْعَرَبيّة 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 sada podnikových aplikácií s otvoreným zdrojovým kódom, ktoré pokrývajú všetky potreby vašej spoločnosti: CRM, e-shop, účtovníctvo, skladové hospodárstvo, miesto predaja, projektový manažment atď.

Odoo prináša vysokú pridanú hodnotu v jednoduchom použití a súčasne plne integrovanými biznis aplikáciami.

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