0
我對酒店管理模塊工作在odoo版本8如何計算Odoo晚酒店管理模塊的8號
我希望計算住宿天數留入住日期和退房日期之間。誰能幫我這個?
我定義了一個預訂類,使用更改方法進行簽入和簽出。我試着計算一個函數total_nights
。這裏是我的代碼,
class hotel_reservation(osv.Model):
_name = "hotel.reservation"
_rec_name = "reservation_no"
_description = "Reservation"
_order = 'reservation_no desc'
_columns = {
'reservation_no': fields.char('Reservation No', size=64, required=True, readonly=True),
'date_order':fields.datetime('Date Ordered', required=True, readonly=True, states={'draft':[('readonly', False)]}),
'warehouse_id':fields.many2one('stock.warehouse', 'Hotel', readonly=True, required=True, states={'draft':[('readonly', False)]}),
'partner_id':fields.many2one('res.partner', 'Guest Name', readonly=True, required=True, states={'draft':[('readonly', False)]}),
'pricelist_id':fields.many2one('product.pricelist', 'Price List', required=True, readonly=True, states={'draft':[('readonly', False)]}, help="Pricelist for current reservation. "),
'partner_invoice_id':fields.many2one('res.partner', 'Invoice Address', readonly=True, states={'draft':[('readonly', False)]}, help="Invoice address for current reservation. "),
'partner_order_id':fields.many2one('res.partner', 'Ordering Contact', readonly=True, states={'draft':[('readonly', False)]}, help="The name and address of the contact that requested the order or quotation."),
'partner_shipping_id':fields.many2one('res.partner', 'Delivery Address', readonly=True, states={'draft':[('readonly', False)]}, help="Delivery address for current reservation. "),
'checkin': fields.datetime('Expected-Date-Arrival', required=True, readonly=True, states={'draft':[('readonly', False)]}),
'checkout': fields.datetime('Expected-Date-Departure', required=True, readonly=True, states={'draft':[('readonly', False)]}),
'adults':fields.integer('Adults', size=64, readonly=True, states={'draft':[('readonly', False)]}, help='List of adults there in guest list. '),
'children':fields.integer('Children', size=64, readonly=True, states={'draft':[('readonly', False)]}, help='Number of children there in guest list. '),
'reservation_line':fields.one2many('hotel_reservation.line', 'line_id', 'Reservation Line', help='Hotel room reservation details. '),
'state': fields.selection([('draft', 'Draft'), ('confirm', 'Confirm'), ('cancel', 'Cancel'), ('done', 'Done')], 'State', readonly=True),
'folio_id': fields.many2many('hotel.folio', 'hotel_folio_reservation_rel', 'order_id', 'invoice_id', 'Folio'),
'dummy': fields.datetime('Dummy'),
#'No_of_nights': fields.integer('Number of Nights', size=64, readonly=True, states={'draft':[('readonly', False)]}, help='Number of Nights.'),
'no_of_nights':fields.function(_total_nights, string='Amount to be returned',
store={
'value': (lambda self, cr, uid, ids, c={}: ids, ['amount', 'roi'], 10),
},),
}
_defaults = {
'reservation_no': lambda obj, cr, uid, context: obj.pool.get('ir.sequence').get(cr, uid, 'hotel.reservation'),
'state': lambda *a: 'draft',
'date_order': lambda *a: time.strftime('%Y-%m-%d %H:%M:%S'),
}
def on_change_checkin(self, cr, uid, ids, date_order, checkin_date=time.strftime('%Y-%m-%d %H:%M:%S'), context=None):
if date_order and checkin_date:
if checkin_date < date_order:
raise osv.except_osv(_('Warning'), _('Checkin date should be greater than the current date.'))
return {'value':{}}
def on_change_checkout(self, cr, uid, ids, checkin_date=time.strftime('%Y-%m-%d %H:%M:%S'), checkout_date=time.strftime('%Y-%m-%d %H:%M:%S'), context=None):
if not (checkout_date and checkin_date):
return {'value':{}}
if checkout_date < checkin_date:
raise osv.except_osv(_('Warning'), _('Checkout date should be greater than the Checkin date.'))
delta = datetime.timedelta(days=1)
addDays = datetime.datetime(*time.strptime(checkout_date, '%Y-%m-%d %H:%M:%S')[:5]) + delta
val = {'value':{'dummy':addDays.strftime('%Y-%m-%d %H:%M:%S')}}
return val
def onchange_partner_id(self, cr, uid, ids, partner_id):
if not partner_id:
return {'value':{'partner_invoice_id': False, 'partner_shipping_id':False, 'partner_order_id':False}}
partner_obj = self.pool.get('res.partner')
addr = partner_obj.address_get(cr, uid, [partner_id], ['delivery', 'invoice', 'contact'])
pricelist = partner_obj.browse(cr, uid, partner_id).property_product_pricelist.id
return {'value':{'partner_invoice_id': addr['invoice'], 'partner_order_id':addr['contact'], 'partner_shipping_id':addr['delivery'], 'pricelist_id': pricelist}}
def total_nights(self, cr, uid, ids, context=None):
print("Function for Calculating total Nights !")
context = context or {}
res = {}
''''''
for value in self.browse(cr, uid, ids, checkin_date=time.strftime('%Y-%m-%d %H:%M:%S'), checkout_date=time.strftime('%Y-%m-%d %H:%M:%S'), context=context):
check_in = datetime.strptime(check_in, "%Y-%m-%d")
check_out = datetime.strptime(check_out, "%Y-%m-%d")
delta = check_out - check_in
print delta.days
return res
class hotel_room_reservation_line(osv.Model):
_name = 'hotel.room.reservation.line'
_description = 'Hotel Room Reservation'
_rec_name = 'room_id'
_columns = {
'room_id': fields.many2one('hotel.room', 'Room id'),
'check_in':fields.datetime('Check In Date', required=True),
'check_out': fields.datetime('Check Out Date', required=True),
'state': fields.selection([('assigned', 'Assigned'), ('unassigned', 'Unassigned')], 'Room Status'),
'reservation_id': fields.many2one('hotel.reservation', 'Reservation'),
}
hotel_room_reservation_line()
顯示你已經嘗試些什麼?! –
我現在將我的代碼添加到了問題中。 –