Skip to Content
Odoo Menu
  • Sign in
  • Try it free
  • Apps
    Finance
    • Accounting
    • Invoicing
    • Expenses
    • Spreadsheet (BI)
    • Documents
    • Sign
    Sales
    • CRM
    • Sales
    • POS Shop
    • POS Restaurant
    • Subscriptions
    • Rental
    Websites
    • Website Builder
    • eCommerce
    • Blog
    • Forum
    • Live Chat
    • eLearning
    Supply Chain
    • Inventory
    • Manufacturing
    • PLM
    • Purchase
    • Maintenance
    • Quality
    Human Resources
    • Employees
    • Recruitment
    • Time Off
    • Appraisals
    • Referrals
    • Fleet
    Marketing
    • Social Marketing
    • Email Marketing
    • SMS Marketing
    • Events
    • Marketing Automation
    • Surveys
    Services
    • Project
    • Timesheets
    • Field Service
    • Helpdesk
    • Planning
    • Appointments
    Productivity
    • Discuss
    • Approvals
    • IoT
    • VoIP
    • Knowledge
    • WhatsApp
    Third party apps Odoo Studio Odoo Cloud Platform
  • Industries
    Retail
    • Book Store
    • Clothing Store
    • Furniture Store
    • Grocery Store
    • Hardware Store
    • Toy Store
    Food & Hospitality
    • Bar and Pub
    • Restaurant
    • Fast Food
    • Guest House
    • Beverage Distributor
    • Hotel
    Real Estate
    • Real Estate Agency
    • Architecture Firm
    • Construction
    • Estate Management
    • Gardening
    • Property Owner Association
    Consulting
    • Accounting Firm
    • Odoo Partner
    • Marketing Agency
    • Law firm
    • Talent Acquisition
    • Audit & Certification
    Manufacturing
    • Textile
    • Metal
    • Furnitures
    • Food
    • Brewery
    • Corporate Gifts
    Health & Fitness
    • Sports Club
    • Eyewear Store
    • Fitness Center
    • Wellness Practitioners
    • Pharmacy
    • Hair Salon
    Trades
    • Handyman
    • IT Hardware & Support
    • Solar Energy Systems
    • Shoe Maker
    • Cleaning Services
    • HVAC Services
    Others
    • Nonprofit Organization
    • Environmental Agency
    • Billboard Rental
    • Photography
    • Bike Leasing
    • Software Reseller
    Browse all Industries
  • Community
    Learn
    • Tutorials
    • Documentation
    • Certifications
    • Training
    • Blog
    • Podcast
    Empower Education
    • Education Program
    • Scale Up! Business Game
    • Visit Odoo
    Get the Software
    • Download
    • Compare Editions
    • Releases
    Collaborate
    • Github
    • Forum
    • Events
    • Translations
    • Become a Partner
    • Services for Partners
    • Register your Accounting Firm
    Get Services
    • Find a Partner
    • Find an Accountant
    • Meet an advisor
    • Implementation Services
    • Customer References
    • Support
    • Upgrades
    Github Youtube Twitter Linkedin Instagram Facebook Spotify
    +1 (650) 691-3277
    Get a demo
  • Pricing
  • Help

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

  • CRM
  • e-Commerce
  • Accounting
  • Inventory
  • PoS
  • Project
  • MRP
All apps
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
You need to be registered to interact with the community.
All Posts People Badges
Tags (View all)
odoo accounting v14 pos v15
About this forum
Help

@api odoo11

Subscribe

Get notified when there's activity on this post

This question has been flagged
rentalrent@api.dependsOdoo11
5 Replies
5448 Views
Avatar
Tiến Paul

hai,

Hello everyone, I'm newbie, I want to write @api so that when there are customers renting that room on the table room, the status fields will automatically turn into 'busy' and vice versa will return 'free'

class booking_room(models.Model):
_name = 'room'
_rec_name = 'name'

name = fields.Char(string="Mã phòng", required=True)
   status = fields.Selection([('1', 'Trống'), ('2', 'Bận')], string="Trạng thái", required=True)
kind = fields.Selection([('3', 'A'), ('4', 'B'), ('5', 'C'), ('6', 'Vip')], string="Loại phòng", required=True)
price = fields.Integer(string="Giá phòng", required=True)
description = fields.Text("Ghi chú")
-------------------------

class guest_room(models.Model):
_name = 'guest'

name = fields.Char(string="Họ tên", required=True)
cmnd = fields.Char(string="Số CMND", required=True)
sdt = fields.Char(string="SĐT", required=True)
time_in = fields.Datetime(string="Ngày đến")
time_out = fields.Datetime(string="Ngày trả")
servicesd = fields.Many2one('service', string="Dịch vụ sử dụng")
roomsd = fields.Many2one('room', string="Phòng mượn")

