Skip to Content
Odoo Menu
  • Prijavi
  • Try it free
  • Aplikacije
    Finance
    • Knjigovodstvo
    • Obračun
    • Stroški
    • Spreadsheet (BI)
    • Dokumenti
    • Podpisovanje
    Prodaja
    • CRM
    • Prodaja
    • POS Shop
    • POS Restaurant
    • Naročnine
    • Najem
    Spletne strani
    • Website Builder
    • Spletna trgovina
    • Blog
    • Forum
    • Pogovor v živo
    • eUčenje
    Dobavna veriga
    • Zaloga
    • Proizvodnja
    • PLM
    • Nabava
    • Vzdrževanje
    • Kakovost
    Kadri
    • Kadri
    • Kadrovanje
    • Odsotnost
    • Ocenjevanja
    • Priporočila
    • Vozni park
    Marketing
    • Družbeno Trženje
    • Email Marketing
    • SMS Marketing
    • Dogodki
    • Avtomatizacija trženja
    • Ankete
    Storitve
    • Projekt
    • Časovnice
    • Storitve na terenu
    • Služba za pomoč
    • Načrtovanje
    • Termini
    Produktivnost
    • Razprave
    • Odobritve
    • IoT
    • Voip
    • Znanje
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industrije
    Trgovina na drobno
    • Book Store
    • Trgovina z oblačili
    • Trgovina s pohištvom
    • Grocery Store
    • Trgovina s strojno opremo računalnikov
    • Trgovina z igračami
    Food & Hospitality
    • Bar and Pub
    • Restavracija
    • Hitra hrana
    • Guest House
    • Beverage Distributor
    • Hotel
    Nepremičnine
    • Real Estate Agency
    • Arhitekturno podjetje
    • Gradbeništvo
    • Estate Management
    • Vrtnarjenje
    • Združenje lastnikov nepremičnin
    Svetovanje
    • Računovodsko podjetje
    • Odoo Partner
    • Marketinška agencija
    • Law firm
    • Pridobivanje talentov
    • Audit & Certification
    Proizvodnja
    • Tekstil
    • Metal
    • Pohištvo
    • Hrana
    • Brewery
    • Poslovna darila
    Health & Fitness
    • Športni klub
    • Trgovina z očali
    • Fitnes center
    • Wellness Practitioners
    • Lekarna
    • Frizerski salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Sistemi sončne energije
    • Izdelovalec čevljev
    • Čistilne storitve
    • HVAC Services
    Ostali
    • Neprofitna organizacija
    • Agencija za okolje
    • Najem oglasnih panojev
    • Fotografija
    • Najem koles
    • Prodajalec programske opreme
    Browse all Industries
  • Skupnost
    Learn
    • Tutorials
    • Dokumentacija
    • Certifikati
    • Šolanje
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Prenesi
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Dogodki
    • Prevodi
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Sklici kupca
    • Podpora
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Določanje cen
  • Pomoč

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

  • CRM
  • e-Commerce
  • Knjigovodstvo
  • Zaloga
  • PoS
  • Projekt
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Ključne besede (View all)
odoo accounting v14 pos v15
About this forum
Pomoč

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

Naroči se

Get notified when there's activity on this post

This question has been flagged
domainmany2manydomain_filter
1 Odgovori
3981 Prikazi
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
Opusti
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
Opusti
Paul Brown
Avtor

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!

Prijavi
Related Posts Odgovori Prikazi Aktivnost
Filter many2many
domain many2many domain_filter
Avatar
0
jun. 17
4708
[v14] How do I use Many2many fields on Domain Filtering? Solved
domain many2many domain_filter v14
Avatar
Avatar
1
jul. 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
jun. 22
8128
Community
  • Tutorials
  • Dokumentacija
  • Forum
Open Source
  • Prenesi
  • Github
  • Runbot
  • Prevodi
Services
  • Odoo.sh Hosting
  • Podpora
  • Nadgradnja
  • Custom Developments
  • Izobraževanje
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Sredstva blagovne znamke
  • Kontakt
  • Zaposlitve
  • Dogodki
  • Podcast
  • Blog
  • Stranke
  • Pravno • Zasebnost
  • Varnost
الْعَرَبيّة 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 is a suite of open source business apps that cover all your company needs: CRM, eCommerce, accounting, inventory, point of sale, project management, etc.

Odoo's unique value proposition is to be at the same time very easy to use and fully integrated.

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