Skip to Content
Odoo Menú
  • Registra entrada
  • Prova-ho gratis
  • Aplicacions
    Finances
    • Comptabilitat
    • Facturació
    • Despeses
    • Full de càlcul (IA)
    • Documents
    • Signatura
    Vendes
    • CRM
    • Vendes
    • Punt de venda per a botigues
    • Punt de venda per a restaurants
    • Subscripcions
    • Lloguer
    Imatges de llocs web
    • Creació de llocs web
    • Comerç electrònic
    • Blog
    • Fòrum
    • Xat en directe
    • Aprenentatge en línia
    Cadena de subministrament
    • Inventari
    • Fabricació
    • PLM
    • Compres
    • Manteniment
    • Qualitat
    Recursos humans
    • Empleats
    • Reclutament
    • Absències
    • Avaluacions
    • Recomanacions
    • Flota
    Màrqueting
    • Màrqueting Social
    • Màrqueting per correu electrònic
    • Màrqueting per SMS
    • Esdeveniments
    • Automatització del màrqueting
    • Enquestes
    Serveis
    • Projectes
    • Fulls d'hores
    • Servei de camp
    • Suport
    • Planificació
    • Cites
    Productivitat
    • Converses
    • Validacions
    • IoT
    • VoIP
    • Coneixements
    • WhatsApp
    Aplicacions de tercers Odoo Studio Plataforma d'Odoo al núvol
  • Sectors
    Comerç al detall
    • Llibreria
    • Botiga de roba
    • Botiga de mobles
    • Botiga d'ultramarins
    • Ferreteria
    • Botiga de joguines
    Food & Hospitality
    • Bar i pub
    • Restaurant
    • Menjar ràpid
    • Guest House
    • Distribuïdor de begudes
    • Hotel
    Immobiliari
    • Agència immobiliària
    • Estudi d'arquitectura
    • Construcció
    • Gestió immobiliària
    • Jardineria
    • Associació de propietaris de béns immobles
    Consultoria
    • Empresa comptable
    • Partner d'Odoo
    • Agència de màrqueting
    • Bufet d'advocats
    • Captació de talent
    • Auditoria i certificació
    Fabricació
    • Textile
    • Metal
    • Mobles
    • Menjar
    • Brewery
    • Regals corporatius
    Salut i fitness
    • Club d'esport
    • Òptica
    • Centre de fitness
    • Especialistes en benestar
    • Farmàcia
    • Perruqueria
    Trades
    • Servei de manteniment
    • Hardware i suport informàtic
    • Sistemes d'energia solar
    • Shoe Maker
    • Serveis de neteja
    • Instal·lacions HVAC
    Altres
    • Nonprofit Organization
    • Agència del medi ambient
    • Lloguer de panells publicitaris
    • Fotografia
    • Lloguer de bicicletes
    • Distribuïdors de programari
    Browse all Industries
  • Comunitat
    Aprèn
    • Tutorials
    • Documentació
    • Certificacions
    • Formació
    • Blog
    • Pòdcast
    Potenciar l'educació
    • Programa educatiu
    • Scale-Up! El joc empresarial
    • Visita Odoo
    Obtindre el programari
    • Descarregar
    • Comparar edicions
    • Novetats de les versions
    Col·laborar
    • GitHub
    • Fòrum
    • Esdeveniments
    • Traduccions
    • Converteix-te en partner
    • Services for Partners
    • Registra la teva empresa comptable
    Obtindre els serveis
    • Troba un partner
    • Troba un comptable
    • Contacta amb un expert
    • Serveis d'implementació
    • Referències del client
    • Suport
    • Actualitzacions
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Programar una demo
  • Preus
  • Ajuda

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

  • CRM
  • e-Commerce
  • Comptabilitat
  • Inventari
  • PoS
  • Projectes
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Etiquetes (View all)
odoo accounting v14 pos v15
About this forum
Ajuda

Datetime Constarints

Subscriure's

Get notified when there's activity on this post

This question has been flagged
constraintodooV8odoo8.0odoo8
4 Respostes
4845 Vistes
Avatar
Logicious

i have one problem , i have one class named as room details and second one is room booking. we can go to book a room by room booking model. I want to create a constraint to it . Problem is that if one person can book one room at one date&time if second person can book that room may be after that time or before that time.previously i askd this question , and there are some answers also i got but i cant figure it out.I cant able to find out the solution fromr that, please help me.

i will give my code


class room_management(osv.Model):

_name = 'room.management'