Thanks

0
Avatar
Discard
Nikhil Krishnan

Try to make question readable and explain details.

OdooBot
thank you for the help. changed a bit and it worked, but when "status" by default is "busy"

Vào Th 4, 26 thg 9, 2018 vào lúc 06:17 Juan Albarracin <aprados.juan@gmail.com> đã viết:

A new answer on @api odoo11 has been posted. Click here to access the post :

See post

--
Juan Albarracin

Sent by Odoo S.A. using Odoo.

OdooBot
thank you for the help. But it does not work for me

Vào Th 3, 25 thg 9, 2018 vào lúc 15:53 NIKHIL KRISHNAN <nikhilkrishnan0101@gmail.com> đã viết:

A new question @api odoo11 on Help has been posted. Click here to access the question :

See question


Sent by Odoo S.A. using Odoo.

Avatar
Nikhil Krishnan
Best Answer

Hai vu van tien,

You can define a form view for the room table.

Then create a button for allocation and free the rooms.

XML

<button name="roomallocationandfree" string="Allocation/Free" type="object" class="btn-primary"/>

Python

@api.multi
def roomallocationandfree(self):
if self.status == 1:
self.status = 2
else:
self.status = 1

Regards,

Nikhilkrishnan

1
Avatar
Discard
Avatar
Juan Albarracin
Best Answer

Hello, I think you want the field to be computed on the fly, without having to assign the value with a button right?

You can make the status field a computed field and assign its value like in my code below.

Remember to import datetime at the top of your python file, and add the field to the views you prefer!

#import required library to get current datetime
from datetime import datetime as dt
class booking_room(models.Model):
_name = 'room'
name = fields.Char(string="Mã phòng", required=True)
   status = fields.Selection([('1', 'Trống'), ('2', 'Bận')], string="Trạng thái",
        required=True, compute="_get_status"
    )
kind = fields.Selection([('3', 'A'), ('4', 'B'), ('5', 'C'), ('6', 'Vip')],
        string="Loại phòng", required=True
    )
price = fields.Integer(string="Giá phòng", required=True)
description = fields.Text("Ghi chú")
@api.multi
def _get_status(self):
        # Get the current datetime in the format that time_in and time_out fields
        # are stored in the database
        now = dt.now().strftime('%Y-%m-%d %H:%M:%S')
        for room in self:
            # look for guests that have a room booked now, and whose room id is the current
            # the order is important because as the guest table grows,
            # the nº of rows that satisfy the conditions will be lower for the first one,
            # bigger for the second, and the biggest for the last one,
            # and the search will be faster this way.
            # guest_in_room will be True is len(search)>0, False otherwise.
            guest_in_room = len(self.env['guest'].search([
                ('time_out', '>', now),
                ('time_in', '<', now),
                ('roomsd', '=', room.id)
            ])) > 0
            # If guest_in_room is True, room's status is busy, free otherwise
            if guest_in_room:
                room.status = '2'
            else:
                room.status = '1'

 Regards,

Juan Albarracin

1
Avatar
Discard
Avatar
DHA Medic
Best Answer

You can use state:

Ex:

https://github.com/odoo/odoo/blob/11.0/addons/hr_holidays/models/hr_holidays.py#L159-L170

https://github.com/odoo/odoo/blob/11.0/addons/hr_holidays/views/hr_holidays_views.xml#L83-L89

1
Avatar
Discard
Avatar
Tiến Paul
Author Best Answer
 thank you
Juan Albarracin
  has answered, but to me, it does not work. fields 'status' does not work, whether or not the "guest" reservation or not "status" returned is always "blank" and can not be tampered with or created.
0
Avatar
Discard
Enjoying the discussion? Don't just read, join in!

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

Sign up
Related Posts Replies Views Activity
Rental module for Odoo Community
rental rent
Avatar
0
Apr 19
15312
Displaying Prices (Website / Rental)
rental rent website
Avatar
Avatar
1
Apr 25
1921
Edit the rental app
rental rent source_code
Avatar
0
Dec 22
2960
Sale Rental v9c
rental rent Quantity on Hand
Avatar
0
Sep 17
3511
How to rent a fixed asset in odoo 16
rental rent fixedassets fixed_asset
Avatar
0
May 23
3314
Community
  • Tutorials
  • Documentation
  • Forum
Open Source
  • Download
  • Github
  • Runbot
  • Translations
Services
  • Odoo.sh Hosting
  • Support
  • Upgrade
  • Custom Developments
  • Education
  • Find an Accountant
  • Find a Partner
  • Become a Partner
About us
  • Our company
  • Brand Assets
  • Contact us
  • Jobs
  • Events
  • Podcast
  • Blog
  • Customers
  • Legal • Privacy
  • Security
الْعَرَبيّة 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