From 81f8cc6460dfd2ba9616ee6d6082652999ee8cc2 Mon Sep 17 00:00:00 2001 From: Dario Lodeiros Date: Sat, 16 Mar 2019 23:12:03 +0100 Subject: [PATCH] [FIX] State on split Reservations --- hotel/models/hotel_reservation.py | 18 ++++++++++++------ hotel/models/hotel_service.py | 22 +++++++++++++++------- hotel/views/hotel_reservation_views.xml | 11 +++++++---- 3 files changed, 34 insertions(+), 17 deletions(-) diff --git a/hotel/models/hotel_reservation.py b/hotel/models/hotel_reservation.py index 136ce9eaa..b1b35792d 100644 --- a/hotel/models/hotel_reservation.py +++ b/hotel/models/hotel_reservation.py @@ -389,9 +389,12 @@ class HotelReservation(models.Model): if 'checkout' in vals: vals['real_checkout'] = vals['checkout'] + real_checkin = vals['real_checkin'] if 'real_checkin' in vals else record.real_checkin + real_checkout = vals['real_checkout'] if 'real_checkout' in vals else record.real_checkout + days_diff = ( - fields.Date.from_string(checkout) - \ - fields.Date.from_string(checkin) + fields.Date.from_string(real_checkout) - \ + fields.Date.from_string(real_checkin) ).days if self.compute_board_services(vals): record.service_ids.filtered(lambda r: r.is_board_service == True).unlink() @@ -410,7 +413,7 @@ class HotelReservation(models.Model): if record.compute_price_out_vals(vals): pricelist_id = vals['pricelist_id'] if 'pricelist_id' in vals else record.pricelist_id.id record.update(record.prepare_reservation_lines( - checkin, + real_checkin, days_diff, pricelist_id, vals=vals)) #REVISAR el unlink @@ -418,7 +421,7 @@ class HotelReservation(models.Model): for service in record.service_ids: if service.product_id.per_day: service.update(service.prepare_service_lines( - dfrom=checkin, + dfrom=real_checkin, days=days_diff, per_person=service.product_id.per_person, persons=service.ser_room_line.adults, @@ -756,7 +759,6 @@ class HotelReservation(models.Model): @param self: object pointer ''' _logger.info('confirm') - hotel_folio_obj = self.env['hotel.folio'] hotel_reserv_obj = self.env['hotel.reservation'] for record in self: vals = {} @@ -775,8 +777,10 @@ class HotelReservation(models.Model): ('id', '=', master_reservation.id), ('folio_id', '=', record.folio_id.id), ('id', '!=', record.id), - ('state', '!=', 'confirm') + ('state', 'not in', ('confirm', 'booking')) ]) + if master_reservation.checkin_partner_ids: + record.update({'state': 'booking'}) splitted_reservs.confirm() return True @@ -1111,7 +1115,9 @@ class HotelReservation(models.Model): 'parent_reservation': parent_res.id, 'room_type_id': parent_res.room_type_id.id, 'discount': parent_res.discount, + 'state': parent_res.state, 'reservation_line_ids': reservation_lines[1], + 'preconfirm': False, }) reservation_copy = self.env['hotel.reservation'].with_context({ 'ignore_avail_restrictions': True}).create(vals) diff --git a/hotel/models/hotel_service.py b/hotel/models/hotel_service.py index e1a5ea054..273b636ab 100644 --- a/hotel/models/hotel_service.py +++ b/hotel/models/hotel_service.py @@ -169,10 +169,12 @@ class HotelService(models.Model): if self.compute_lines_out_vals(vals): reservation = self.env['hotel.reservation'].browse(vals['ser_room_line']) product = self.env['product.product'].browse(vals['product_id']) - + checkin_dt = fields.Date.from_string(reservation.real_checkin) + checkout_dt = fields.Date.from_string(reservation.real_checkout) + nights = abs((checkout_dt - checkin_dt).days) vals.update(self.prepare_service_lines( - dfrom=reservation.checkin, - days=reservation.nights, + dfrom=reservation.real_checkin, + days=nights, per_person=product.per_person, persons=reservation.adults, old_day_lines=False, @@ -195,9 +197,12 @@ class HotelService(models.Model): reservations = self.env['hotel.reservation'] reservation = reservations.browse(vals['ser_room_line']) \ if 'ser_room_line' in vals else record.ser_room_line + checkin_dt = fields.Date.from_string(reservation.real_checkin) + checkout_dt = fields.Date.from_string(reservation.real_checkout) + nights = abs((checkout_dt - checkin_dt).days) record.update(record.prepare_service_lines( - dfrom=reservation.checkin, - days=reservation.nights, + dfrom=reservation.real_checkin, + days=nights, per_person=product.per_person, persons=reservation.adults, old_line_days=self.service_line_ids @@ -272,9 +277,12 @@ class HotelService(models.Model): if record.per_day and record.ser_room_line: product = record.product_id reservation = record.ser_room_line + checkin_dt = fields.Date.from_string(reservation.real_checkin) + checkout_dt = fields.Date.from_string(reservation.real_checkout) + nights = abs((checkout_dt - checkin_dt).days) vals.update(record.prepare_service_lines( - dfrom=reservation.checkin, - days=reservation.nights, + dfrom=reservation.real_checkin, + days=nights, per_person=product.per_person, persons=reservation.adults, old_line_days=record.service_line_ids)) diff --git a/hotel/views/hotel_reservation_views.xml b/hotel/views/hotel_reservation_views.xml index 3255d2741..d50458d53 100644 --- a/hotel/views/hotel_reservation_views.xml +++ b/hotel/views/hotel_reservation_views.xml @@ -202,7 +202,7 @@ ('hotel_room_type_id', '=', room_type_id), ('pricelist_id', 'in', [pricelist_id, False])]" options="{'no_create': True,'no_open': True}" - attrs="{'invisible': [('reservation_type','in',('out'))]}" /> + attrs="{'invisible': ['|',('reservation_type','in',('out')),('parent_reservation','!=',False)]}" /> @@ -234,7 +234,8 @@ + attrs="{'invisible': ['|',('reservation_type','in',('out')), + ('parent_reservation','!=',False)]}"> + attrs="{'invisible': ['|',('reservation_type','in',('out')), + ('parent_reservation','!=',False)]}"> @@ -304,7 +306,8 @@ /> + attrs="{'invisible': ['|',('reservation_type','in',('out')), + ('parent_reservation','!=',False)]}">