_columns = {

'name': fields.char('Name',requierd=True, help='Put a Name for your Room example: Interview room,board room,conference Hall...etc '),

'location':fields.char('Location',requierd=True,help="give the location as city name or street name..etc"),

'floar':fields.char('Floor Details',help='Enter the Foar no or name,like Foar 4B6 or somthing should identification'),

'address':fields.text('Address',requierd=True,help='Detailed Address'),

'no_seats':fields.integer('No of Seats',requierd=True,help='Number of seats occupied in this room'),

'room_no':fields.char('Room No',requierd=True,help='Should be unique',),

}


class room_booking(osv.Model):

_name = 'room.booking'

_columns = {

'room_id' : fields.many2one('room.management', string="Room Booking"),

'duration': fields.integer('Duration'),

'reason': fields.char('Reason',requierd=True ,help="short deatails about booking,Example:Simons Hr interview"),

'start': fields.datetime('Start At',requierd=True),

'end': fields.datetime('End At',requierd=True),

}


1
Avatar
Descartar
Avatar
Marvin Taboada
Best Answer

Hello Logicious,

This kind of constraints are applicable for creation but also for edition. If you really want to perform input validation overwriting `create` also overwrite `write` as well.

A cleaner solution to cover both cases is to create Python based constraints like the one you can see in `hr_holidays`, please see here:

* https://github.com/odoo/odoo/blob/8.0/addons/hr_holidays/hr_holidays.py#L208

* https://github.com/odoo/odoo/blob/8.0/addons/hr_holidays/hr_holidays.py#L152

Constraints are automatically invoked during creation or edition:

* https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L3949 

* https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L4273 

* https://github.com/odoo/odoo/blob/8.0/openerp/models.py#L1239 

Please also note tha Odoo 8 introduced a new way to declare constraints (and deprecated the above):

* https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.models.Model._inherits

* https://www.odoo.com/documentation/8.0/reference/orm.html#openerp.api.constrains

Regards.

1
Avatar
Descartar
Avatar
Prasanth ks
Best Answer

you just try this i think its will work fine as your wish :-

def create(self, cr, uid, vals, context=None):

all_room_ids=self.search(cr,uid,[('room_id','=',vals['room_id'])])

for room_id in all_room_ids     

       room_data=self.browse(cr,uid,room_id)          

                      if ((vals['start'] >= room_data.start) and (vals['end'] <= room_data.start)) or (vals['start'] >= room_data.end):

                                  print'yyyyyyyyyyyyy',room_data

                      else:

                              raise osv.except_osv(_('Error!'),_("Room Already booked."))

2
Avatar
Descartar
Avatar
Akhilesh Gupta
Best Answer

Hi,

You should make room booking constraints on the basis of room status Or you can create warning if it already booked.

May it will help you.

0
Avatar
Descartar
Avatar
Logicious
Autor Best Answer

@prasanth: thanks prasanth. its working perfectly

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

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

Registrar-se
Related Posts Respostes Vistes Activitat
High Availability Odoo 8.0 on Windows
odooV8 odoo8.0 odoo8
Avatar
0
de febr. 21
4543
Product received Administrator in Odoo 8 purchase module
odooV8 odoo8.0 odoo8
Avatar
0
de febr. 18
3275
blockUI requires jQuery v1.2.3 or later! You are using v1.11.1 error when installing Odoo 8 on Windows 10
odooV8 odoo8.0 odoo8
Avatar
Avatar
Avatar
3
de juny 17
6638
Values are reset on save
odooV8 odoo8.0 odoo8
Avatar
0
de gen. 16
4375
How to change Error log window on "client"-side service of Odoo? Solved
odooV8 odoo8.0 odoo8 Odoo8
Avatar
Avatar
2
d’ag. 19
5585
Community
  • Tutorials
  • Documentació
  • Fòrum
Codi obert
  • Descarregar
  • GitHub
  • Runbot
  • Traduccions
Serveis
  • Allotjament a Odoo.sh
  • Suport
  • Actualització
  • Desenvolupaments personalitzats
  • Educació
  • Troba un comptable
  • Troba un partner
  • Converteix-te en partner
Sobre nosaltres
  • La nostra empresa
  • Actius de marca
  • Contacta amb nosaltres
  • Llocs de treball
  • Esdeveniments
  • Pòdcast
  • Blog
  • Clients
  • Informació legal • Privacitat
  • Seguretat
الْعَرَبيّة 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 és un conjunt d'aplicacions empresarials de codi obert que cobreix totes les necessitats de la teva empresa: CRM, comerç electrònic, comptabilitat, inventari, punt de venda, gestió de projectes, etc.

La proposta única de valor d'Odoo és ser molt fàcil d'utilitzar i estar totalment integrat, ambdues alhora.

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