如何在open erp中使用ORM方法获取另一个模型中的更新字段

时间:2015-10-12 05:34:09

标签: python xml openerp odoo

我是openERP的新手,所以我开始创建基本模块。

我使用4种不同的型号名称创建了酒店管理模块。 1.room.info [房间信息],2.room.book [预订房间,与room.info有很多关系],3.room.vacant [空房],4.room.engaged [订房]

我想要的是每当我创建房间信息时它应该来到room.vacant模型(空置房间)以及每当客户预订房间时它应该来到房间。房屋模型和空房间应该更新。我没有正确地获得ORM方法。请帮帮我。谢谢你提前

Here is the image of my module

CODE:

from openerp.osv import fields, osv
from openerp import api
from datetime import datetime, timedelta
import datetime

class Hotel(osv.osv):
_name = 'hotel.book'

_columns ={

    'c_name' : fields.char('Customer name',required=True),
    'room_num' : fields.many2one('room.info','Room number', required=True),
    'charges' : fields.float('Price'),
    'mobile' : fields.char('Mobile Number', size=64, required=True),
    'charges' : fields.float('Price'),
    'check_in':fields.date('Check In'),
    'check_out':fields.date('Check Out'),
    'days': fields.float('Number of Days'),
    'total' : fields.float('Amount'),


        }
Hotel()

 class RoomInfo(osv.osv):
     _name='room.info'
     _rec_name='room_num'

     _columns = {

        'room_num':fields.integer('Room Number'),
        'status':fields.selection([('reserved', 'Reserved'),('vacant', 'Vacant')],'Status'),

               }

   RoomInfo()

   class VacantRooms(osv.osv):
       _name='room.vacant'
       _columns = {

           'room_num' : fields.many2one('room.info','Room number'),

            }

   VacantRooms()

   class EngagedRooms(osv.osv):
       _name='room.engage'
       _columns = {

          'room_num' : fields.many2one('room.info','Room number'),
          'status':fields.selection([('reserved', 'Reserved'),('vacant', 'Vacant')],'Status'),


}
    EngagedRooms()

1 个答案:

答案 0 :(得分:0)

您可以尝试以下代码:

from openerp import fields, models


class Hotel(models.Model):
    _name = 'hotel.book'

    c_name = fields.Char('Customer name', required=True)
    room_num = fields.Many2one('room.info', 'Room number', required=True)
    charges = fields.Float('Price')
    mobile = fields.Char('Mobile Number', required=True)
    charges = fields.Float('Price')
    check_in = fields.Date('Check In')
    check_out = fields.Date('Check Out')
    days = fields.Float('Number of Days')
    total = fields.Float('Amount')


class RoomInfo(models.Model):
    _name = 'room.info'

    room_num = fields.Integer('Room Number')
    status = fields.Selection([('reserved', 'Reserved'), ('vacant', 'Vacant')], string='Status')


class VacantRooms(models.Model):
    _name = 'room.vacant'

    room_num = fields.Many2one('room.info', 'Room number')


class EngagedRooms(models.Model):
    _name = 'room.engage'

    room_num = fields.Many2one('room.info', 'Room number')
    status = fields.Selection([('reserved', 'Reserved'), ('vacant', 'Vacant')], 'Status')